* 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.
This commit is contained in:
parent
97e5d3ffa4
commit
2b1407d372
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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))
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user