* include/sys/strace.h: Define _STRACE_SPECIAL.
(strace_printf_wrap): Fix NOSTRACE definitions. (strace_printf_wrap1): Fix NOSTRACE definitions. (special_printf): Define. * thread.cc: Perform minor syntax fix in a comment. Rename "is_good_initialzer*" to "is_initializer*" throughout. Use pthread_printf rather than debug_printf throughout. Add extra pthread_printf debugging throughout. (pthread_mutex::_new_mutex): New constant value. (pthread_mutex::_unlocked_mutex): Ditto. (pthread_mutex::_destroyed_mutex): Ditto. (pthread_mutex::no_owner): Define new function. (pthread_mutex::can_be_unlocked): Detect no_owner situation. Handle PTHREAD_MUTEX_NORMAL as a special case. (pthread::create_cancel_event): Use C++ boolean values. (pthread::precreate): Use method to set mutex type. (pthread_cond::pthread_cond): Ditto. (pthread_rwlock::pthread_rwlock): Ditto. (pthread_mutex::pthread_mutex): Set owner to _new_mutex initially. (pthread_mutex::~pthread_mutex): Reset various elements to make it clearer if they are incorrectly reused. (pthread_mutex::lock): Add clarifying comment. (pthread_mutex::unlock): Attempt to handle various mutex types correctly. In particular, reinstate ability to have one thread unlock another thread's mutex if type == PTHREAD_MUTEX_NORMAL. (semaphore::_fixup_after_fork): Avoid redundancy. (pthread_mutex::_fixup_after_fork): Ditto. Fix debugging statement. (__pthread_cond_dowait): Accommodate changes to remove previously inexplicable use can_be_unblocked() as a static function. * thread.h: Rename "is_good_initialzer*" to "is_initializer*" throughout. (pthread_mutex): Reorganize. Make many things private. (pthread_mutex::no_owner): Define new method. (pthread_mutex::_new_mutex): Define new constant. (pthread_mutex::_unlocked_mutex): Ditto. (pthread_mutex::_destroyed_mutex): Ditto.
This commit is contained in:
@ -267,15 +267,42 @@ public:
|
||||
class pthread_mutex: public verifyable_object
|
||||
{
|
||||
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 *);
|
||||
static bool can_be_unlocked (pthread_mutex_t const *);
|
||||
static void init_mutex ();
|
||||
static int init (pthread_mutex_t *, const pthread_mutexattr_t *attr,
|
||||
const pthread_mutex_t);
|
||||
static bool is_good_object (pthread_mutex_t const *);
|
||||
static bool is_initializer (pthread_mutex_t const *);
|
||||
static bool is_initializer_or_object (pthread_mutex_t const *);
|
||||
static bool is_initializer_or_bad_object (pthread_mutex_t const *);
|
||||
|
||||
int lock ();
|
||||
int trylock ();
|
||||
int unlock ();
|
||||
int destroy ();
|
||||
void set_type (int in_type) {type = in_type;}
|
||||
|
||||
int lock_recursive ()
|
||||
{
|
||||
if (recursion_counter == UINT_MAX)
|
||||
return EAGAIN;
|
||||
recursion_counter++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool can_be_unlocked ();
|
||||
|
||||
pthread_mutex (pthread_mutexattr * = NULL);
|
||||
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
|
||||
~pthread_mutex ();
|
||||
|
||||
class pthread_mutex *next;
|
||||
static void fixup_after_fork ()
|
||||
{
|
||||
mutexes.fixup_after_fork ();
|
||||
mutexes.for_each (&pthread_mutex::_fixup_after_fork);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned long lock_counter;
|
||||
HANDLE win32_obj_id;
|
||||
unsigned int recursion_counter;
|
||||
@ -287,10 +314,6 @@ public:
|
||||
int type;
|
||||
int pshared;
|
||||
|
||||
int lock ();
|
||||
int trylock ();
|
||||
int unlock ();
|
||||
int destroy ();
|
||||
void set_owner (pthread_t self)
|
||||
{
|
||||
recursion_counter = 1;
|
||||
@ -299,31 +322,16 @@ public:
|
||||
tid = GetCurrentThreadId ();
|
||||
#endif
|
||||
}
|
||||
static const pthread_t _new_mutex;
|
||||
static const pthread_t _unlocked_mutex;
|
||||
static const pthread_t _destroyed_mutex;
|
||||
|
||||
int lock_recursive ()
|
||||
{
|
||||
if (UINT_MAX == recursion_counter)
|
||||
return EAGAIN;
|
||||
++recursion_counter;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pthread_mutex (pthread_mutexattr * = NULL);
|
||||
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
|
||||
~pthread_mutex ();
|
||||
|
||||
class pthread_mutex * next;
|
||||
static void fixup_after_fork ()
|
||||
{
|
||||
mutexes.fixup_after_fork ();
|
||||
mutexes.for_each (&pthread_mutex::_fixup_after_fork);
|
||||
}
|
||||
|
||||
private:
|
||||
bool no_owner ();
|
||||
void _fixup_after_fork ();
|
||||
|
||||
static List<pthread_mutex> mutexes;
|
||||
static fast_mutex mutex_initialization_lock;
|
||||
friend class pthread_cond;
|
||||
};
|
||||
|
||||
#define WAIT_CANCELED (WAIT_OBJECT_0 + 1)
|
||||
@ -467,9 +475,9 @@ class pthread_cond: public verifyable_object
|
||||
{
|
||||
public:
|
||||
static bool is_good_object (pthread_cond_t const *);
|
||||
static bool is_good_initializer (pthread_cond_t const *);
|
||||
static bool is_good_initializer_or_object (pthread_cond_t const *);
|
||||
static bool is_good_initializer_or_bad_object (pthread_cond_t const *);
|
||||
static bool is_initializer (pthread_cond_t const *);
|
||||
static bool is_initializer_or_object (pthread_cond_t const *);
|
||||
static bool is_initializer_or_bad_object (pthread_cond_t const *);
|
||||
static void init_mutex ();
|
||||
static int init (pthread_cond_t *, const pthread_condattr_t *);
|
||||
|
||||
@ -518,9 +526,9 @@ class pthread_rwlock: public verifyable_object
|
||||
{
|
||||
public:
|
||||
static bool is_good_object (pthread_rwlock_t const *);
|
||||
static bool is_good_initializer (pthread_rwlock_t const *);
|
||||
static bool is_good_initializer_or_object (pthread_rwlock_t const *);
|
||||
static bool is_good_initializer_or_bad_object (pthread_rwlock_t const *);
|
||||
static bool is_initializer (pthread_rwlock_t const *);
|
||||
static bool is_initializer_or_object (pthread_rwlock_t const *);
|
||||
static bool is_initializer_or_bad_object (pthread_rwlock_t const *);
|
||||
static void init_mutex ();
|
||||
static int init (pthread_rwlock_t *, const pthread_rwlockattr_t *);
|
||||
|
||||
|
Reference in New Issue
Block a user