summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2010-02-12 20:07:13 +0000
committerChristopher Faylor <me@cgf.cx>2010-02-12 20:07:13 +0000
commit2b1407d372f69777ee4949b9e41cf1a1e87810be (patch)
tree8472fb355cf864fb0305daa8b7528f4176a64f60
parent97e5d3ffa4bf04157850d82e66d4744610067c25 (diff)
downloadcygnal-2b1407d372f69777ee4949b9e41cf1a1e87810be.tar.gz
cygnal-2b1407d372f69777ee4949b9e41cf1a1e87810be.tar.bz2
cygnal-2b1407d372f69777ee4949b9e41cf1a1e87810be.zip
* pthread.cc (pthread_mutex_init): Explicitly fill out third arg to
pthread_mutex::init. * thread.cc: Remov some obsolete comments. (verifyable_object_isvalid): Reflect change to use thread_magic_t for magic numbers. (pthread_mutex::pthread_mutex): Set magic number to invalid initially until we've verified that everything is valid. (pthread_mutex::unlock): Fix a comment. (verifyable_object::verifyable_object): Delete here. (~verifyable_object::~verifyable_object): Ditto. (pthread_mutex::init): Don't run is_good_initializer for non-static objects. * thread.h (thread_magic_t): New typedef. (verifyable_object::verifyable_object): Use thread_magic_t; (verifyable_object::magic): Ditto. (pthread_mutex::is_good_initializer_or_bad_object): Remove unneeded variable names. (pthread_mutex::can_be_unlocked): Ditto. (pthread_mutex::init): Ditto. Remove default for third argument.
-rw-r--r--winsup/cygwin/ChangeLog22
-rw-r--r--winsup/cygwin/pthread.cc2
-rw-r--r--winsup/cygwin/thread.cc69
-rw-r--r--winsup/cygwin/thread.h16
4 files changed, 46 insertions, 63 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 1b7a42eb5..02abda230 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,25 @@
+2010-02-12 Christopher Faylor <me+cygwin@cgf.cx>
+
+ * pthread.cc (pthread_mutex_init): Explicitly fill out third arg to
+ pthread_mutex::init.
+ * thread.cc: Remov some obsolete comments.
+ (verifyable_object_isvalid): Reflect change to use thread_magic_t for
+ magic numbers.
+ (pthread_mutex::pthread_mutex): Set magic number to invalid initially
+ until we've verified that everything is valid.
+ (pthread_mutex::unlock): Fix a comment.
+ (verifyable_object::verifyable_object): Delete here.
+ (~verifyable_object::~verifyable_object): Ditto.
+ (pthread_mutex::init): Don't run is_good_initializer for non-static
+ objects.
+ * thread.h (thread_magic_t): New typedef.
+ (verifyable_object::verifyable_object): Use thread_magic_t;
+ (verifyable_object::magic): Ditto.
+ (pthread_mutex::is_good_initializer_or_bad_object): Remove unneeded
+ variable names.
+ (pthread_mutex::can_be_unlocked): Ditto.
+ (pthread_mutex::init): Ditto. Remove default for third argument.
+
2010-02-12 Corinna Vinschen <corinna@vinschen.de>
* regex/regcomp.c (xwcrtomb): New function to convert wide chars
diff --git a/winsup/cygwin/pthread.cc b/winsup/cygwin/pthread.cc
index b110b831b..18f2aea5d 100644
--- a/winsup/cygwin/pthread.cc
+++ b/winsup/cygwin/pthread.cc
@@ -88,7 +88,7 @@ pthread_t pthread_self ()
int
pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr)
{
- return pthread_mutex::init (mutex, attr);
+ return pthread_mutex::init (mutex, attr, NULL);
}
/* Synchronisation */
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 16f6ed160..53a4f8c31 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -41,7 +41,7 @@ details. */
extern "C" void __fp_lock_all ();
extern "C" void __fp_unlock_all ();
static inline verifyable_object_state
- verifyable_object_isvalid (void const * objectptr, long magic,
+ verifyable_object_isvalid (void const * objectptr, thread_magic_t magic,
void *static_ptr1 = NULL,
void *static_ptr2 = NULL,
void *static_ptr3 = NULL);
@@ -95,7 +95,7 @@ __cygwin_lock_unlock (_LOCK_T *lock)
}
static inline verifyable_object_state
-verifyable_object_isvalid (void const *objectptr, long magic, void *static_ptr1,
+verifyable_object_isvalid (void const *objectptr, thread_magic_t magic, void *static_ptr1,
void *static_ptr2, void *static_ptr3)
{
myfault efault;
@@ -1503,28 +1503,7 @@ pthread_key::run_destructor ()
}
}
-/* pshared mutexs:
-
- REMOVED FROM CURRENT. These can be reinstated with the daemon, when all the
- gymnastics can be a lot easier.
-
- the mutex_t (size 4) is not used as a verifyable object because we cannot
- guarantee the same address space for all processes.
- we use the following:
- high bit set (never a valid address).
- second byte is reserved for the priority.
- third byte is reserved
- fourth byte is the mutex id. (max 255 cygwin mutexs system wide).
- creating mutex's does get slower and slower, but as creation is a one time
- job, it should never become an issue
-
- And if you're looking at this and thinking, why not an array in cygwin for all mutexs,
- - you incur a penalty on _every_ mutex call and you have toserialise them all.
- ... Bad karma.
-
- option 2? put everything in userspace and update the ABI?
- - bad karma as well - the HANDLE, while identical across process's,
- Isn't duplicated, it's reopened. */
+/* pshared mutexs */
/* static members */
@@ -1533,9 +1512,6 @@ List<pthread_mutex> pthread_mutex::mutexes;
/* This is used for mutex creation protection within a single process only */
fast_mutex NO_COPY pthread_mutex::mutex_initialization_lock;
-/* We can only be called once.
- TODO: (no rush) use a non copied memory section to
- hold an initialization flag. */
void
pthread_mutex::init_mutex ()
{
@@ -1544,7 +1520,7 @@ pthread_mutex::init_mutex ()
}
pthread_mutex::pthread_mutex (pthread_mutexattr *attr) :
- verifyable_object (PTHREAD_MUTEX_MAGIC),
+ verifyable_object (0), /* set magic to zero initially */
lock_counter (0),
win32_obj_id (NULL), recursion_counter (0),
condwaits (0), owner (NULL),
@@ -1556,23 +1532,16 @@ pthread_mutex::pthread_mutex (pthread_mutexattr *attr) :
{
win32_obj_id = ::CreateEvent (&sec_none_nih, false, false, NULL);
if (!win32_obj_id)
- {
- magic = 0;
- return;
- }
+ return;
/*attr checked in the C call */
- if (attr)
- {
- if (attr->pshared == PTHREAD_PROCESS_SHARED)
- {
- // fail
- magic = 0;
- return;
- }
-
- type = attr->mutextype;
- }
+ if (!attr)
+ /* handled in the caller */;
+ else if (attr->pshared != PTHREAD_PROCESS_SHARED)
+ type = attr->mutextype;
+ else
+ return; /* Not implemented */
+ magic = PTHREAD_MUTEX_MAGIC;
mutexes.insert (this);
}
@@ -1625,7 +1594,7 @@ pthread_mutex::unlock ()
tid = 0;
#endif
if (InterlockedDecrement ((long *) &lock_counter))
- ::SetEvent (win32_obj_id); // Another thread may be waiting
+ ::SetEvent (win32_obj_id); // Another thread is waiting
}
return 0;
@@ -1692,16 +1661,6 @@ pthread_mutexattr::~pthread_mutexattr ()
{
}
-verifyable_object::verifyable_object (long verifyer):
-magic (verifyer)
-{
-}
-
-verifyable_object::~verifyable_object ()
-{
- magic = 0;
-}
-
DWORD WINAPI
pthread::thread_init_wrapper (void *arg)
{
@@ -2664,7 +2623,7 @@ pthread_mutex::init (pthread_mutex_t *mutex,
return EINVAL;
mutex_initialization_lock.lock ();
- if (pthread_mutex::is_good_initializer (mutex))
+ if (initializer == NULL || pthread_mutex::is_good_initializer (mutex))
{
pthread_mutex_t new_mutex = new pthread_mutex (attr ? (*attr) : NULL);
if (!is_good_object (&new_mutex))
diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
index 21d278dae..17f3b59cb 100644
--- a/winsup/cygwin/thread.h
+++ b/winsup/cygwin/thread.h
@@ -100,15 +100,17 @@ class pinfo;
#define MUTEX_OWNER_ANONYMOUS ((pthread_t) -1)
+typedef unsigned long thread_magic_t;
+
/* verifyable_object should not be defined here - it's a general purpose class */
class verifyable_object
{
public:
- long magic;
+ thread_magic_t magic;
- verifyable_object (long);
- virtual ~verifyable_object ();
+ verifyable_object (thread_magic_t verifyer): magic (verifyer) {}
+ virtual ~verifyable_object () { magic = 0; }
};
typedef enum
@@ -268,11 +270,11 @@ public:
static bool is_good_object (pthread_mutex_t const *);
static bool is_good_initializer (pthread_mutex_t const *);
static bool is_good_initializer_or_object (pthread_mutex_t const *);
- static bool is_good_initializer_or_bad_object (pthread_mutex_t const *mutex);
- static bool can_be_unlocked (pthread_mutex_t const *mutex);
+ static bool is_good_initializer_or_bad_object (pthread_mutex_t const *);
+ static bool can_be_unlocked (pthread_mutex_t const *);
static void init_mutex ();
- static int init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr,
- const pthread_mutex_t initializer = NULL);
+ static int init (pthread_mutex_t *, const pthread_mutexattr_t *attr,
+ const pthread_mutex_t);
unsigned long lock_counter;
HANDLE win32_obj_id;