* [PATCH] default to normal pthread mutexes
@ 2014-07-13 23:38 Yaakov Selkowitz
2014-07-14 9:45 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: Yaakov Selkowitz @ 2014-07-13 23:38 UTC (permalink / raw)
To: cygwin-patches
[-- Attachment #1: Type: text/plain, Size: 283 bytes --]
Defaulting to ERRORCHECK mutexes (with the various stringencies it
implies) does not match the behaviour on Linux, where NORMAL mutexes are
the default. I have been testing this locally for some time, and I
believe it affects a lot of software. Patch and STC attached.
Yaakov
[-- Attachment #2: pthread-mutex-default.patch --]
[-- Type: text/plain, Size: 2388 bytes --]
2014-07-13 Yaakov Selkowitz <yselkowitz@...>
* thread.cc (pthread_mutex::pthread_mutex): Change default type
to PTHREAD_MUTEX_NORMAL.
(pthread_mutexattr::pthread_mutexattr): Ditto.
(pthread_mutex_unlock): Do not fail if mutex is a normal mutex
initializer.
* include/pthread.h (PTHREAD_MUTEX_INITIALIZER): Redefine as
PTHREAD_NORMAL_MUTEX_INITIALIZER_NP.
Index: thread.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/thread.cc,v
retrieving revision 1.287
diff -u -p -r1.287 thread.cc
--- thread.cc 1 Dec 2013 10:27:16 -0000 1.287
+++ thread.cc 26 Mar 2014 04:24:08 -0000
@@ -1708,7 +1708,7 @@ pthread_mutex::pthread_mutex (pthread_mu
tid (0),
#endif
recursion_counter (0), condwaits (0),
- type (PTHREAD_MUTEX_ERRORCHECK),
+ type (PTHREAD_MUTEX_NORMAL),
pshared (PTHREAD_PROCESS_PRIVATE)
{
win32_obj_id = ::CreateEvent (&sec_none_nih, false, false, NULL);
@@ -1850,7 +1850,7 @@ pthread_mutex::_fixup_after_fork ()
}
pthread_mutexattr::pthread_mutexattr ():verifyable_object (PTHREAD_MUTEXATTR_MAGIC),
-pshared (PTHREAD_PROCESS_PRIVATE), mutextype (PTHREAD_MUTEX_ERRORCHECK)
+pshared (PTHREAD_PROCESS_PRIVATE), mutextype (PTHREAD_MUTEX_NORMAL)
{
}
@@ -3158,7 +3158,7 @@ extern "C" int
pthread_mutex_unlock (pthread_mutex_t *mutex)
{
if (pthread_mutex::is_initializer (mutex))
- return EPERM;
+ pthread_mutex::init (mutex, NULL, *mutex);
if (!pthread_mutex::is_good_object (mutex))
return EINVAL;
return (*mutex)->unlock ();
Index: include/pthread.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/pthread.h,v
retrieving revision 1.39
diff -u -p -r1.39 pthread.h
--- include/pthread.h 26 Feb 2013 10:32:36 -0000 1.39
+++ include/pthread.h 26 Mar 2014 04:24:08 -0000
@@ -49,7 +49,7 @@ extern "C"
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP (pthread_mutex_t)18
#define PTHREAD_NORMAL_MUTEX_INITIALIZER_NP (pthread_mutex_t)19
#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP (pthread_mutex_t)20
-#define PTHREAD_MUTEX_INITIALIZER PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+#define PTHREAD_MUTEX_INITIALIZER PTHREAD_NORMAL_MUTEX_INITIALIZER_NP
#define PTHREAD_ONCE_INIT { PTHREAD_MUTEX_INITIALIZER, 0 }
#if defined(_POSIX_THREAD_PRIO_INHERIT) && _POSIX_THREAD_PRIO_INHERIT >= 0
#define PTHREAD_PRIO_NONE 0
[-- Attachment #3: pthread-mutex-test.c --]
[-- Type: text/plain, Size: 1008 bytes --]
#include <pthread.h>
#include <stdio.h>
#include <error.h>
int
main(void)
{
int ret;
pthread_mutexattr_t attr;
pthread_mutex_t mutex;
#ifdef __CYGWIN__
pthread_mutex_t mutexstatic = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP;
#else
pthread_mutex_t mutexstatic = PTHREAD_MUTEX_INITIALIZER;
#endif
pthread_mutexattr_init(&attr);
{
int type;
printf ("PTHREAD_MUTEX_NORMAL = %d\n", PTHREAD_MUTEX_NORMAL);
printf ("PTHREAD_MUTEX_ERRORCHECK = %d\n", PTHREAD_MUTEX_ERRORCHECK);
printf ("PTHREAD_MUTEX_DEFAULT = %d\n", PTHREAD_MUTEX_DEFAULT);
pthread_mutexattr_gettype (&attr, &type);
printf ("pthread_mutexattr_init(NULL) type is: %d\n", type);
}
pthread_mutex_init(&mutex, &attr);
pthread_mutexattr_destroy(&attr);
if ((ret = pthread_mutex_unlock(&mutex)))
error(0, ret, "pthread_mutex_unlock(mutex)");
// pthread_mutex_init(&mutexstatic, NULL);
if ((ret = pthread_mutex_unlock(&mutexstatic)))
error(0, ret, "pthread_mutex_unlock(mutexstatic)");
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] default to normal pthread mutexes
2014-07-13 23:38 [PATCH] default to normal pthread mutexes Yaakov Selkowitz
@ 2014-07-14 9:45 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2014-07-14 9:45 UTC (permalink / raw)
To: cygwin-patches
[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]
Hi Yaakov,
On Jul 13 18:38, Yaakov Selkowitz wrote:
> Defaulting to ERRORCHECK mutexes (with the various stringencies it implies)
> does not match the behaviour on Linux, where NORMAL mutexes are the default.
> I have been testing this locally for some time, and I believe it affects a
> lot of software. Patch and STC attached.
>
>
> Yaakov
> 2014-07-13 Yaakov Selkowitz <yselkowitz@...>
>
> * thread.cc (pthread_mutex::pthread_mutex): Change default type
> to PTHREAD_MUTEX_NORMAL.
> (pthread_mutexattr::pthread_mutexattr): Ditto.
> (pthread_mutex_unlock): Do not fail if mutex is a normal mutex
> initializer.
> * include/pthread.h (PTHREAD_MUTEX_INITIALIZER): Redefine as
> PTHREAD_NORMAL_MUTEX_INITIALIZER_NP.
I checked this in with a small addition. While testing I found that
Cygwin's pthread_mutex_unlock returned EINVAL if the mutex is of the
PTHREAD_MUTEX_ERRORCHECK type and the mutex wasn't owned by any thread
(as in your STC), Linux returns EPERM in this case. I fixed that.
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-07-14 9:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-13 23:38 [PATCH] default to normal pthread mutexes Yaakov Selkowitz
2014-07-14 9:45 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).