2001-12-02 13:23:26 +08:00
|
|
|
/* thread.cc: Locking and threading module functions
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2001-09-12 12:47:47 +08:00
|
|
|
/* Implementation overview and caveats:
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2001-09-12 12:47:47 +08:00
|
|
|
Win32 puts some contraints on what can and cannot be implemented. Where
|
|
|
|
possible we work around those contrainsts. Where we cannot work around
|
|
|
|
the constraints we either pretend to be conformant, or return an error
|
|
|
|
code.
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
Some caveats: PROCESS_SHARED objects, while they pretend to be process
|
2001-09-12 12:47:47 +08:00
|
|
|
shared, may not actually work. Some test cases are needed to determine
|
|
|
|
win32's behaviour. My suspicion is that the win32 handle needs to be
|
|
|
|
opened with different flags for proper operation.
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2001-09-12 12:47:47 +08:00
|
|
|
R.Collins, April 2001. */
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
#include "winsup.h"
|
2008-04-08 00:15:45 +08:00
|
|
|
#include "miscfuncs.h"
|
2007-03-30 00:37:36 +08:00
|
|
|
#include "path.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
2003-11-29 04:55:59 +08:00
|
|
|
#include "sigproc.h"
|
2007-03-30 00:37:36 +08:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2011-04-29 16:27:11 +08:00
|
|
|
#include "ntdll.h"
|
2012-06-18 04:50:24 +08:00
|
|
|
#include "cygwait.h"
|
2004-03-27 04:02:01 +08:00
|
|
|
|
|
|
|
extern "C" void __fp_lock_all ();
|
|
|
|
extern "C" void __fp_unlock_all ();
|
2016-05-20 23:38:22 +08:00
|
|
|
extern "C" bool valid_sched_parameters(const struct sched_param *);
|
2016-05-20 23:45:24 +08:00
|
|
|
extern "C" int sched_get_thread_priority(HANDLE thread);
|
2010-04-06 23:27:34 +08:00
|
|
|
extern "C" int sched_set_thread_priority(HANDLE thread, int priority);
|
2005-07-03 11:25:19 +08:00
|
|
|
static inline verifyable_object_state
|
2010-02-13 04:07:13 +08:00
|
|
|
verifyable_object_isvalid (void const * objectptr, thread_magic_t magic,
|
2005-07-03 11:25:19 +08:00
|
|
|
void *static_ptr1 = NULL,
|
|
|
|
void *static_ptr2 = NULL,
|
|
|
|
void *static_ptr3 = NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
extern int threadsafe;
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
const pthread_t pthread_mutex::_new_mutex = (pthread_t) 1;
|
|
|
|
const pthread_t pthread_mutex::_unlocked_mutex = (pthread_t) 2;
|
|
|
|
const pthread_t pthread_mutex::_destroyed_mutex = (pthread_t) 3;
|
|
|
|
|
POSIX barrier implementation, take 3
The attached patch should address all of the review comments.
Modifed change log:
Newlib:
* libc/include/sys/features.h (_POSIX_BARRIERS): Define for Cygwin.
* libc/include/sys/types.h (pthread_barrier_t)
(pthread_barrierattr_t): Do not define for Cygwin.
Cygwin:
* common.din (pthread_barrierattr_init)
(pthread_barrierattr_setpshared, pthread_barrierattr_getpshared)
(pthread_barrierattr_destroy, pthread_barrier_init)
(pthread_barrier_destroy, pthread_barrier_wait): Export.
* include/cygwin/types.h (pthread_barrierattr_t)
(pthread_barrier_t): Declare.
* include/pthread.h (PTHREAD_BARRIER_SERIAL_THREAD)
(pthread_barrierattr_init, pthread_barrierattr_setpshared)
(pthread_barrierattr_getpshared, pthread_barrierattr_destroy)
(pthread_barrier_init, pthread_barrier_destroy)
(pthread_barrier_wait): Declare.
* thread.h (PTHREAD_BARRIER_MAGIC)
(PTHREAD_BARRIERATTR_MAGIC): Define.
(class pthread_barrierattr, class pthread_barrier): Declare.
* thread.cc (delete_and_clear): New local helper function.
(class pthread_barrierattr, class pthread_barrier): Implement.
* miscfuncs.h (likely, unlikely): New macros.
--
VH
2016-02-13 05:25:59 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static inline
|
|
|
|
void
|
|
|
|
delete_and_clear (T * * const ptr)
|
|
|
|
{
|
|
|
|
delete *ptr;
|
|
|
|
*ptr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
inline bool
|
|
|
|
pthread_mutex::no_owner()
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
if (!owner)
|
|
|
|
{
|
|
|
|
debug_printf ("NULL owner value");
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
else if (owner == _destroyed_mutex)
|
|
|
|
{
|
|
|
|
paranoid_printf ("attempt to use destroyed mutex");
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
else if (owner == _new_mutex || owner == _unlocked_mutex)
|
|
|
|
res = 1;
|
|
|
|
else
|
|
|
|
res = 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-08-18 20:27:05 +08:00
|
|
|
#undef __getreent
|
|
|
|
extern "C" struct _reent *
|
|
|
|
__getreent ()
|
|
|
|
{
|
|
|
|
return &_my_tls.local_clib;
|
|
|
|
}
|
|
|
|
|
2004-03-27 04:02:01 +08:00
|
|
|
extern "C" void
|
|
|
|
__cygwin_lock_init (_LOCK_T *lock)
|
|
|
|
{
|
|
|
|
*lock = _LOCK_T_INITIALIZER;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
__cygwin_lock_init_recursive (_LOCK_T *lock)
|
|
|
|
{
|
|
|
|
*lock = _LOCK_T_RECURSIVE_INITIALIZER;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
__cygwin_lock_fini (_LOCK_T *lock)
|
|
|
|
{
|
|
|
|
pthread_mutex_destroy ((pthread_mutex_t*) lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
__cygwin_lock_lock (_LOCK_T *lock)
|
|
|
|
{
|
2009-06-04 09:45:05 +08:00
|
|
|
paranoid_printf ("threadcount %d. locking", MT_INTERFACE->threadcount);
|
|
|
|
pthread_mutex_lock ((pthread_mutex_t*) lock);
|
2004-03-27 04:02:01 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 00:06:02 +08:00
|
|
|
extern "C" int
|
2004-03-27 04:02:01 +08:00
|
|
|
__cygwin_lock_trylock (_LOCK_T *lock)
|
|
|
|
{
|
2012-05-24 22:17:51 +08:00
|
|
|
return pthread_mutex_trylock ((pthread_mutex_t*) lock);
|
2004-03-27 04:02:01 +08:00
|
|
|
}
|
|
|
|
|
2012-05-30 17:15:38 +08:00
|
|
|
|
2004-03-27 04:02:01 +08:00
|
|
|
extern "C" void
|
|
|
|
__cygwin_lock_unlock (_LOCK_T *lock)
|
|
|
|
{
|
2012-05-24 03:49:39 +08:00
|
|
|
pthread_mutex_unlock ((pthread_mutex_t*) lock);
|
2009-06-04 09:45:05 +08:00
|
|
|
paranoid_printf ("threadcount %d. unlocked", MT_INTERFACE->threadcount);
|
2004-03-27 04:02:01 +08:00
|
|
|
}
|
|
|
|
|
2005-07-03 11:25:19 +08:00
|
|
|
static inline verifyable_object_state
|
2010-02-13 04:07:13 +08:00
|
|
|
verifyable_object_isvalid (void const *objectptr, thread_magic_t magic, void *static_ptr1,
|
2005-07-03 11:25:19 +08:00
|
|
|
void *static_ptr2, void *static_ptr3)
|
|
|
|
{
|
2014-08-22 17:21:33 +08:00
|
|
|
verifyable_object_state state = INVALID_OBJECT;
|
2005-07-05 10:02:23 +08:00
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
if (!objectptr || !(*(const char **) objectptr))
|
|
|
|
__leave;
|
2006-05-28 03:00:36 +08:00
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
verifyable_object **object = (verifyable_object **) objectptr;
|
|
|
|
|
|
|
|
if ((static_ptr1 && *object == static_ptr1) ||
|
|
|
|
(static_ptr2 && *object == static_ptr2) ||
|
|
|
|
(static_ptr3 && *object == static_ptr3))
|
|
|
|
state = VALID_STATIC_OBJECT;
|
|
|
|
else if ((*object)->magic == magic)
|
|
|
|
state = VALID_OBJECT;
|
|
|
|
}
|
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
return state;
|
2005-07-03 11:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static members */
|
|
|
|
inline bool
|
|
|
|
pthread_attr::is_good_object (pthread_attr_t const *attr)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (attr, PTHREAD_ATTR_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
pthread_condattr::is_good_object (pthread_condattr_t const *attr)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (attr, PTHREAD_CONDATTR_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
pthread_rwlockattr::is_good_object (pthread_rwlockattr_t const *attr)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (attr, PTHREAD_RWLOCKATTR_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
pthread_key::is_good_object (pthread_key_t const *key)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (key, PTHREAD_KEY_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-29 18:32:40 +08:00
|
|
|
inline bool
|
|
|
|
pthread_spinlock::is_good_object (pthread_spinlock_t const *mutex)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (mutex, PTHREAD_SPINLOCK_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-07-03 11:25:19 +08:00
|
|
|
inline bool
|
|
|
|
pthread_mutex::is_good_object (pthread_mutex_t const *mutex)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_mutex::is_initializer (pthread_mutex_t const *mutex)
|
2005-07-03 11:25:19 +08:00
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC,
|
|
|
|
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
|
|
|
|
PTHREAD_NORMAL_MUTEX_INITIALIZER_NP,
|
|
|
|
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) != VALID_STATIC_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_mutex::is_initializer_or_object (pthread_mutex_t const *mutex)
|
2005-07-03 11:25:19 +08:00
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC,
|
|
|
|
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
|
|
|
|
PTHREAD_NORMAL_MUTEX_INITIALIZER_NP,
|
|
|
|
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) == INVALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
/* FIXME: Accommodate PTHREAD_MUTEX_ERRORCHECK */
|
2005-07-03 11:25:19 +08:00
|
|
|
inline bool
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_mutex::can_be_unlocked ()
|
2005-07-03 11:25:19 +08:00
|
|
|
{
|
|
|
|
pthread_t self = pthread::self ();
|
2005-09-07 03:22:54 +08:00
|
|
|
/* Check if the mutex is owned by the current thread and can be unlocked.
|
|
|
|
* Also check for the ANONYMOUS owner to cover NORMAL mutexes as well. */
|
2010-02-23 04:36:04 +08:00
|
|
|
bool res = type == PTHREAD_MUTEX_NORMAL || no_owner ()
|
|
|
|
|| (recursion_counter == 1 && pthread::equal (owner, self));
|
2013-04-23 17:44:36 +08:00
|
|
|
pthread_printf ("recursion_counter %u res %d", recursion_counter, res);
|
2010-02-23 04:36:04 +08:00
|
|
|
return res;
|
2005-07-03 11:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
pthread_mutexattr::is_good_object (pthread_mutexattr_t const * attr)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (attr, PTHREAD_MUTEXATTR_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool __attribute__ ((used))
|
|
|
|
pthread::is_good_object (pthread_t const *thread)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (thread, PTHREAD_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread synchronisation */
|
|
|
|
inline bool
|
|
|
|
pthread_cond::is_good_object (pthread_cond_t const *cond)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_cond::is_initializer (pthread_cond_t const *cond)
|
2005-07-03 11:25:19 +08:00
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC, PTHREAD_COND_INITIALIZER) != VALID_STATIC_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_cond::is_initializer_or_object (pthread_cond_t const *cond)
|
2005-07-03 11:25:19 +08:00
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (cond, PTHREAD_COND_MAGIC, PTHREAD_COND_INITIALIZER) == INVALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
POSIX barrier implementation, take 3
The attached patch should address all of the review comments.
Modifed change log:
Newlib:
* libc/include/sys/features.h (_POSIX_BARRIERS): Define for Cygwin.
* libc/include/sys/types.h (pthread_barrier_t)
(pthread_barrierattr_t): Do not define for Cygwin.
Cygwin:
* common.din (pthread_barrierattr_init)
(pthread_barrierattr_setpshared, pthread_barrierattr_getpshared)
(pthread_barrierattr_destroy, pthread_barrier_init)
(pthread_barrier_destroy, pthread_barrier_wait): Export.
* include/cygwin/types.h (pthread_barrierattr_t)
(pthread_barrier_t): Declare.
* include/pthread.h (PTHREAD_BARRIER_SERIAL_THREAD)
(pthread_barrierattr_init, pthread_barrierattr_setpshared)
(pthread_barrierattr_getpshared, pthread_barrierattr_destroy)
(pthread_barrier_init, pthread_barrier_destroy)
(pthread_barrier_wait): Declare.
* thread.h (PTHREAD_BARRIER_MAGIC)
(PTHREAD_BARRIERATTR_MAGIC): Define.
(class pthread_barrierattr, class pthread_barrier): Declare.
* thread.cc (delete_and_clear): New local helper function.
(class pthread_barrierattr, class pthread_barrier): Implement.
* miscfuncs.h (likely, unlikely): New macros.
--
VH
2016-02-13 05:25:59 +08:00
|
|
|
inline bool
|
|
|
|
pthread_barrierattr::is_good_object (pthread_barrierattr_t const *cond)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (cond, PTHREAD_BARRIERATTR_MAGIC)
|
|
|
|
!= VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
pthread_barrier::is_good_object (pthread_barrier_t const *cond)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (cond, PTHREAD_BARRIER_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-07-03 11:25:19 +08:00
|
|
|
/* RW locks */
|
|
|
|
inline bool
|
|
|
|
pthread_rwlock::is_good_object (pthread_rwlock_t const *rwlock)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (rwlock, PTHREAD_RWLOCK_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_rwlock::is_initializer (pthread_rwlock_t const *rwlock)
|
2005-07-03 11:25:19 +08:00
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (rwlock, PTHREAD_RWLOCK_MAGIC, PTHREAD_RWLOCK_INITIALIZER) != VALID_STATIC_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_rwlock::is_initializer_or_object (pthread_rwlock_t const *rwlock)
|
2005-07-03 11:25:19 +08:00
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (rwlock, PTHREAD_RWLOCK_MAGIC, PTHREAD_RWLOCK_INITIALIZER) == INVALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
semaphore::is_good_object (sem_t const * sem)
|
|
|
|
{
|
|
|
|
if (verifyable_object_isvalid (sem, SEM_MAGIC) != VALID_OBJECT)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
void
|
2003-05-16 03:42:51 +08:00
|
|
|
MTinterface::Init ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_mutex::init_mutex ();
|
|
|
|
pthread_cond::init_mutex ();
|
|
|
|
pthread_rwlock::init_mutex ();
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-09-17 17:12:36 +08:00
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
MTinterface::fixup_before_fork ()
|
2002-09-17 17:12:36 +08:00
|
|
|
{
|
|
|
|
pthread_key::fixup_before_fork ();
|
2013-07-23 22:15:20 +08:00
|
|
|
semaphore::fixup_before_fork ();
|
2002-09-17 17:12:36 +08:00
|
|
|
}
|
|
|
|
|
2001-09-11 16:15:39 +08:00
|
|
|
/* This function is called from a single threaded process */
|
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
MTinterface::fixup_after_fork ()
|
2001-09-11 16:15:39 +08:00
|
|
|
{
|
2002-09-17 17:12:36 +08:00
|
|
|
pthread_key::fixup_after_fork ();
|
2003-03-05 04:16:49 +08:00
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
threadcount = 0;
|
2004-04-10 08:53:25 +08:00
|
|
|
pthread::init_mainthread ();
|
2003-03-05 04:16:49 +08:00
|
|
|
|
2003-06-25 04:14:01 +08:00
|
|
|
pthread::fixup_after_fork ();
|
2003-03-23 18:52:02 +08:00
|
|
|
pthread_mutex::fixup_after_fork ();
|
|
|
|
pthread_cond::fixup_after_fork ();
|
|
|
|
pthread_rwlock::fixup_after_fork ();
|
|
|
|
semaphore::fixup_after_fork ();
|
2001-09-11 16:15:39 +08:00
|
|
|
}
|
|
|
|
|
2002-06-10 09:10:45 +08:00
|
|
|
/* pthread calls */
|
|
|
|
|
|
|
|
/* static methods */
|
2002-09-16 18:53:29 +08:00
|
|
|
void
|
2004-04-10 08:53:25 +08:00
|
|
|
pthread::init_mainthread ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread *thread = _my_tls.tid;
|
2002-11-24 21:54:14 +08:00
|
|
|
if (!thread)
|
|
|
|
{
|
2004-04-10 08:53:25 +08:00
|
|
|
thread = new pthread ();
|
|
|
|
if (!thread)
|
2004-05-29 03:50:07 +08:00
|
|
|
api_fatal ("failed to create mainthread object");
|
2002-11-24 21:54:14 +08:00
|
|
|
}
|
|
|
|
|
2013-03-31 20:35:44 +08:00
|
|
|
thread->set_tls_self_pointer ();
|
2003-11-29 04:55:59 +08:00
|
|
|
thread->thread_id = GetCurrentThreadId ();
|
2009-12-19 04:32:04 +08:00
|
|
|
if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
|
|
|
|
GetCurrentProcess (), &thread->win32_obj_id,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS))
|
2003-12-15 22:38:12 +08:00
|
|
|
api_fatal ("failed to create mainthread handle");
|
|
|
|
if (!thread->create_cancel_event ())
|
|
|
|
api_fatal ("couldn't create cancel event for main thread");
|
2004-01-24 07:05:33 +08:00
|
|
|
VerifyHandle (thread->win32_obj_id);
|
2014-07-22 00:32:09 +08:00
|
|
|
/* Make sure the pthread mutex is recursive. See comment in
|
|
|
|
pthread::precreate (called only for subsequent pthreads)
|
|
|
|
for a description. */
|
|
|
|
thread->mutex.set_type (PTHREAD_MUTEX_RECURSIVE);
|
2003-11-29 04:55:59 +08:00
|
|
|
thread->postcreate ();
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
2002-06-10 09:10:45 +08:00
|
|
|
|
|
|
|
pthread *
|
|
|
|
pthread::self ()
|
|
|
|
{
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread *thread = _my_tls.tid;
|
2004-04-10 08:53:25 +08:00
|
|
|
if (!thread)
|
|
|
|
{
|
|
|
|
thread = pthread_null::get_null_pthread ();
|
2013-03-31 20:35:44 +08:00
|
|
|
thread->set_tls_self_pointer ();
|
2004-04-10 08:53:25 +08:00
|
|
|
}
|
|
|
|
return thread;
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
|
|
|
|
2004-04-10 08:53:25 +08:00
|
|
|
void
|
2013-03-31 20:35:44 +08:00
|
|
|
pthread::set_tls_self_pointer ()
|
2004-04-10 08:53:25 +08:00
|
|
|
{
|
2013-03-31 20:35:44 +08:00
|
|
|
cygtls = &_my_tls;
|
|
|
|
_my_tls.tid = this;
|
2004-04-10 08:53:25 +08:00
|
|
|
}
|
|
|
|
|
2003-06-25 04:14:01 +08:00
|
|
|
List<pthread> pthread::threads;
|
|
|
|
|
2002-06-10 09:10:45 +08:00
|
|
|
/* member methods */
|
2001-04-12 12:04:53 +08:00
|
|
|
pthread::pthread ():verifyable_object (PTHREAD_MAGIC), win32_obj_id (0),
|
2011-04-30 18:20:25 +08:00
|
|
|
valid (false), suspended (false), canceled (false),
|
2002-09-23 05:39:03 +08:00
|
|
|
cancelstate (0), canceltype (0), cancel_event (0),
|
2003-06-25 04:14:01 +08:00
|
|
|
joiner (NULL), next (NULL), cleanup_stack (NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-06-25 04:14:01 +08:00
|
|
|
if (this != pthread_null::get_null_pthread ())
|
|
|
|
threads.insert (this);
|
2011-08-24 23:18:17 +08:00
|
|
|
sigprocmask (SIG_SETMASK, NULL, &parent_sigmask);
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
pthread::~pthread ()
|
|
|
|
{
|
|
|
|
if (win32_obj_id)
|
|
|
|
CloseHandle (win32_obj_id);
|
2002-07-04 22:17:30 +08:00
|
|
|
if (cancel_event)
|
|
|
|
CloseHandle (cancel_event);
|
2003-06-25 04:14:01 +08:00
|
|
|
|
|
|
|
if (this != pthread_null::get_null_pthread ())
|
|
|
|
threads.remove (this);
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-12-12 12:15:32 +08:00
|
|
|
bool
|
|
|
|
pthread::create_cancel_event ()
|
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
cancel_event = ::CreateEvent (&sec_none_nih, true, false, NULL);
|
2003-12-12 12:15:32 +08:00
|
|
|
if (!cancel_event)
|
|
|
|
{
|
2003-12-15 22:38:12 +08:00
|
|
|
system_printf ("couldn't create cancel event, %E");
|
2003-12-12 12:15:32 +08:00
|
|
|
/* we need the event for correct behaviour */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
void
|
2002-09-16 18:53:29 +08:00
|
|
|
pthread::precreate (pthread_attr *newattr)
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2002-06-23 15:36:21 +08:00
|
|
|
pthread_mutex *verifyable_mutex_obj = &mutex;
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* already running ? */
|
2001-03-21 10:17:58 +08:00
|
|
|
if (win32_obj_id)
|
|
|
|
return;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
if (newattr)
|
|
|
|
{
|
|
|
|
attr.joinable = newattr->joinable;
|
2001-04-12 12:04:53 +08:00
|
|
|
attr.contentionscope = newattr->contentionscope;
|
|
|
|
attr.inheritsched = newattr->inheritsched;
|
2011-05-16 02:49:40 +08:00
|
|
|
attr.stackaddr = newattr->stackaddr;
|
2001-03-21 10:17:58 +08:00
|
|
|
attr.stacksize = newattr->stacksize;
|
2011-05-16 02:49:40 +08:00
|
|
|
attr.guardsize = newattr->guardsize;
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutex::is_good_object (&verifyable_mutex_obj))
|
2002-06-10 10:40:13 +08:00
|
|
|
{
|
|
|
|
thread_printf ("New thread object access mutex is not valid. this %p",
|
|
|
|
this);
|
|
|
|
magic = 0;
|
|
|
|
return;
|
|
|
|
}
|
2012-05-23 21:24:57 +08:00
|
|
|
/* This mutex MUST be recursive. Consider the following scenario:
|
|
|
|
- The thread installs a cleanup handler.
|
|
|
|
- The cleanup handler calls a function which itself installs a
|
|
|
|
cleanup handler.
|
|
|
|
- pthread_cancel is called for this thread.
|
|
|
|
- The thread's cleanup handler is called under mutex lock condition.
|
|
|
|
- The cleanup handler calls the subsequent function with cleanup handler.
|
|
|
|
- The function runs to completion, so it calls pthread_cleanup_pop.
|
|
|
|
- pthread_cleanup_pop calls pthread::pop_cleanup_handler which will again
|
|
|
|
try to lock the mutex.
|
|
|
|
- Deadlock. */
|
|
|
|
mutex.set_type (PTHREAD_MUTEX_RECURSIVE);
|
2003-12-12 12:15:32 +08:00
|
|
|
if (!create_cancel_event ())
|
|
|
|
magic = 0;
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
|
|
|
|
2005-08-06 00:14:41 +08:00
|
|
|
bool
|
2002-09-16 18:53:29 +08:00
|
|
|
pthread::create (void *(*func) (void *), pthread_attr *newattr,
|
|
|
|
void *threadarg)
|
2002-09-17 00:09:54 +08:00
|
|
|
{
|
2005-08-06 00:14:41 +08:00
|
|
|
bool retval;
|
|
|
|
|
2002-09-16 18:53:29 +08:00
|
|
|
precreate (newattr);
|
|
|
|
if (!magic)
|
2005-08-06 00:14:41 +08:00
|
|
|
return false;
|
2003-11-26 06:58:32 +08:00
|
|
|
|
|
|
|
function = func;
|
|
|
|
arg = threadarg;
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2004-04-13 10:59:19 +08:00
|
|
|
mutex.lock ();
|
2014-07-16 18:21:18 +08:00
|
|
|
/* stackaddr holds the uppermost stack address. See the comments in
|
|
|
|
pthread_attr_setstack and pthread_attr_setstackaddr for a description. */
|
2015-07-05 21:51:37 +08:00
|
|
|
ULONG stacksize = attr.stacksize ?: get_rlimit_stack ();
|
2014-07-16 18:21:18 +08:00
|
|
|
PVOID stackaddr = attr.stackaddr ? ((caddr_t) attr.stackaddr - stacksize)
|
|
|
|
: NULL;
|
|
|
|
win32_obj_id = CygwinCreateThread (thread_init_wrapper, this, stackaddr,
|
|
|
|
stacksize, attr.guardsize, 0, &thread_id);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
if (!win32_obj_id)
|
2002-06-27 22:19:30 +08:00
|
|
|
{
|
2003-11-29 04:55:59 +08:00
|
|
|
thread_printf ("CreateThread failed: this %p, %E", this);
|
2002-06-27 22:19:30 +08:00
|
|
|
magic = 0;
|
|
|
|
}
|
2003-11-26 06:55:31 +08:00
|
|
|
else
|
|
|
|
{
|
2004-04-13 11:25:50 +08:00
|
|
|
postcreate ();
|
2005-06-11 12:56:36 +08:00
|
|
|
while (!cygtls)
|
2010-03-13 07:13:48 +08:00
|
|
|
yield ();
|
2003-11-26 06:55:31 +08:00
|
|
|
}
|
2005-08-06 00:14:41 +08:00
|
|
|
retval = magic;
|
2004-04-13 10:59:19 +08:00
|
|
|
mutex.unlock ();
|
2005-08-06 00:14:41 +08:00
|
|
|
return retval;
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pthread::postcreate ()
|
|
|
|
{
|
2003-11-01 04:42:56 +08:00
|
|
|
valid = true;
|
2003-06-25 04:14:01 +08:00
|
|
|
|
|
|
|
InterlockedIncrement (&MT_INTERFACE->threadcount);
|
2016-05-20 23:45:24 +08:00
|
|
|
|
|
|
|
/* Per POSIX the new thread inherits the sched priority from its caller
|
|
|
|
thread if PTHREAD_INHERIT_SCHED is set.
|
|
|
|
FIXME: set the priority appropriately for system contention scope */
|
|
|
|
if (attr.inheritsched == PTHREAD_INHERIT_SCHED)
|
|
|
|
attr.schedparam.sched_priority
|
|
|
|
= sched_get_thread_priority (GetCurrentThread ());
|
|
|
|
if (attr.schedparam.sched_priority)
|
|
|
|
sched_set_thread_priority (win32_obj_id, attr.schedparam.sched_priority);
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-07-04 22:17:30 +08:00
|
|
|
void
|
|
|
|
pthread::exit (void *value_ptr)
|
|
|
|
{
|
|
|
|
class pthread *thread = this;
|
2014-11-29 04:46:13 +08:00
|
|
|
_cygtls *tls = cygtls; /* Save cygtls before deleting this. */
|
2002-07-04 22:17:30 +08:00
|
|
|
|
|
|
|
// run cleanup handlers
|
|
|
|
pop_all_cleanup_handlers ();
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_key::run_all_destructors ();
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.lock ();
|
2002-07-04 22:17:30 +08:00
|
|
|
// cleanup if thread is in detached state and not joined
|
2003-04-18 03:57:01 +08:00
|
|
|
if (equal (joiner, thread))
|
2002-07-04 22:17:30 +08:00
|
|
|
delete this;
|
|
|
|
else
|
2002-09-17 00:09:54 +08:00
|
|
|
{
|
2003-11-01 04:42:56 +08:00
|
|
|
valid = false;
|
2002-07-04 22:17:30 +08:00
|
|
|
return_ptr = value_ptr;
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.unlock ();
|
2002-07-04 22:17:30 +08:00
|
|
|
}
|
|
|
|
|
2004-09-07 12:05:14 +08:00
|
|
|
if (_my_tls.local_clib.__sdidinit < 0)
|
|
|
|
_my_tls.local_clib.__sdidinit = 0;
|
2017-03-11 03:16:48 +08:00
|
|
|
_reclaim_reent (_REENT);
|
2003-11-12 03:10:47 +08:00
|
|
|
|
2002-07-04 22:17:30 +08:00
|
|
|
if (InterlockedDecrement (&MT_INTERFACE->threadcount) == 0)
|
|
|
|
::exit (0);
|
|
|
|
else
|
2011-08-24 22:23:38 +08:00
|
|
|
{
|
2014-11-29 04:46:13 +08:00
|
|
|
if (tls == _main_tls)
|
2011-08-24 22:23:38 +08:00
|
|
|
{
|
2014-11-29 04:46:13 +08:00
|
|
|
cygheap->find_tls (tls); /* Lock _main_tls mutex. */
|
2011-08-24 22:23:38 +08:00
|
|
|
_cygtls *dummy = (_cygtls *) malloc (sizeof (_cygtls));
|
|
|
|
*dummy = *_main_tls;
|
|
|
|
_main_tls = dummy;
|
2014-11-28 20:10:12 +08:00
|
|
|
_main_tls->initialized = 0;
|
2011-08-24 22:23:38 +08:00
|
|
|
}
|
2014-11-29 04:46:13 +08:00
|
|
|
/* This also unlocks and closes the _main_tls mutex. */
|
|
|
|
tls->remove (INFINITE);
|
2012-12-22 03:32:43 +08:00
|
|
|
ExitThread (0);
|
2011-08-24 22:23:38 +08:00
|
|
|
}
|
2002-07-04 22:17:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 11:16:46 +08:00
|
|
|
pthread::cancel ()
|
2002-07-04 22:17:30 +08:00
|
|
|
{
|
|
|
|
class pthread *thread = this;
|
|
|
|
class pthread *self = pthread::self ();
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.lock ();
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2003-11-01 04:42:56 +08:00
|
|
|
if (!valid)
|
2003-06-25 04:14:01 +08:00
|
|
|
{
|
|
|
|
mutex.unlock ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-04 22:17:30 +08:00
|
|
|
if (canceltype == PTHREAD_CANCEL_DEFERRED ||
|
|
|
|
cancelstate == PTHREAD_CANCEL_DISABLE)
|
|
|
|
{
|
|
|
|
// cancel deferred
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.unlock ();
|
2011-04-30 18:20:25 +08:00
|
|
|
canceled = true;
|
2002-07-04 22:17:30 +08:00
|
|
|
SetEvent (cancel_event);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-04-18 03:57:01 +08:00
|
|
|
else if (equal (thread, self))
|
2002-07-04 22:17:30 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.unlock ();
|
2002-07-04 22:17:30 +08:00
|
|
|
cancel_self ();
|
|
|
|
return 0; // Never reached
|
|
|
|
}
|
|
|
|
|
|
|
|
// cancel asynchronous
|
|
|
|
SuspendThread (win32_obj_id);
|
|
|
|
if (WaitForSingleObject (win32_obj_id, 0) == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
CONTEXT context;
|
|
|
|
context.ContextFlags = CONTEXT_CONTROL;
|
|
|
|
GetThreadContext (win32_obj_id, &context);
|
2012-05-24 01:39:39 +08:00
|
|
|
/* The OS is not foolproof in terms of asynchronous thread cancellation
|
|
|
|
and tends to hang infinitely if we change the instruction pointer.
|
2012-08-17 07:34:45 +08:00
|
|
|
So just don't cancel asynchronously if the thread is currently
|
2012-05-24 01:39:39 +08:00
|
|
|
executing Windows code. Rely on deferred cancellation in this case. */
|
2014-11-29 04:46:13 +08:00
|
|
|
threadlist_t *tl_entry = cygheap->find_tls (cygtls);
|
2012-05-24 01:39:39 +08:00
|
|
|
if (!cygtls->inside_kernel (&context))
|
2012-08-17 07:34:45 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
context.Rip = (ULONG_PTR) pthread::static_cancel_self;
|
|
|
|
#else
|
2012-08-17 07:34:45 +08:00
|
|
|
context.Eip = (DWORD) pthread::static_cancel_self;
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2012-08-17 07:34:45 +08:00
|
|
|
SetThreadContext (win32_obj_id, &context);
|
|
|
|
}
|
2014-11-29 04:46:13 +08:00
|
|
|
cygheap->unlock_tls (tl_entry);
|
2002-07-04 22:17:30 +08:00
|
|
|
}
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.unlock ();
|
2012-05-24 01:39:39 +08:00
|
|
|
/* See above. For instance, a thread which waits for a semaphore in sem_wait
|
2012-08-16 03:07:42 +08:00
|
|
|
will call cygwait which in turn calls WFMO. While this WFMO call
|
2012-05-24 01:39:39 +08:00
|
|
|
is cancelable by setting the thread's cancel_event object, the OS
|
|
|
|
apparently refuses to set the thread's context and continues to wait for
|
|
|
|
the WFMO conditions. This is *not* reflected in the return value of
|
2012-05-22 18:28:05 +08:00
|
|
|
SetThreadContext or ResumeThread, btw.
|
2012-05-24 01:39:39 +08:00
|
|
|
So, what we do here is to set the cancel_event as well to allow at least
|
|
|
|
a deferred cancel. */
|
2012-05-22 18:28:05 +08:00
|
|
|
canceled = true;
|
|
|
|
SetEvent (cancel_event);
|
2002-07-04 22:17:30 +08:00
|
|
|
ResumeThread (win32_obj_id);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-30 02:29:26 +08:00
|
|
|
/* TODO: Insert pthread_testcancel into the required functions.
|
|
|
|
|
|
|
|
Here are the lists of required and optional functions per POSIX.1-2001
|
2011-05-01 00:34:48 +08:00
|
|
|
and POSIX.1-2008. A star (*) indicates that the Cygwin function already
|
|
|
|
is a cancellation point (aka "calls pthread_testcancel"), an o (o)
|
|
|
|
indicates that the function is not implemented in Cygwin.
|
2011-04-30 02:29:26 +08:00
|
|
|
|
|
|
|
Required cancellation points:
|
|
|
|
|
2011-05-01 00:34:48 +08:00
|
|
|
* accept ()
|
2018-07-24 13:31:59 +08:00
|
|
|
* aio_suspend ()
|
2011-08-04 03:17:02 +08:00
|
|
|
* clock_nanosleep ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* close ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* connect ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* creat ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* fcntl () F_SETLKW
|
|
|
|
* fdatasync ()
|
|
|
|
* fsync ()
|
|
|
|
o getmsg ()
|
|
|
|
o getpmsg ()
|
|
|
|
* lockf () F_LOCK
|
2011-04-30 02:29:26 +08:00
|
|
|
* mq_receive ()
|
|
|
|
* mq_send ()
|
|
|
|
* mq_timedreceive ()
|
|
|
|
* mq_timedsend ()
|
|
|
|
msgrcv ()
|
|
|
|
msgsnd ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* msync ()
|
|
|
|
* nanosleep ()
|
|
|
|
* open ()
|
|
|
|
* openat ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* pause ()
|
2011-05-03 23:58:52 +08:00
|
|
|
* poll ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* pread ()
|
2011-05-03 23:58:52 +08:00
|
|
|
* pselect ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* pthread_cond_timedwait ()
|
|
|
|
* pthread_cond_wait ()
|
|
|
|
* pthread_join ()
|
|
|
|
* pthread_testcancel ()
|
2011-05-01 00:34:48 +08:00
|
|
|
o putmsg ()
|
|
|
|
o putpmsg ()
|
|
|
|
* pwrite ()
|
|
|
|
* read ()
|
|
|
|
* readv ()
|
|
|
|
* recv ()
|
|
|
|
* recvfrom ()
|
|
|
|
* recvmsg ()
|
2011-05-03 23:58:52 +08:00
|
|
|
* select ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* sem_timedwait ()
|
|
|
|
* sem_wait ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* send ()
|
|
|
|
* sendmsg ()
|
|
|
|
* sendto ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* sigpause ()
|
|
|
|
* sigsuspend ()
|
2017-12-15 09:05:55 +08:00
|
|
|
* sigtimedwait ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* sigwait ()
|
|
|
|
* sigwaitinfo ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* sleep ()
|
|
|
|
* system ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* tcdrain ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* usleep ()
|
|
|
|
* wait ()
|
|
|
|
* wait3()
|
2011-05-01 00:34:48 +08:00
|
|
|
o waitid ()
|
2011-04-30 02:29:26 +08:00
|
|
|
* waitpid ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* write ()
|
|
|
|
* writev ()
|
2011-04-30 02:29:26 +08:00
|
|
|
|
|
|
|
Optional cancellation points:
|
|
|
|
|
|
|
|
access ()
|
|
|
|
asctime ()
|
|
|
|
asctime_r ()
|
2011-05-01 00:34:48 +08:00
|
|
|
catclose () Implemented externally: libcatgets
|
|
|
|
catgets () Implemented externally: libcatgets
|
|
|
|
catopen () Implemented externally: libcatgets
|
2011-04-30 02:29:26 +08:00
|
|
|
chmod ()
|
|
|
|
chown ()
|
|
|
|
closedir ()
|
|
|
|
closelog ()
|
|
|
|
ctermid ()
|
|
|
|
ctime ()
|
|
|
|
ctime_r ()
|
2011-05-01 00:34:48 +08:00
|
|
|
dbm_close () Implemented externally: libgdbm
|
|
|
|
dbm_delete () Implemented externally: libgdbm
|
|
|
|
dbm_fetch () Implemented externally: libgdbm
|
|
|
|
dbm_nextkey () Implemented externally: libgdbm
|
|
|
|
dbm_open () Implemented externally: libgdbm
|
|
|
|
dbm_store () Implemented externally: libgdbm
|
2011-04-30 02:29:26 +08:00
|
|
|
dlclose ()
|
|
|
|
dlopen ()
|
|
|
|
dprintf ()
|
|
|
|
endgrent ()
|
|
|
|
endhostent ()
|
2011-05-01 00:34:48 +08:00
|
|
|
o endnetent ()
|
2011-04-30 02:29:26 +08:00
|
|
|
endprotoent ()
|
|
|
|
endpwent ()
|
|
|
|
endservent ()
|
|
|
|
endutxent ()
|
|
|
|
faccessat ()
|
|
|
|
fchmod ()
|
|
|
|
fchmodat ()
|
|
|
|
fchown ()
|
|
|
|
fchownat ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* fclose ()
|
|
|
|
* fcntl () (any value)
|
2011-04-30 02:29:26 +08:00
|
|
|
fflush ()
|
|
|
|
fgetc ()
|
|
|
|
fgetpos ()
|
|
|
|
fgets ()
|
|
|
|
fgetwc ()
|
|
|
|
fgetws ()
|
2011-05-01 00:34:48 +08:00
|
|
|
o fmtmsg ()
|
2011-04-30 02:29:26 +08:00
|
|
|
fopen ()
|
|
|
|
fpathconf ()
|
|
|
|
fprintf ()
|
|
|
|
fputc ()
|
|
|
|
fputs ()
|
|
|
|
fputwc ()
|
|
|
|
fputws ()
|
|
|
|
fread ()
|
|
|
|
freopen ()
|
|
|
|
fscanf ()
|
|
|
|
fseek ()
|
|
|
|
fseeko ()
|
|
|
|
fsetpos ()
|
|
|
|
fstat ()
|
|
|
|
fstatat ()
|
|
|
|
ftell ()
|
|
|
|
ftello ()
|
|
|
|
ftw ()
|
|
|
|
futimens ()
|
|
|
|
fwprintf ()
|
|
|
|
fwrite ()
|
|
|
|
fwscanf ()
|
|
|
|
getaddrinfo ()
|
|
|
|
getc ()
|
|
|
|
getc_unlocked ()
|
|
|
|
getchar ()
|
|
|
|
getchar_unlocked ()
|
|
|
|
getcwd ()
|
2011-05-01 00:34:48 +08:00
|
|
|
o getdate ()
|
2011-04-30 02:29:26 +08:00
|
|
|
getdelim ()
|
|
|
|
getgrent ()
|
|
|
|
getgrgid ()
|
|
|
|
getgrgid_r ()
|
|
|
|
getgrnam ()
|
|
|
|
getgrnam_r ()
|
|
|
|
gethostbyaddr ()
|
|
|
|
gethostbyname ()
|
|
|
|
gethostent ()
|
|
|
|
gethostid ()
|
|
|
|
gethostname ()
|
|
|
|
getline ()
|
|
|
|
getlogin ()
|
|
|
|
getlogin_r ()
|
|
|
|
getnameinfo ()
|
2011-05-01 00:34:48 +08:00
|
|
|
o getnetbyaddr ()
|
|
|
|
o getnetbyname ()
|
|
|
|
o getnetent ()
|
2011-04-30 02:29:26 +08:00
|
|
|
getopt () (if opterr is nonzero)
|
|
|
|
getprotobyname ()
|
|
|
|
getprotobynumber ()
|
|
|
|
getprotoent ()
|
|
|
|
getpwent ()
|
|
|
|
* getpwnam ()
|
|
|
|
* getpwnam_r ()
|
|
|
|
* getpwuid ()
|
|
|
|
* getpwuid_r ()
|
|
|
|
gets ()
|
|
|
|
getservbyname ()
|
|
|
|
getservbyport ()
|
|
|
|
getservent ()
|
|
|
|
getutxent ()
|
|
|
|
getutxid ()
|
|
|
|
getutxline ()
|
|
|
|
getwc ()
|
|
|
|
getwchar ()
|
|
|
|
getwd ()
|
|
|
|
glob ()
|
2011-05-01 00:34:48 +08:00
|
|
|
iconv_close () Implemented externally: libiconv
|
|
|
|
iconv_open () Implemented externally: libiconv
|
2011-04-30 02:29:26 +08:00
|
|
|
ioctl ()
|
|
|
|
link ()
|
|
|
|
linkat ()
|
2018-07-24 13:31:59 +08:00
|
|
|
* lio_listio ()
|
2011-04-30 02:29:26 +08:00
|
|
|
localtime ()
|
|
|
|
localtime_r ()
|
2011-05-01 00:34:48 +08:00
|
|
|
* lockf ()
|
2011-04-30 02:29:26 +08:00
|
|
|
lseek ()
|
|
|
|
lstat ()
|
|
|
|
mkdir ()
|
|
|
|
mkdirat ()
|
|
|
|
mkdtemp ()
|
|
|
|
mkfifo ()
|
|
|
|
mkfifoat ()
|
|
|
|
mknod ()
|
|
|
|
mknodat ()
|
|
|
|
mkstemp ()
|
|
|
|
mktime ()
|
|
|
|
nftw ()
|
|
|
|
opendir ()
|
|
|
|
openlog ()
|
|
|
|
pathconf ()
|
|
|
|
pclose ()
|
|
|
|
perror ()
|
|
|
|
popen ()
|
|
|
|
posix_fadvise ()
|
|
|
|
posix_fallocate ()
|
|
|
|
posix_madvise ()
|
|
|
|
posix_openpt ()
|
2013-12-01 18:27:16 +08:00
|
|
|
posix_spawn ()
|
|
|
|
posix_spawnp ()
|
2011-05-01 00:34:48 +08:00
|
|
|
o posix_trace_clear ()
|
|
|
|
o posix_trace_close ()
|
|
|
|
o posix_trace_create ()
|
|
|
|
o posix_trace_create_withlog ()
|
|
|
|
o posix_trace_eventtypelist_getnext_id ()
|
|
|
|
o posix_trace_eventtypelist_rewind ()
|
|
|
|
o posix_trace_flush ()
|
|
|
|
o posix_trace_get_attr ()
|
|
|
|
o posix_trace_get_filter ()
|
|
|
|
o posix_trace_get_status ()
|
|
|
|
o posix_trace_getnext_event ()
|
|
|
|
o posix_trace_open ()
|
|
|
|
o posix_trace_rewind ()
|
|
|
|
o posix_trace_set_filter ()
|
|
|
|
o posix_trace_shutdown ()
|
|
|
|
o posix_trace_timedgetnext_event ()
|
|
|
|
o posix_typed_mem_open ()
|
2011-04-30 02:29:26 +08:00
|
|
|
printf ()
|
2011-05-20 07:44:55 +08:00
|
|
|
psiginfo ()
|
|
|
|
psignal ()
|
2011-04-30 02:29:26 +08:00
|
|
|
pthread_rwlock_rdlock ()
|
2011-12-30 14:47:13 +08:00
|
|
|
o pthread_rwlock_timedrdlock ()
|
|
|
|
o pthread_rwlock_timedwrlock ()
|
2011-04-30 02:29:26 +08:00
|
|
|
pthread_rwlock_wrlock ()
|
|
|
|
putc ()
|
|
|
|
putc_unlocked ()
|
|
|
|
putchar ()
|
|
|
|
putchar_unlocked ()
|
|
|
|
puts ()
|
|
|
|
pututxline ()
|
|
|
|
putwc ()
|
|
|
|
putwchar ()
|
|
|
|
readdir ()
|
|
|
|
readdir_r ()
|
|
|
|
readlink ()
|
|
|
|
readlinkat ()
|
|
|
|
remove ()
|
|
|
|
rename ()
|
|
|
|
renameat ()
|
|
|
|
rewind ()
|
|
|
|
rewinddir ()
|
|
|
|
scandir ()
|
|
|
|
scanf ()
|
|
|
|
seekdir ()
|
|
|
|
semop ()
|
|
|
|
setgrent ()
|
|
|
|
sethostent ()
|
2011-05-01 00:34:48 +08:00
|
|
|
o setnetent ()
|
2011-04-30 02:29:26 +08:00
|
|
|
setprotoent ()
|
|
|
|
setpwent ()
|
|
|
|
setservent ()
|
|
|
|
setutxent ()
|
|
|
|
sigpause ()
|
|
|
|
stat ()
|
|
|
|
strerror ()
|
|
|
|
strerror_r ()
|
|
|
|
strftime ()
|
|
|
|
symlink ()
|
|
|
|
symlinkat ()
|
|
|
|
sync ()
|
|
|
|
syslog ()
|
|
|
|
tmpfile ()
|
|
|
|
tmpnam ()
|
|
|
|
ttyname ()
|
|
|
|
ttyname_r ()
|
|
|
|
tzset ()
|
|
|
|
ungetc ()
|
|
|
|
ungetwc ()
|
|
|
|
unlink ()
|
|
|
|
unlinkat ()
|
|
|
|
utime ()
|
|
|
|
utimensat ()
|
|
|
|
utimes ()
|
|
|
|
vdprintf ()
|
|
|
|
vfprintf ()
|
|
|
|
vfwprintf ()
|
|
|
|
vprintf ()
|
|
|
|
vwprintf ()
|
|
|
|
wcsftime ()
|
|
|
|
wordexp ()
|
|
|
|
wprintf ()
|
|
|
|
wscanf ()
|
|
|
|
|
|
|
|
An implementation may also mark other functions not specified in the
|
|
|
|
standard as cancellation points. In particular, an implementation is
|
|
|
|
likely to mark any nonstandard function that may block as a
|
|
|
|
cancellation point. */
|
|
|
|
|
2002-07-04 22:17:30 +08:00
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
pthread::testcancel ()
|
2002-07-04 22:17:30 +08:00
|
|
|
{
|
|
|
|
if (cancelstate == PTHREAD_CANCEL_DISABLE)
|
|
|
|
return;
|
|
|
|
|
2011-04-30 18:20:25 +08:00
|
|
|
/* We check for the canceled flag first. This allows to use the
|
|
|
|
pthread_testcancel function a lot without adding the overhead of
|
|
|
|
an OS call. Only if the thread is marked as canceled, we wait for
|
|
|
|
cancel_event being really set, on the off-chance that pthread_cancel
|
|
|
|
gets interrupted before calling SetEvent. */
|
|
|
|
if (canceled)
|
|
|
|
{
|
|
|
|
WaitForSingleObject (cancel_event, INFINITE);
|
|
|
|
cancel_self ();
|
|
|
|
}
|
2002-07-04 22:17:30 +08:00
|
|
|
}
|
|
|
|
|
2011-05-02 01:42:41 +08:00
|
|
|
/* Return cancel event handle if it exists *and* cancel is not disabled.
|
|
|
|
This function is supposed to be used from other functions which are
|
|
|
|
cancelable and need the cancel event in a WFMO call. */
|
|
|
|
HANDLE
|
|
|
|
pthread::get_cancel_event ()
|
|
|
|
{
|
|
|
|
pthread_t thread = pthread::self ();
|
|
|
|
|
|
|
|
return (thread && thread->cancel_event
|
|
|
|
&& thread->cancelstate != PTHREAD_CANCEL_DISABLE)
|
|
|
|
? thread->cancel_event : NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-04 22:17:30 +08:00
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
pthread::static_cancel_self ()
|
2002-07-04 22:17:30 +08:00
|
|
|
{
|
2002-09-17 17:12:36 +08:00
|
|
|
pthread::self ()->cancel_self ();
|
2002-07-04 22:17:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread::setcancelstate (int state, int *oldstate)
|
|
|
|
{
|
|
|
|
if (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE)
|
2015-12-09 00:55:33 +08:00
|
|
|
return EINVAL;
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2015-12-09 00:55:33 +08:00
|
|
|
if (oldstate)
|
|
|
|
*oldstate = cancelstate;
|
|
|
|
cancelstate = state;
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2015-12-09 00:55:33 +08:00
|
|
|
return 0;
|
2002-07-04 22:17:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread::setcanceltype (int type, int *oldtype)
|
|
|
|
{
|
|
|
|
if (type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS)
|
2015-12-09 00:55:33 +08:00
|
|
|
return EINVAL;
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2015-12-09 00:55:33 +08:00
|
|
|
if (oldtype)
|
|
|
|
*oldtype = canceltype;
|
|
|
|
canceltype = type;
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2015-12-09 00:55:33 +08:00
|
|
|
return 0;
|
2002-07-04 22:17:30 +08:00
|
|
|
}
|
|
|
|
|
2002-06-10 09:10:45 +08:00
|
|
|
void
|
|
|
|
pthread::push_cleanup_handler (__pthread_cleanup_handler *handler)
|
|
|
|
{
|
|
|
|
if (this != self ())
|
|
|
|
// TODO: do it?
|
2002-09-17 00:09:54 +08:00
|
|
|
api_fatal ("Attempt to push a cleanup handler across threads");
|
2002-06-23 15:36:21 +08:00
|
|
|
handler->next = cleanup_stack;
|
2003-10-25 03:34:47 +08:00
|
|
|
cleanup_stack = handler;
|
2002-06-10 09:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pthread::pop_cleanup_handler (int const execute)
|
|
|
|
{
|
|
|
|
if (this != self ())
|
|
|
|
// TODO: send a signal or something to the thread ?
|
|
|
|
api_fatal ("Attempt to execute a cleanup handler across threads");
|
2002-09-17 00:09:54 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.lock ();
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2002-06-23 15:36:21 +08:00
|
|
|
if (cleanup_stack != NULL)
|
2002-06-10 09:10:45 +08:00
|
|
|
{
|
2002-06-23 15:36:21 +08:00
|
|
|
__pthread_cleanup_handler *handler = cleanup_stack;
|
2002-06-10 09:10:45 +08:00
|
|
|
|
|
|
|
if (execute)
|
2002-09-17 00:09:54 +08:00
|
|
|
(*handler->function) (handler->arg);
|
2002-06-23 15:36:21 +08:00
|
|
|
cleanup_stack = handler->next;
|
2002-06-10 09:10:45 +08:00
|
|
|
}
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex.unlock ();
|
2002-06-10 09:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pthread::pop_all_cleanup_handlers ()
|
|
|
|
{
|
2012-05-23 21:18:34 +08:00
|
|
|
/* We will no honor cancels since the thread is exiting. */
|
|
|
|
cancelstate = PTHREAD_CANCEL_DISABLE;
|
|
|
|
|
2002-06-23 15:36:21 +08:00
|
|
|
while (cleanup_stack != NULL)
|
2002-06-10 09:10:45 +08:00
|
|
|
pop_cleanup_handler (1);
|
|
|
|
}
|
|
|
|
|
2002-09-16 18:53:29 +08:00
|
|
|
void
|
2002-09-17 17:12:36 +08:00
|
|
|
pthread::cancel_self ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
2011-05-04 14:16:59 +08:00
|
|
|
/* Can someone explain why the pthread:: is needed here? g++ complains
|
|
|
|
without it. */
|
|
|
|
pthread::exit (PTHREAD_CANCELED);
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread::get_thread_id ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
return thread_id;
|
|
|
|
}
|
|
|
|
|
2003-06-25 04:14:01 +08:00
|
|
|
void
|
|
|
|
pthread::_fixup_after_fork ()
|
|
|
|
{
|
|
|
|
/* set thread to not running if it is not the forking thread */
|
|
|
|
if (this != pthread::self ())
|
|
|
|
{
|
|
|
|
magic = 0;
|
2003-11-01 04:42:56 +08:00
|
|
|
valid = false;
|
2003-06-25 04:14:01 +08:00
|
|
|
win32_obj_id = NULL;
|
2011-04-30 18:20:25 +08:00
|
|
|
canceled = false;
|
2003-06-25 04:14:01 +08:00
|
|
|
cancel_event = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-01 04:42:56 +08:00
|
|
|
void
|
|
|
|
pthread::suspend_except_self ()
|
|
|
|
{
|
|
|
|
if (valid && this != pthread::self ())
|
2003-11-26 06:57:22 +08:00
|
|
|
SuspendThread (win32_obj_id);
|
2003-11-01 04:42:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pthread::resume ()
|
|
|
|
{
|
|
|
|
if (valid)
|
2003-11-26 06:57:22 +08:00
|
|
|
ResumeThread (win32_obj_id);
|
2003-11-01 04:42:56 +08:00
|
|
|
}
|
|
|
|
|
2002-09-21 06:34:05 +08:00
|
|
|
/* instance members */
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
pthread_attr::pthread_attr ():verifyable_object (PTHREAD_ATTR_MAGIC),
|
2001-04-12 12:04:53 +08:00
|
|
|
joinable (PTHREAD_CREATE_JOINABLE), contentionscope (PTHREAD_SCOPE_PROCESS),
|
2014-07-09 20:06:08 +08:00
|
|
|
inheritsched (PTHREAD_INHERIT_SCHED), stackaddr (NULL), stacksize (0),
|
2016-08-23 01:43:05 +08:00
|
|
|
guardsize (wincap.def_guard_page_size ()), name (NULL)
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2001-04-12 12:04:53 +08:00
|
|
|
schedparam.sched_priority = 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
pthread_attr::~pthread_attr ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
pthread_condattr::pthread_condattr ():verifyable_object
|
2011-07-21 17:39:22 +08:00
|
|
|
(PTHREAD_CONDATTR_MAGIC), shared (PTHREAD_PROCESS_PRIVATE),
|
|
|
|
clock_id (CLOCK_REALTIME)
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
pthread_condattr::~pthread_condattr ()
|
|
|
|
{
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
List<pthread_cond> pthread_cond::conds;
|
|
|
|
|
2003-01-10 04:40:44 +08:00
|
|
|
/* This is used for cond creation protection within a single process only */
|
2003-10-25 03:34:47 +08:00
|
|
|
fast_mutex NO_COPY pthread_cond::cond_initialization_lock;
|
2003-01-10 04:40:44 +08:00
|
|
|
|
|
|
|
/* We can only be called once.
|
|
|
|
TODO: (no rush) use a non copied memory section to
|
|
|
|
hold an initialization flag. */
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_cond::init_mutex ()
|
2003-01-10 04:40:44 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!cond_initialization_lock.init ())
|
2003-01-10 04:40:44 +08:00
|
|
|
api_fatal ("Could not create win32 Mutex for pthread cond static initializer support.");
|
|
|
|
}
|
|
|
|
|
2003-03-19 03:49:38 +08:00
|
|
|
pthread_cond::pthread_cond (pthread_condattr *attr) :
|
|
|
|
verifyable_object (PTHREAD_COND_MAGIC),
|
2011-07-21 17:39:22 +08:00
|
|
|
shared (0), clock_id (CLOCK_REALTIME), waiting (0), pending (0),
|
|
|
|
sem_wait (NULL), mtx_cond(NULL), next (NULL)
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2003-03-19 03:49:38 +08:00
|
|
|
pthread_mutex *verifyable_mutex_obj;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 03:49:38 +08:00
|
|
|
if (attr)
|
2011-07-21 17:39:22 +08:00
|
|
|
{
|
|
|
|
clock_id = attr->clock_id;
|
|
|
|
|
|
|
|
if (attr->shared != PTHREAD_PROCESS_PRIVATE)
|
|
|
|
{
|
|
|
|
magic = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
verifyable_mutex_obj = &mtx_in;
|
|
|
|
if (!pthread_mutex::is_good_object (&verifyable_mutex_obj))
|
2001-05-07 06:23:43 +08:00
|
|
|
{
|
2003-03-19 03:49:38 +08:00
|
|
|
thread_printf ("Internal cond mutex is not valid. this %p", this);
|
2001-06-26 22:57:33 +08:00
|
|
|
magic = 0;
|
2003-03-19 03:49:38 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-03-28 03:52:20 +08:00
|
|
|
/*
|
|
|
|
* Change the mutex type to NORMAL.
|
|
|
|
* This mutex MUST be of type normal
|
|
|
|
*/
|
2010-02-23 04:36:04 +08:00
|
|
|
mtx_in.set_type (PTHREAD_MUTEX_NORMAL);
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
verifyable_mutex_obj = &mtx_out;
|
|
|
|
if (!pthread_mutex::is_good_object (&verifyable_mutex_obj))
|
2003-03-19 03:49:38 +08:00
|
|
|
{
|
|
|
|
thread_printf ("Internal cond mutex is not valid. this %p", this);
|
|
|
|
magic = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Change the mutex type to NORMAL to speed up mutex operations */
|
2010-02-23 04:36:04 +08:00
|
|
|
mtx_out.set_type (PTHREAD_MUTEX_NORMAL);
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
sem_wait = ::CreateSemaphore (&sec_none_nih, 0, INT32_MAX, NULL);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!sem_wait)
|
2003-03-19 03:49:38 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_printf ("CreateSemaphore failed. %E");
|
2003-03-19 03:49:38 +08:00
|
|
|
magic = 0;
|
|
|
|
return;
|
2001-05-07 06:23:43 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
conds.insert (this);
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
pthread_cond::~pthread_cond ()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (sem_wait)
|
|
|
|
CloseHandle (sem_wait);
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
conds.remove (this);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_cond::unblock (const bool all)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
LONG releaseable;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-07-26 12:53:59 +08:00
|
|
|
/*
|
2003-03-19 03:49:38 +08:00
|
|
|
* Block outgoing threads (and avoid simultanous unblocks)
|
2001-12-26 20:46:26 +08:00
|
|
|
*/
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_out.lock ();
|
2003-03-19 03:49:38 +08:00
|
|
|
|
|
|
|
releaseable = waiting - pending;
|
|
|
|
if (releaseable)
|
2001-09-29 17:01:01 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
LONG released;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
|
|
|
if (!pending)
|
2003-07-26 12:53:59 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Block incoming threads until all waiting threads are released.
|
|
|
|
*/
|
|
|
|
mtx_in.lock ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate releaseable again because threads can enter until
|
|
|
|
* the semaphore has been taken, but they can not leave, therefore pending
|
|
|
|
* is unchanged and releaseable can only get higher
|
|
|
|
*/
|
|
|
|
releaseable = waiting - pending;
|
|
|
|
}
|
2003-03-19 03:49:38 +08:00
|
|
|
|
|
|
|
released = all ? releaseable : 1;
|
|
|
|
pending += released;
|
|
|
|
/*
|
|
|
|
* Signal threads
|
|
|
|
*/
|
2003-03-28 03:52:20 +08:00
|
|
|
::ReleaseSemaphore (sem_wait, released, NULL);
|
2001-09-29 17:01:01 +08:00
|
|
|
}
|
2003-03-19 03:49:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* And let the threads release.
|
|
|
|
*/
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_out.unlock ();
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-08-04 00:40:48 +08:00
|
|
|
pthread_cond::wait (pthread_mutex_t mutex, PLARGE_INTEGER timeout)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-21 22:23:47 +08:00
|
|
|
DWORD rv;
|
2003-01-10 04:50:23 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_in.lock ();
|
2013-04-23 17:44:36 +08:00
|
|
|
if (InterlockedIncrement (&waiting) == 1)
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_cond = mutex;
|
|
|
|
else if (mtx_cond != mutex)
|
2003-03-19 03:49:38 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
InterlockedDecrement (&waiting);
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_in.unlock ();
|
2003-03-19 03:49:38 +08:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_in.unlock ();
|
2003-03-19 03:49:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the mutex and wait on semaphore
|
2003-01-10 04:50:23 +08:00
|
|
|
*/
|
2003-03-19 03:49:38 +08:00
|
|
|
++mutex->condwaits;
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex->unlock ();
|
2001-09-12 12:47:47 +08:00
|
|
|
|
2017-03-07 22:15:47 +08:00
|
|
|
rv = cygwait (sem_wait, timeout, cw_cancel | cw_sig_restart);
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_out.lock ();
|
2003-07-26 12:53:59 +08:00
|
|
|
|
2017-03-07 22:15:47 +08:00
|
|
|
if (rv != WAIT_OBJECT_0 && WaitForSingleObject (sem_wait, 0) == WAIT_OBJECT_0)
|
|
|
|
/* Thread got cancelled ot timed out while a signalling is in progress.
|
|
|
|
Set wait result back to signaled */
|
|
|
|
rv = WAIT_OBJECT_0;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
InterlockedDecrement (&waiting);
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:57:06 +08:00
|
|
|
if (rv == WAIT_OBJECT_0 && --pending == 0)
|
2003-03-19 03:49:38 +08:00
|
|
|
/*
|
|
|
|
* All signaled threads are released,
|
|
|
|
* new threads can enter Wait
|
|
|
|
*/
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_in.unlock ();
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_out.unlock ();
|
2003-07-26 12:53:59 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex->lock ();
|
2003-03-19 03:49:38 +08:00
|
|
|
--mutex->condwaits;
|
|
|
|
|
|
|
|
if (rv == WAIT_CANCELED)
|
|
|
|
pthread::static_cancel_self ();
|
|
|
|
else if (rv == WAIT_TIMEOUT)
|
|
|
|
return ETIMEDOUT;
|
|
|
|
|
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-09-11 16:15:39 +08:00
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_cond::_fixup_after_fork ()
|
2001-09-11 16:15:39 +08:00
|
|
|
{
|
2003-03-19 03:49:38 +08:00
|
|
|
waiting = pending = 0;
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_cond = NULL;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
|
|
|
/* Unlock eventually locked mutexes */
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx_in.unlock ();
|
|
|
|
mtx_out.unlock ();
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
sem_wait = ::CreateSemaphore (&sec_none_nih, 0, INT32_MAX, NULL);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!sem_wait)
|
|
|
|
api_fatal ("pthread_cond::_fixup_after_fork () failed to recreate win32 semaphore");
|
2001-09-11 16:15:39 +08:00
|
|
|
}
|
|
|
|
|
POSIX barrier implementation, take 3
The attached patch should address all of the review comments.
Modifed change log:
Newlib:
* libc/include/sys/features.h (_POSIX_BARRIERS): Define for Cygwin.
* libc/include/sys/types.h (pthread_barrier_t)
(pthread_barrierattr_t): Do not define for Cygwin.
Cygwin:
* common.din (pthread_barrierattr_init)
(pthread_barrierattr_setpshared, pthread_barrierattr_getpshared)
(pthread_barrierattr_destroy, pthread_barrier_init)
(pthread_barrier_destroy, pthread_barrier_wait): Export.
* include/cygwin/types.h (pthread_barrierattr_t)
(pthread_barrier_t): Declare.
* include/pthread.h (PTHREAD_BARRIER_SERIAL_THREAD)
(pthread_barrierattr_init, pthread_barrierattr_setpshared)
(pthread_barrierattr_getpshared, pthread_barrierattr_destroy)
(pthread_barrier_init, pthread_barrier_destroy)
(pthread_barrier_wait): Declare.
* thread.h (PTHREAD_BARRIER_MAGIC)
(PTHREAD_BARRIERATTR_MAGIC): Define.
(class pthread_barrierattr, class pthread_barrier): Declare.
* thread.cc (delete_and_clear): New local helper function.
(class pthread_barrierattr, class pthread_barrier): Implement.
* miscfuncs.h (likely, unlikely): New macros.
--
VH
2016-02-13 05:25:59 +08:00
|
|
|
pthread_barrierattr::pthread_barrierattr ()
|
|
|
|
: verifyable_object (PTHREAD_BARRIERATTR_MAGIC)
|
|
|
|
, shared (PTHREAD_PROCESS_PRIVATE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_barrierattr::~pthread_barrierattr ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_barrier::pthread_barrier ()
|
|
|
|
: verifyable_object (PTHREAD_BARRIER_MAGIC)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_barrier::~pthread_barrier ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
pthread_rwlockattr::pthread_rwlockattr ():verifyable_object
|
|
|
|
(PTHREAD_RWLOCKATTR_MAGIC), shared (PTHREAD_PROCESS_PRIVATE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_rwlockattr::~pthread_rwlockattr ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
List<pthread_rwlock> pthread_rwlock::rwlocks;
|
|
|
|
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
/* This is used for rwlock creation protection within a single process only */
|
2003-10-25 03:34:47 +08:00
|
|
|
fast_mutex NO_COPY pthread_rwlock::rwlock_initialization_lock;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
/* We can only be called once.
|
|
|
|
TODO: (no rush) use a non copied memory section to
|
|
|
|
hold an initialization flag. */
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::init_mutex ()
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!rwlock_initialization_lock.init ())
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
api_fatal ("Could not create win32 Mutex for pthread rwlock static initializer support.");
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_rwlock::pthread_rwlock (pthread_rwlockattr *attr) :
|
|
|
|
verifyable_object (PTHREAD_RWLOCK_MAGIC),
|
2003-03-28 03:52:20 +08:00
|
|
|
shared (0), waiting_readers (0), waiting_writers (0), writer (NULL),
|
2003-10-25 03:34:47 +08:00
|
|
|
readers (NULL), readers_mx (), mtx (NULL), cond_readers (NULL), cond_writers (NULL),
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
next (NULL)
|
|
|
|
{
|
|
|
|
pthread_mutex *verifyable_mutex_obj = &mtx;
|
|
|
|
pthread_cond *verifyable_cond_obj;
|
|
|
|
|
2003-10-25 03:34:47 +08:00
|
|
|
if (!readers_mx.init ())
|
|
|
|
{
|
|
|
|
thread_printf ("Internal rwlock synchronisation mutex is not valid. this %p", this);
|
|
|
|
magic = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
if (attr)
|
|
|
|
if (attr->shared != PTHREAD_PROCESS_PRIVATE)
|
|
|
|
{
|
2003-07-26 12:53:59 +08:00
|
|
|
magic = 0;
|
|
|
|
return;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutex::is_good_object (&verifyable_mutex_obj))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
thread_printf ("Internal rwlock mutex is not valid. this %p", this);
|
|
|
|
magic = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Change the mutex type to NORMAL to speed up mutex operations */
|
2010-02-23 04:36:04 +08:00
|
|
|
mtx.set_type (PTHREAD_MUTEX_NORMAL);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
verifyable_cond_obj = &cond_readers;
|
|
|
|
if (!pthread_cond::is_good_object (&verifyable_cond_obj))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
thread_printf ("Internal rwlock readers cond is not valid. this %p", this);
|
|
|
|
magic = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
verifyable_cond_obj = &cond_writers;
|
|
|
|
if (!pthread_cond::is_good_object (&verifyable_cond_obj))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
thread_printf ("Internal rwlock writers cond is not valid. this %p", this);
|
|
|
|
magic = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
rwlocks.insert (this);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pthread_rwlock::~pthread_rwlock ()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
rwlocks.remove (this);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-08-04 03:31:38 +08:00
|
|
|
pthread_rwlock::rdlock (PLARGE_INTEGER timeout)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
struct RWLOCK_READER *reader;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.lock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2013-01-08 03:34:44 +08:00
|
|
|
reader = lookup_reader ();
|
2009-01-20 20:40:31 +08:00
|
|
|
if (reader)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
if (reader->n < UINT32_MAX)
|
2009-01-20 20:40:31 +08:00
|
|
|
++reader->n;
|
|
|
|
else
|
2017-08-04 05:09:57 +08:00
|
|
|
result = EAGAIN;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
while (writer || waiting_writers)
|
2003-07-26 12:53:59 +08:00
|
|
|
{
|
2017-08-04 05:14:21 +08:00
|
|
|
int ret;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_cleanup_push (pthread_rwlock::rdlock_cleanup, this);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
++waiting_readers;
|
2017-08-04 05:14:21 +08:00
|
|
|
ret = cond_readers.wait (&mtx, timeout);
|
2003-03-28 03:52:20 +08:00
|
|
|
--waiting_readers;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
pthread_cleanup_pop (0);
|
2017-08-04 05:14:21 +08:00
|
|
|
|
|
|
|
if (ret == ETIMEDOUT)
|
|
|
|
{
|
|
|
|
result = ETIMEDOUT;
|
|
|
|
goto DONE;
|
|
|
|
}
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2013-01-08 03:34:44 +08:00
|
|
|
if ((reader = add_reader ()))
|
|
|
|
++reader->n;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = EAGAIN;
|
|
|
|
goto DONE;
|
|
|
|
}
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
DONE:
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::tryrdlock ()
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.lock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2013-01-08 00:01:10 +08:00
|
|
|
if (writer || waiting_writers)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
result = EBUSY;
|
|
|
|
else
|
|
|
|
{
|
2013-01-08 03:34:44 +08:00
|
|
|
RWLOCK_READER *reader = lookup_reader ();
|
2013-01-08 00:01:10 +08:00
|
|
|
if (!reader)
|
|
|
|
reader = add_reader ();
|
2013-04-23 17:44:36 +08:00
|
|
|
if (reader && reader->n < UINT32_MAX)
|
2009-01-20 20:40:31 +08:00
|
|
|
++reader->n;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
else
|
2003-07-26 12:53:59 +08:00
|
|
|
result = EAGAIN;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
2003-07-26 12:53:59 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-08-04 03:31:38 +08:00
|
|
|
pthread_rwlock::wrlock (PLARGE_INTEGER timeout)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
pthread_t self = pthread::self ();
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.lock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
if (writer == self || lookup_reader ())
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
result = EDEADLK;
|
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (writer || readers)
|
2003-07-26 12:53:59 +08:00
|
|
|
{
|
2017-08-04 05:14:21 +08:00
|
|
|
int ret;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_cleanup_push (pthread_rwlock::wrlock_cleanup, this);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
++waiting_writers;
|
2017-08-04 05:14:21 +08:00
|
|
|
ret = cond_writers.wait (&mtx, timeout);
|
2003-03-28 03:52:20 +08:00
|
|
|
--waiting_writers;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
pthread_cleanup_pop (0);
|
2017-08-04 05:14:21 +08:00
|
|
|
|
|
|
|
if (ret == ETIMEDOUT)
|
|
|
|
{
|
|
|
|
result = ETIMEDOUT;
|
|
|
|
goto DONE;
|
|
|
|
}
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
writer = self;
|
|
|
|
|
|
|
|
DONE:
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::trywrlock ()
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
pthread_t self = pthread::self ();
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.lock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
if (writer || readers)
|
|
|
|
result = EBUSY;
|
|
|
|
else
|
|
|
|
writer = self;
|
2003-07-26 12:53:59 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::unlock ()
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.lock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
if (writer)
|
|
|
|
{
|
2013-01-08 03:34:44 +08:00
|
|
|
if (writer != pthread::self ())
|
2003-07-26 12:53:59 +08:00
|
|
|
{
|
|
|
|
result = EPERM;
|
|
|
|
goto DONE;
|
|
|
|
}
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
writer = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-08 03:34:44 +08:00
|
|
|
struct RWLOCK_READER *reader = lookup_reader ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
if (!reader)
|
2003-07-26 12:53:59 +08:00
|
|
|
{
|
|
|
|
result = EPERM;
|
|
|
|
goto DONE;
|
|
|
|
}
|
2009-01-20 20:40:31 +08:00
|
|
|
if (--reader->n > 0)
|
2011-06-06 13:02:13 +08:00
|
|
|
goto DONE;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
remove_reader (reader);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
delete reader;
|
|
|
|
}
|
|
|
|
|
2003-04-16 04:14:12 +08:00
|
|
|
release ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
DONE:
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-01-08 00:01:10 +08:00
|
|
|
pthread_rwlock::RWLOCK_READER *
|
|
|
|
pthread_rwlock::add_reader ()
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2013-01-08 00:01:10 +08:00
|
|
|
RWLOCK_READER *rd = new RWLOCK_READER;
|
|
|
|
if (rd)
|
|
|
|
List_insert (readers, rd);
|
|
|
|
return rd;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::remove_reader (struct RWLOCK_READER *rd)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2003-10-25 03:34:47 +08:00
|
|
|
List_remove (readers_mx, readers, rd);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pthread_rwlock::RWLOCK_READER *
|
2013-01-08 03:34:44 +08:00
|
|
|
pthread_rwlock::lookup_reader ()
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2003-10-25 03:34:47 +08:00
|
|
|
readers_mx.lock ();
|
2013-01-08 03:34:44 +08:00
|
|
|
pthread_t thread = pthread::self ();
|
2003-10-25 03:34:47 +08:00
|
|
|
|
|
|
|
struct RWLOCK_READER *cur = readers;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2003-10-25 03:34:47 +08:00
|
|
|
while (cur && cur->thread != thread)
|
|
|
|
cur = cur->next;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2003-10-25 03:34:47 +08:00
|
|
|
readers_mx.unlock ();
|
|
|
|
|
|
|
|
return cur;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::rdlock_cleanup (void *arg)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
pthread_rwlock *rwlock = (pthread_rwlock *) arg;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
--(rwlock->waiting_readers);
|
2003-04-16 04:14:12 +08:00
|
|
|
rwlock->release ();
|
2003-03-28 03:52:20 +08:00
|
|
|
rwlock->mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::wrlock_cleanup (void *arg)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
pthread_rwlock *rwlock = (pthread_rwlock *) arg;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
--(rwlock->waiting_writers);
|
2003-04-16 04:14:12 +08:00
|
|
|
rwlock->release ();
|
2003-03-28 03:52:20 +08:00
|
|
|
rwlock->mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_rwlock::_fixup_after_fork ()
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
pthread_t self = pthread::self ();
|
|
|
|
struct RWLOCK_READER **temp = &readers;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
waiting_readers = 0;
|
|
|
|
waiting_writers = 0;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
|
2003-10-25 03:34:47 +08:00
|
|
|
if (!readers_mx.init ())
|
|
|
|
api_fatal ("pthread_rwlock::_fixup_after_fork () failed to recreate mutex");
|
|
|
|
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
/* Unlock eventually locked mutex */
|
2003-03-28 03:52:20 +08:00
|
|
|
mtx.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
/*
|
|
|
|
* Remove all readers except self
|
|
|
|
*/
|
|
|
|
while (*temp)
|
|
|
|
{
|
|
|
|
if ((*temp)->thread == self)
|
2003-07-26 12:53:59 +08:00
|
|
|
temp = &((*temp)->next);
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
else
|
2003-07-26 12:53:59 +08:00
|
|
|
{
|
|
|
|
struct RWLOCK_READER *cur = *temp;
|
|
|
|
*temp = (*temp)->next;
|
|
|
|
delete cur;
|
|
|
|
}
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-17 17:12:36 +08:00
|
|
|
/* pthread_key */
|
|
|
|
/* static members */
|
2002-10-01 05:06:05 +08:00
|
|
|
/* This stores pthread_key information across fork() boundaries */
|
|
|
|
List<pthread_key> pthread_key::keys;
|
2002-09-21 11:20:27 +08:00
|
|
|
|
2002-09-17 17:12:36 +08:00
|
|
|
/* non-static members */
|
2001-09-11 16:15:39 +08:00
|
|
|
|
2002-09-21 09:59:46 +08:00
|
|
|
pthread_key::pthread_key (void (*aDestructor) (void *)):verifyable_object (PTHREAD_KEY_MAGIC), destructor (aDestructor)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
tls_index = TlsAlloc ();
|
|
|
|
if (tls_index == TLS_OUT_OF_INDEXES)
|
2001-03-21 10:17:58 +08:00
|
|
|
magic = 0;
|
2002-09-21 11:20:27 +08:00
|
|
|
else
|
2003-03-28 03:52:20 +08:00
|
|
|
keys.insert (this);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
pthread_key::~pthread_key ()
|
|
|
|
{
|
2002-09-21 11:20:27 +08:00
|
|
|
/* We may need to make the list code lock the list during operations
|
|
|
|
*/
|
2002-09-23 05:39:03 +08:00
|
|
|
if (magic != 0)
|
2002-09-17 17:12:36 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
keys.remove (this);
|
|
|
|
TlsFree (tls_index);
|
2002-09-17 17:12:36 +08:00
|
|
|
}
|
2001-04-23 10:56:19 +08:00
|
|
|
}
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2002-09-17 17:12:36 +08:00
|
|
|
void
|
2003-10-25 03:34:47 +08:00
|
|
|
pthread_key::_fixup_before_fork ()
|
2002-09-17 17:12:36 +08:00
|
|
|
{
|
|
|
|
fork_buf = get ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-25 03:34:47 +08:00
|
|
|
pthread_key::_fixup_after_fork ()
|
2002-09-17 17:12:36 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
tls_index = TlsAlloc ();
|
|
|
|
if (tls_index == TLS_OUT_OF_INDEXES)
|
|
|
|
api_fatal ("pthread_key::recreate_key_from_buffer () failed to reallocate Tls storage");
|
2002-09-17 17:12:36 +08:00
|
|
|
set (fork_buf);
|
|
|
|
}
|
|
|
|
|
2002-09-21 09:59:46 +08:00
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_key::run_destructor ()
|
2002-09-21 09:59:46 +08:00
|
|
|
{
|
2002-09-30 09:19:45 +08:00
|
|
|
if (destructor)
|
2002-09-27 23:08:50 +08:00
|
|
|
{
|
2002-09-30 09:19:45 +08:00
|
|
|
void *oldValue = get ();
|
2002-09-27 23:08:50 +08:00
|
|
|
if (oldValue)
|
|
|
|
{
|
2003-01-15 04:31:47 +08:00
|
|
|
set (NULL);
|
|
|
|
destructor (oldValue);
|
2002-09-27 23:08:50 +08:00
|
|
|
}
|
|
|
|
}
|
2002-09-21 09:59:46 +08:00
|
|
|
}
|
|
|
|
|
2010-02-13 04:07:13 +08:00
|
|
|
/* pshared mutexs */
|
2001-04-21 22:23:47 +08:00
|
|
|
|
2002-09-21 06:34:05 +08:00
|
|
|
/* static members */
|
2003-03-19 03:39:21 +08:00
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
List<pthread_mutex> pthread_mutex::mutexes;
|
|
|
|
|
2002-10-01 05:06:05 +08:00
|
|
|
/* This is used for mutex creation protection within a single process only */
|
2003-10-25 03:34:47 +08:00
|
|
|
fast_mutex NO_COPY pthread_mutex::mutex_initialization_lock;
|
2002-09-30 07:47:45 +08:00
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_mutex::init_mutex ()
|
2002-09-30 07:47:45 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!mutex_initialization_lock.init ())
|
2002-09-30 23:11:55 +08:00
|
|
|
api_fatal ("Could not create win32 Mutex for pthread mutex static initializer support.");
|
2002-09-30 07:47:45 +08:00
|
|
|
}
|
|
|
|
|
2003-01-10 04:50:23 +08:00
|
|
|
pthread_mutex::pthread_mutex (pthread_mutexattr *attr) :
|
2010-02-13 04:07:13 +08:00
|
|
|
verifyable_object (0), /* set magic to zero initially */
|
2003-03-19 03:39:21 +08:00
|
|
|
lock_counter (0),
|
2011-03-29 18:32:40 +08:00
|
|
|
win32_obj_id (NULL), owner (_new_mutex),
|
2007-02-22 20:34:55 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
tid (0),
|
|
|
|
#endif
|
2011-03-29 18:32:40 +08:00
|
|
|
recursion_counter (0), condwaits (0),
|
2014-07-14 17:42:15 +08:00
|
|
|
type (PTHREAD_MUTEX_NORMAL),
|
2003-01-15 04:31:47 +08:00
|
|
|
pshared (PTHREAD_PROCESS_PRIVATE)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-02-10 15:25:26 +08:00
|
|
|
win32_obj_id = ::CreateEvent (&sec_none_nih, false, false, NULL);
|
2003-01-10 04:50:23 +08:00
|
|
|
if (!win32_obj_id)
|
2010-02-13 04:07:13 +08:00
|
|
|
return;
|
2003-01-10 04:50:23 +08:00
|
|
|
/*attr checked in the C call */
|
2010-02-13 04:07:13 +08:00
|
|
|
if (!attr)
|
|
|
|
/* handled in the caller */;
|
|
|
|
else if (attr->pshared != PTHREAD_PROCESS_SHARED)
|
|
|
|
type = attr->mutextype;
|
|
|
|
else
|
|
|
|
return; /* Not implemented */
|
2003-01-10 04:50:23 +08:00
|
|
|
|
2010-02-13 04:07:13 +08:00
|
|
|
magic = PTHREAD_MUTEX_MAGIC;
|
2003-03-28 03:52:20 +08:00
|
|
|
mutexes.insert (this);
|
2001-04-12 12:04:53 +08:00
|
|
|
}
|
2001-03-21 10:17:58 +08:00
|
|
|
|
|
|
|
pthread_mutex::~pthread_mutex ()
|
|
|
|
{
|
2003-01-10 04:50:23 +08:00
|
|
|
if (win32_obj_id)
|
2010-02-23 04:36:04 +08:00
|
|
|
{
|
|
|
|
CloseHandle (win32_obj_id);
|
|
|
|
win32_obj_id = NULL;
|
|
|
|
}
|
2003-01-10 04:50:23 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
mutexes.remove (this);
|
2010-02-23 04:36:04 +08:00
|
|
|
owner = _destroyed_mutex;
|
|
|
|
magic = 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2017-08-04 01:13:21 +08:00
|
|
|
pthread_mutex::lock (PLARGE_INTEGER timeout)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread_t self = ::pthread_self ();
|
2003-01-10 04:50:23 +08:00
|
|
|
int result = 0;
|
2003-01-15 04:31:47 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
if (InterlockedIncrement (&lock_counter) == 1)
|
2003-03-28 03:52:20 +08:00
|
|
|
set_owner (self);
|
2010-02-23 04:36:04 +08:00
|
|
|
else if (type == PTHREAD_MUTEX_NORMAL /* potentially causes deadlock */
|
|
|
|
|| !pthread::equal (owner, self))
|
2005-06-11 12:56:36 +08:00
|
|
|
{
|
2017-08-04 05:14:21 +08:00
|
|
|
if (cygwait (win32_obj_id, timeout, cw_sig | cw_sig_restart)
|
|
|
|
!= WAIT_TIMEOUT)
|
|
|
|
set_owner (self);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InterlockedDecrement (&lock_counter);
|
|
|
|
result = ETIMEDOUT;
|
|
|
|
}
|
2005-06-11 12:56:36 +08:00
|
|
|
}
|
|
|
|
else
|
2001-09-12 11:18:05 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
InterlockedDecrement (&lock_counter);
|
2003-03-28 03:57:06 +08:00
|
|
|
if (type == PTHREAD_MUTEX_RECURSIVE)
|
2003-03-28 03:52:20 +08:00
|
|
|
result = lock_recursive ();
|
2003-01-10 04:50:23 +08:00
|
|
|
else
|
2003-01-15 04:31:47 +08:00
|
|
|
result = EDEADLK;
|
2001-09-12 11:18:05 +08:00
|
|
|
}
|
2003-01-15 04:31:47 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
pthread_printf ("mutex %p, self %p, owner %p, lock_counter %d, recursion_counter %u",
|
2010-02-23 04:36:04 +08:00
|
|
|
this, self, owner, lock_counter, recursion_counter);
|
2003-01-10 04:50:23 +08:00
|
|
|
return result;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread_mutex::unlock ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-02-23 15:12:38 +08:00
|
|
|
int res = 0;
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread_t self = ::pthread_self ();
|
2010-02-23 04:36:04 +08:00
|
|
|
if (type == PTHREAD_MUTEX_NORMAL)
|
|
|
|
/* no error checking */;
|
|
|
|
else if (no_owner ())
|
2014-07-14 17:42:15 +08:00
|
|
|
res = type == PTHREAD_MUTEX_ERRORCHECK ? EPERM : 0;
|
2010-02-23 04:36:04 +08:00
|
|
|
else if (!pthread::equal (owner, self))
|
|
|
|
res = EPERM;
|
2010-02-23 15:12:38 +08:00
|
|
|
if (!res && recursion_counter > 0 && --recursion_counter == 0)
|
2010-02-23 04:36:04 +08:00
|
|
|
/* Don't try to unlock anything if recursion_counter == 0.
|
|
|
|
This means the mutex was never locked or that we've forked. */
|
2001-09-12 11:18:05 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
owner = (pthread_t) _unlocked_mutex;
|
2007-02-22 20:34:55 +08:00
|
|
|
#ifdef DEBUGGING
|
2012-12-23 03:35:41 +08:00
|
|
|
tid = 0; // thread-id
|
2007-02-22 20:34:55 +08:00
|
|
|
#endif
|
2013-04-23 17:44:36 +08:00
|
|
|
if (InterlockedDecrement (&lock_counter))
|
2010-02-13 04:07:13 +08:00
|
|
|
::SetEvent (win32_obj_id); // Another thread is waiting
|
2010-02-23 04:36:04 +08:00
|
|
|
res = 0;
|
2001-09-12 11:18:05 +08:00
|
|
|
}
|
2003-01-15 04:31:47 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
pthread_printf ("mutex %p, owner %p, self %p, lock_counter %d, recursion_counter %u, type %d, res %d",
|
2010-02-23 15:12:38 +08:00
|
|
|
this, owner, self, lock_counter, recursion_counter, type, res);
|
2010-02-23 04:36:04 +08:00
|
|
|
return res;
|
2003-01-10 04:50:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread_mutex::trylock ()
|
2003-01-10 04:50:23 +08:00
|
|
|
{
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread_t self = ::pthread_self ();
|
|
|
|
int result = 0;
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
if (InterlockedCompareExchange (&lock_counter, 1, 0) == 0)
|
2010-02-10 15:25:26 +08:00
|
|
|
set_owner (self);
|
|
|
|
else if (type == PTHREAD_MUTEX_RECURSIVE && pthread::equal (owner, self))
|
|
|
|
result = lock_recursive ();
|
|
|
|
else
|
|
|
|
result = EBUSY;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_mutex::destroy ()
|
|
|
|
{
|
|
|
|
if (condwaits || trylock ())
|
2003-01-10 04:50:23 +08:00
|
|
|
// Do not destroy a condwaited or locked mutex
|
|
|
|
return EBUSY;
|
2008-11-08 02:32:41 +08:00
|
|
|
else if (recursion_counter > 1)
|
2003-01-10 04:50:23 +08:00
|
|
|
{
|
|
|
|
// Do not destroy a recursive locked mutex
|
2008-11-08 02:32:41 +08:00
|
|
|
recursion_counter--;
|
2003-01-10 04:50:23 +08:00
|
|
|
return EBUSY;
|
|
|
|
}
|
2003-01-15 04:31:47 +08:00
|
|
|
|
2003-01-10 04:50:23 +08:00
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-15 04:31:47 +08:00
|
|
|
|
2001-09-11 16:15:39 +08:00
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_mutex::_fixup_after_fork ()
|
2001-09-11 16:15:39 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_printf ("mutex %p", this);
|
2001-09-11 16:15:39 +08:00
|
|
|
if (pshared != PTHREAD_PROCESS_PRIVATE)
|
2008-09-30 10:22:39 +08:00
|
|
|
api_fatal ("pthread_mutex::_fixup_after_fork () doesn't understand PROCESS_SHARED mutex's");
|
2003-01-10 04:50:23 +08:00
|
|
|
|
2008-09-30 10:22:39 +08:00
|
|
|
/* All waiting threads are gone after a fork */
|
2008-11-08 02:32:41 +08:00
|
|
|
recursion_counter = 0;
|
2008-09-30 10:22:39 +08:00
|
|
|
lock_counter = 0;
|
2001-09-12 11:18:05 +08:00
|
|
|
condwaits = 0;
|
2008-09-30 10:39:07 +08:00
|
|
|
#ifdef DEBUGGING
|
2008-11-08 02:32:41 +08:00
|
|
|
tid = 0xffffffff; /* Don't know the tid after a fork */
|
2008-09-30 10:39:07 +08:00
|
|
|
#endif
|
2010-02-10 15:25:26 +08:00
|
|
|
win32_obj_id = ::CreateEvent (&sec_none_nih, false, false, NULL);
|
2008-11-08 02:32:41 +08:00
|
|
|
if (!win32_obj_id)
|
2010-02-23 04:36:04 +08:00
|
|
|
api_fatal ("pthread_mutex::_fixup_after_fork () failed to recreate win32 event for mutex");
|
2001-09-11 16:15:39 +08:00
|
|
|
}
|
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
pthread_mutexattr::pthread_mutexattr ():verifyable_object (PTHREAD_MUTEXATTR_MAGIC),
|
2014-07-14 17:42:15 +08:00
|
|
|
pshared (PTHREAD_PROCESS_PRIVATE), mutextype (PTHREAD_MUTEX_NORMAL)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutexattr::~pthread_mutexattr ()
|
|
|
|
{
|
2001-04-23 10:56:19 +08:00
|
|
|
}
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2011-03-29 18:32:40 +08:00
|
|
|
/* pshared spinlocks
|
|
|
|
|
|
|
|
The infrastructure is provided by the underlying pthread_mutex class.
|
|
|
|
The rest is a simplification implementing spin locking. */
|
|
|
|
|
|
|
|
pthread_spinlock::pthread_spinlock (int pshared) :
|
|
|
|
pthread_mutex (NULL)
|
|
|
|
{
|
|
|
|
magic = PTHREAD_SPINLOCK_MAGIC;
|
|
|
|
set_type (PTHREAD_MUTEX_NORMAL);
|
|
|
|
set_shared (pshared);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_spinlock::lock ()
|
|
|
|
{
|
|
|
|
pthread_t self = ::pthread_self ();
|
|
|
|
int result = -1;
|
2016-03-11 18:28:27 +08:00
|
|
|
unsigned spins = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
We want to spin using 'pause' instruction on multi-core system but we
|
|
|
|
want to avoid this on single-core systems.
|
|
|
|
|
|
|
|
The limit of 1000 spins is semi-arbitrary. Microsoft suggests (in their
|
|
|
|
InitializeCriticalSectionAndSpinCount documentation on MSDN) they are
|
|
|
|
using spin count limit 4000 for their heap manager critical
|
|
|
|
sections. Other source suggest spin count as small as 200 for fast path
|
|
|
|
of mutex locking.
|
|
|
|
*/
|
|
|
|
unsigned const FAST_SPINS_LIMIT = wincap.cpu_count () != 1 ? 1000 : 0;
|
2011-03-29 18:32:40 +08:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
if (InterlockedExchange (&lock_counter, 1) == 0)
|
2011-03-29 18:32:40 +08:00
|
|
|
{
|
|
|
|
set_owner (self);
|
|
|
|
result = 0;
|
|
|
|
}
|
2016-03-11 18:28:27 +08:00
|
|
|
else if (unlikely(pthread::equal (owner, self)))
|
2011-03-29 18:32:40 +08:00
|
|
|
result = EDEADLK;
|
2016-03-11 18:28:27 +08:00
|
|
|
else if (spins < FAST_SPINS_LIMIT)
|
|
|
|
{
|
|
|
|
++spins;
|
|
|
|
__asm__ volatile ("pause":::);
|
|
|
|
}
|
2011-08-04 00:40:48 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Minimal timeout to minimize CPU usage while still spinning. */
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
timeout.QuadPart = -10000LL;
|
2012-06-18 04:50:24 +08:00
|
|
|
/* FIXME: no cancel? */
|
2012-08-16 03:07:42 +08:00
|
|
|
cygwait (win32_obj_id, &timeout, cw_sig);
|
2011-08-04 00:40:48 +08:00
|
|
|
}
|
2011-03-29 18:32:40 +08:00
|
|
|
}
|
|
|
|
while (result == -1);
|
|
|
|
pthread_printf ("spinlock %p, self %p, owner %p", this, self, owner);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_spinlock::unlock ()
|
|
|
|
{
|
|
|
|
pthread_t self = ::pthread_self ();
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
if (!pthread::equal (owner, self))
|
|
|
|
result = EPERM;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
owner = (pthread_t) _unlocked_mutex;
|
|
|
|
#ifdef DEBUGGING
|
2012-12-23 03:35:41 +08:00
|
|
|
tid = 0; // thread-id
|
2011-03-29 18:32:40 +08:00
|
|
|
#endif
|
2013-04-23 17:44:36 +08:00
|
|
|
InterlockedExchange (&lock_counter, 0);
|
2011-03-29 18:32:40 +08:00
|
|
|
::SetEvent (win32_obj_id);
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
pthread_printf ("spinlock %p, owner %p, self %p, res %d",
|
|
|
|
this, owner, self, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-12-14 15:09:22 +08:00
|
|
|
DWORD WINAPI
|
|
|
|
pthread::thread_init_wrapper (void *arg)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-12-03 13:21:55 +08:00
|
|
|
pthread *thread = (pthread *) arg;
|
2013-04-08 07:53:00 +08:00
|
|
|
/* This *must* be set prior to calling set_tls_self_pointer or there is
|
|
|
|
a race with the signal processing code which may miss the signal mask
|
|
|
|
settings. */
|
2013-03-31 20:35:44 +08:00
|
|
|
_my_tls.sigmask = thread->parent_sigmask;
|
|
|
|
thread->set_tls_self_pointer ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2016-07-28 07:40:23 +08:00
|
|
|
// Give thread default name
|
|
|
|
SetThreadName (GetCurrentThreadId (), program_invocation_short_name);
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
thread->mutex.lock ();
|
2003-12-24 00:26:31 +08:00
|
|
|
|
2002-06-05 20:39:55 +08:00
|
|
|
// if thread is detached force cleanup on exit
|
2002-06-10 09:10:45 +08:00
|
|
|
if (thread->attr.joinable == PTHREAD_CREATE_DETACHED && thread->joiner == NULL)
|
2002-11-24 21:54:14 +08:00
|
|
|
thread->joiner = thread;
|
2003-03-28 03:52:20 +08:00
|
|
|
thread->mutex.unlock ();
|
2002-06-05 20:39:55 +08:00
|
|
|
|
2012-06-18 04:50:24 +08:00
|
|
|
debug_printf ("tid %p", &_my_tls);
|
2003-12-24 00:26:31 +08:00
|
|
|
thread_printf ("started thread %p %p %p %p %p %p", arg, &_my_tls.local_clib,
|
2001-03-21 10:17:58 +08:00
|
|
|
_impure_ptr, thread, thread->function, thread->arg);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-19 05:11:25 +08:00
|
|
|
// call the user's thread
|
2000-02-18 03:38:33 +08:00
|
|
|
void *ret = thread->function (thread->arg);
|
|
|
|
|
2002-07-04 22:17:30 +08:00
|
|
|
thread->exit (ret);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-12-14 15:09:22 +08:00
|
|
|
return 0; // just for show. Never returns.
|
2003-12-03 13:21:55 +08:00
|
|
|
}
|
|
|
|
|
2002-09-16 18:53:29 +08:00
|
|
|
unsigned long
|
|
|
|
pthread::getsequence_np ()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
return get_thread_id ();
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread::create (pthread_t *thread, const pthread_attr_t *attr,
|
2001-03-21 10:17:58 +08:00
|
|
|
void *(*start_routine) (void *), void *arg)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (attr && !pthread_attr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
*thread = new pthread ();
|
2005-08-06 00:14:41 +08:00
|
|
|
if (!(*thread)->create (start_routine, attr ? *attr : NULL, arg))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-03-21 10:17:58 +08:00
|
|
|
delete (*thread);
|
|
|
|
*thread = NULL;
|
|
|
|
return EAGAIN;
|
2000-08-04 12:04:46 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread::once (pthread_once_t *once_control, void (*init_routine) (void))
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2002-06-23 15:36:21 +08:00
|
|
|
// already done ?
|
|
|
|
if (once_control->state)
|
|
|
|
return 0;
|
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
pthread_mutex_lock (&once_control->mutex);
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Here we must set a cancellation handler to unlock the mutex if needed */
|
|
|
|
/* but a cancellation handler is not the right thing. We need this in the thread
|
2001-07-27 04:47:05 +08:00
|
|
|
*cleanup routine. Assumption: a thread can only be in one pthread_once routine
|
|
|
|
*at a time. Stote a mutex_t *in the pthread_structure. if that's non null unlock
|
|
|
|
*on pthread_exit ();
|
2001-04-12 12:04:53 +08:00
|
|
|
*/
|
2002-06-23 15:36:21 +08:00
|
|
|
if (!once_control->state)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
|
|
|
init_routine ();
|
|
|
|
once_control->state = 1;
|
|
|
|
}
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Here we must remove our cancellation handler */
|
2001-04-12 12:04:53 +08:00
|
|
|
pthread_mutex_unlock (&once_control->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread::cancel (pthread_t thread)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (&thread))
|
2001-04-12 12:04:53 +08:00
|
|
|
return ESRCH;
|
|
|
|
|
2002-07-04 22:17:30 +08:00
|
|
|
return thread->cancel ();
|
2001-04-12 12:04:53 +08:00
|
|
|
}
|
|
|
|
|
2001-04-13 23:28:20 +08:00
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
pthread::atforkprepare ()
|
2001-04-13 23:28:20 +08:00
|
|
|
{
|
2001-04-23 10:56:19 +08:00
|
|
|
callback *cb = MT_INTERFACE->pthread_prepare;
|
2001-04-13 23:28:20 +08:00
|
|
|
while (cb)
|
|
|
|
{
|
2001-04-23 10:56:19 +08:00
|
|
|
cb->cb ();
|
|
|
|
cb = cb->next;
|
2001-04-13 23:28:20 +08:00
|
|
|
}
|
2004-03-27 04:02:01 +08:00
|
|
|
|
|
|
|
__fp_lock_all ();
|
2004-03-29 23:14:07 +08:00
|
|
|
|
|
|
|
MT_INTERFACE->fixup_before_fork ();
|
2001-04-13 23:28:20 +08:00
|
|
|
}
|
|
|
|
|
2001-04-23 10:56:19 +08:00
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
pthread::atforkparent ()
|
2001-04-13 23:28:20 +08:00
|
|
|
{
|
2004-03-27 04:02:01 +08:00
|
|
|
__fp_unlock_all ();
|
|
|
|
|
2001-04-23 10:56:19 +08:00
|
|
|
callback *cb = MT_INTERFACE->pthread_parent;
|
2001-04-13 23:28:20 +08:00
|
|
|
while (cb)
|
|
|
|
{
|
2001-04-23 10:56:19 +08:00
|
|
|
cb->cb ();
|
|
|
|
cb = cb->next;
|
2001-04-13 23:28:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
pthread::atforkchild ()
|
2001-04-13 23:28:20 +08:00
|
|
|
{
|
2002-09-17 17:12:36 +08:00
|
|
|
MT_INTERFACE->fixup_after_fork ();
|
|
|
|
|
2004-03-27 04:02:01 +08:00
|
|
|
__fp_unlock_all ();
|
|
|
|
|
2001-04-23 10:56:19 +08:00
|
|
|
callback *cb = MT_INTERFACE->pthread_child;
|
2001-04-13 23:28:20 +08:00
|
|
|
while (cb)
|
|
|
|
{
|
2001-04-23 10:56:19 +08:00
|
|
|
cb->cb ();
|
|
|
|
cb = cb->next;
|
2001-04-13 23:28:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Register a set of functions to run before and after fork.
|
|
|
|
prepare calls are called in LI-FC order.
|
|
|
|
parent and child calls are called in FI-FC order. */
|
2001-04-13 23:28:20 +08:00
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread::atfork (void (*prepare)(void), void (*parent)(void), void (*child)(void))
|
2001-04-13 23:28:20 +08:00
|
|
|
{
|
2001-07-27 04:47:05 +08:00
|
|
|
callback *prepcb = NULL, *parentcb = NULL, *childcb = NULL;
|
2001-04-13 23:28:20 +08:00
|
|
|
if (prepare)
|
|
|
|
{
|
|
|
|
prepcb = new callback;
|
|
|
|
if (!prepcb)
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
parentcb = new callback;
|
|
|
|
if (!parentcb)
|
|
|
|
{
|
|
|
|
if (prepcb)
|
|
|
|
delete prepcb;
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
childcb = new callback;
|
|
|
|
if (!childcb)
|
|
|
|
{
|
|
|
|
if (prepcb)
|
|
|
|
delete prepcb;
|
|
|
|
if (parentcb)
|
|
|
|
delete parentcb;
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prepcb)
|
|
|
|
{
|
|
|
|
prepcb->cb = prepare;
|
2003-12-02 06:10:57 +08:00
|
|
|
List_insert (MT_INTERFACE->pthread_prepare, prepcb);
|
2001-04-13 23:28:20 +08:00
|
|
|
}
|
|
|
|
if (parentcb)
|
|
|
|
{
|
|
|
|
parentcb->cb = parent;
|
2001-07-27 04:47:05 +08:00
|
|
|
callback **t = &MT_INTERFACE->pthread_parent;
|
2001-04-13 23:28:20 +08:00
|
|
|
while (*t)
|
|
|
|
t = &(*t)->next;
|
2002-09-30 09:19:45 +08:00
|
|
|
/* t = pointer to last next in the list */
|
2003-12-02 06:10:57 +08:00
|
|
|
List_insert (*t, parentcb);
|
2001-04-13 23:28:20 +08:00
|
|
|
}
|
|
|
|
if (childcb)
|
|
|
|
{
|
|
|
|
childcb->cb = child;
|
2001-07-27 04:47:05 +08:00
|
|
|
callback **t = &MT_INTERFACE->pthread_child;
|
2001-04-13 23:28:20 +08:00
|
|
|
while (*t)
|
|
|
|
t = &(*t)->next;
|
2002-09-30 09:19:45 +08:00
|
|
|
/* t = pointer to last next in the list */
|
2003-12-02 06:10:57 +08:00
|
|
|
List_insert (*t, childcb);
|
2001-04-13 23:28:20 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_init (pthread_attr_t *attr)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-03-21 10:17:58 +08:00
|
|
|
*attr = new pthread_attr;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
|
|
|
delete (*attr);
|
|
|
|
*attr = NULL;
|
2003-06-12 03:08:42 +08:00
|
|
|
return ENOMEM;
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getinheritsched (const pthread_attr_t *attr,
|
2001-04-12 12:04:53 +08:00
|
|
|
int *inheritsched)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
*inheritsched = (*attr)->inheritsched;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getschedparam (const pthread_attr_t *attr,
|
2001-04-12 12:04:53 +08:00
|
|
|
struct sched_param *param)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
*param = (*attr)->schedparam;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* From a pure code point of view, this should call a helper in sched.cc,
|
|
|
|
to allow for someone adding scheduler policy changes to win32 in the future.
|
|
|
|
However that's extremely unlikely, so short and sweet will do us */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
*policy = SCHED_FIFO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getscope (const pthread_attr_t *attr, int *contentionscope)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
*contentionscope = (*attr)->contentionscope;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
if (detachstate < 0 || detachstate > 1)
|
|
|
|
return EINVAL;
|
|
|
|
(*attr)->joinable = detachstate;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
*detachstate = (*attr)->joinable;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setinheritsched (pthread_attr_t *attr, int inheritsched)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
if (inheritsched != PTHREAD_INHERIT_SCHED
|
|
|
|
&& inheritsched != PTHREAD_EXPLICIT_SCHED)
|
|
|
|
return ENOTSUP;
|
|
|
|
(*attr)->inheritsched = inheritsched;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setschedparam (pthread_attr_t *attr,
|
2001-04-12 12:04:53 +08:00
|
|
|
const struct sched_param *param)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
if (!valid_sched_parameters (param))
|
|
|
|
return ENOTSUP;
|
|
|
|
(*attr)->schedparam = *param;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* See __pthread_attr_getschedpolicy for some notes */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
if (policy != SCHED_FIFO)
|
|
|
|
return ENOTSUP;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setscope (pthread_attr_t *attr, int contentionscope)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
if (contentionscope != PTHREAD_SCOPE_SYSTEM
|
|
|
|
&& contentionscope != PTHREAD_SCOPE_PROCESS)
|
|
|
|
return EINVAL;
|
2002-09-30 09:19:45 +08:00
|
|
|
/* In future, we may be able to support system scope by escalating the thread
|
|
|
|
priority to exceed the priority class. For now we only support PROCESS scope. */
|
2001-04-12 12:04:53 +08:00
|
|
|
if (contentionscope != PTHREAD_SCOPE_PROCESS)
|
|
|
|
return ENOTSUP;
|
|
|
|
(*attr)->contentionscope = contentionscope;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-16 02:49:40 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setstack (pthread_attr_t *attr, void *addr, size_t size)
|
|
|
|
{
|
|
|
|
if (!pthread_attr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
|
|
|
if (addr == NULL)
|
2011-06-06 13:02:13 +08:00
|
|
|
return EINVAL;
|
2011-05-16 02:49:40 +08:00
|
|
|
if (size < PTHREAD_STACK_MIN)
|
2011-06-06 13:02:13 +08:00
|
|
|
return EINVAL;
|
2014-07-16 18:21:18 +08:00
|
|
|
/* The incoming address addr points to the lowest addressable byte of a
|
|
|
|
buffer of size bytes. Due to the way pthread_attr_setstackaddr is defined
|
|
|
|
on Linux, the lowest address ot the stack can't be reliably computed when
|
|
|
|
using pthread_attr_setstackaddr/pthread_attr_setstacksize. Therefore we
|
|
|
|
store the uppermost address of the stack in stackaddr. See also the
|
|
|
|
comment in pthread_attr_setstackaddr. */
|
|
|
|
(*attr)->stackaddr = (caddr_t) addr + size;
|
2011-05-16 02:49:40 +08:00
|
|
|
(*attr)->stacksize = size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-03 09:13:37 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getstack (const pthread_attr_t *attr, void **addr, size_t *size)
|
|
|
|
{
|
|
|
|
if (!pthread_attr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
2014-07-16 18:21:18 +08:00
|
|
|
/* stackaddr holds the uppermost stack address. See the comment in
|
|
|
|
pthread_attr_setstack. */
|
|
|
|
*addr = (caddr_t) (*attr)->stackaddr - (*attr)->stacksize;
|
2011-05-03 09:13:37 +08:00
|
|
|
*size = (*attr)->stacksize;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-16 02:49:40 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setstackaddr (pthread_attr_t *attr, void *addr)
|
|
|
|
{
|
|
|
|
if (!pthread_attr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
|
|
|
if (addr == NULL)
|
2011-06-06 13:02:13 +08:00
|
|
|
return EINVAL;
|
2014-07-16 18:21:18 +08:00
|
|
|
/* This function is deprecated in SUSv4, but SUSv3 didn't define
|
|
|
|
if the incoming stack address is the lowest address of the memory
|
|
|
|
area defined as stack, or if it's the start address of the stack
|
|
|
|
at which it begins its growth. On Linux it's the latter which
|
|
|
|
means the uppermost stack address on x86 based systems. See comment
|
|
|
|
in pthread_attr_setstack as well. */
|
2011-05-16 02:49:40 +08:00
|
|
|
(*attr)->stackaddr = addr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-03 09:13:37 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getstackaddr (const pthread_attr_t *attr, void **addr)
|
|
|
|
{
|
|
|
|
if (!pthread_attr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
2014-07-16 18:21:18 +08:00
|
|
|
/* See comment in pthread_attr_setstackaddr. */
|
2011-05-03 09:13:37 +08:00
|
|
|
*addr = (*attr)->stackaddr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setstacksize (pthread_attr_t *attr, size_t size)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2011-05-03 09:13:37 +08:00
|
|
|
if (size < PTHREAD_STACK_MIN)
|
2011-06-06 13:02:13 +08:00
|
|
|
return EINVAL;
|
2001-03-21 10:17:58 +08:00
|
|
|
(*attr)->stacksize = size;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *size)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2014-07-16 18:21:18 +08:00
|
|
|
/* If the stacksize has not been set by the application, return the
|
|
|
|
default stacksize. Note that this is different from what
|
|
|
|
pthread_attr_getstack returns. */
|
2015-07-05 21:51:37 +08:00
|
|
|
*size = (*attr)->stacksize ?: get_rlimit_stack ();
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-05-16 02:49:40 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_setguardsize (pthread_attr_t *attr, size_t size)
|
|
|
|
{
|
|
|
|
if (!pthread_attr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
|
|
|
/* We don't support a guardsize of more than 1 Meg. */
|
|
|
|
if (size > 1024 * 1024)
|
|
|
|
return EINVAL;
|
|
|
|
(*attr)->guardsize = size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_attr_getguardsize (const pthread_attr_t *attr, size_t *size)
|
|
|
|
{
|
|
|
|
if (!pthread_attr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
|
|
|
*size = (*attr)->guardsize;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_attr_destroy (pthread_attr_t *attr)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_attr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
delete (*attr);
|
|
|
|
*attr = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2018-06-27 23:56:59 +08:00
|
|
|
pthread::join (pthread_t *thread, void **return_val, PLARGE_INTEGER timeout)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread_t joiner = self ();
|
2002-06-05 20:39:55 +08:00
|
|
|
|
2003-01-10 04:57:54 +08:00
|
|
|
joiner->testcancel ();
|
2002-11-24 21:54:14 +08:00
|
|
|
|
2002-06-23 15:36:21 +08:00
|
|
|
// Initialize return val with NULL
|
|
|
|
if (return_val)
|
|
|
|
*return_val = NULL;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (&joiner))
|
2003-01-10 04:57:54 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (thread))
|
2001-03-21 10:17:58 +08:00
|
|
|
return ESRCH;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-04-18 03:57:01 +08:00
|
|
|
if (equal (*thread,joiner))
|
2002-06-23 15:36:21 +08:00
|
|
|
return EDEADLK;
|
2002-06-05 20:39:55 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
(*thread)->mutex.lock ();
|
2002-06-10 10:40:13 +08:00
|
|
|
|
2002-09-17 17:12:36 +08:00
|
|
|
if ((*thread)->attr.joinable == PTHREAD_CREATE_DETACHED)
|
2002-06-05 20:39:55 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
(*thread)->mutex.unlock ();
|
2002-06-10 10:40:13 +08:00
|
|
|
return EINVAL;
|
2002-06-05 20:39:55 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2002-06-05 20:39:55 +08:00
|
|
|
(*thread)->joiner = joiner;
|
2002-06-10 09:10:45 +08:00
|
|
|
(*thread)->attr.joinable = PTHREAD_CREATE_DETACHED;
|
2003-03-28 03:52:20 +08:00
|
|
|
(*thread)->mutex.unlock ();
|
2001-04-21 22:23:47 +08:00
|
|
|
|
2018-06-27 23:56:59 +08:00
|
|
|
switch (cygwait ((*thread)->win32_obj_id, timeout,
|
2015-02-23 21:56:01 +08:00
|
|
|
cw_sig | cw_sig_restart | cw_cancel))
|
2005-06-09 13:11:51 +08:00
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
if (return_val)
|
|
|
|
*return_val = (*thread)->return_ptr;
|
|
|
|
delete (*thread);
|
|
|
|
break;
|
|
|
|
case WAIT_CANCELED:
|
|
|
|
// set joined thread back to joinable since we got canceled
|
|
|
|
(*thread)->joiner = NULL;
|
|
|
|
(*thread)->attr.joinable = PTHREAD_CREATE_JOINABLE;
|
|
|
|
joiner->cancel_self ();
|
|
|
|
// never reached
|
|
|
|
break;
|
2018-06-27 23:56:59 +08:00
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
// set joined thread back to joinable since we got canceled
|
|
|
|
(*thread)->joiner = NULL;
|
|
|
|
(*thread)->attr.joinable = PTHREAD_CREATE_JOINABLE;
|
2018-06-28 00:13:38 +08:00
|
|
|
return (timeout && timeout->QuadPart == 0LL) ? EBUSY : ETIMEDOUT;
|
2005-06-09 13:11:51 +08:00
|
|
|
default:
|
|
|
|
// should never happen
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2003-01-10 04:57:54 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread::detach (pthread_t *thread)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (thread))
|
2001-03-21 10:17:58 +08:00
|
|
|
return ESRCH;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
(*thread)->mutex.lock ();
|
2001-04-12 12:04:53 +08:00
|
|
|
if ((*thread)->attr.joinable == PTHREAD_CREATE_DETACHED)
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
(*thread)->mutex.unlock ();
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-06-10 10:40:13 +08:00
|
|
|
// check if thread is still alive
|
2003-11-01 04:42:56 +08:00
|
|
|
if ((*thread)->valid && WaitForSingleObject ((*thread)->win32_obj_id, 0) == WAIT_TIMEOUT)
|
2002-06-10 10:40:13 +08:00
|
|
|
{
|
|
|
|
// force cleanup on exit
|
|
|
|
(*thread)->joiner = *thread;
|
|
|
|
(*thread)->attr.joinable = PTHREAD_CREATE_DETACHED;
|
2003-03-28 03:52:20 +08:00
|
|
|
(*thread)->mutex.unlock ();
|
2002-06-10 10:40:13 +08:00
|
|
|
}
|
|
|
|
else
|
2002-06-23 15:36:21 +08:00
|
|
|
{
|
|
|
|
// thread has already terminated.
|
2003-03-28 03:52:20 +08:00
|
|
|
(*thread)->mutex.unlock ();
|
2002-06-10 10:40:13 +08:00
|
|
|
delete (*thread);
|
2002-06-23 15:36:21 +08:00
|
|
|
}
|
2002-06-05 20:39:55 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread::suspend (pthread_t *thread)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (thread))
|
2001-03-21 10:17:58 +08:00
|
|
|
return ESRCH;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
if ((*thread)->suspended == false)
|
|
|
|
{
|
|
|
|
(*thread)->suspended = true;
|
|
|
|
SuspendThread ((*thread)->win32_obj_id);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
pthread::resume (pthread_t *thread)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (thread))
|
2001-03-21 10:17:58 +08:00
|
|
|
return ESRCH;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
if ((*thread)->suspended == true)
|
|
|
|
ResumeThread ((*thread)->win32_obj_id);
|
|
|
|
(*thread)->suspended = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-04 01:08:31 +08:00
|
|
|
static inline int
|
|
|
|
pthread_convert_abstime (clockid_t clock_id, const struct timespec *abstime,
|
|
|
|
PLARGE_INTEGER timeout)
|
|
|
|
{
|
|
|
|
struct timespec tp;
|
|
|
|
|
|
|
|
/* According to SUSv3, the abstime value must be checked for validity. */
|
|
|
|
if (abstime->tv_sec < 0
|
|
|
|
|| abstime->tv_nsec < 0
|
2018-02-07 20:07:44 +08:00
|
|
|
|| abstime->tv_nsec >= NSPERSEC)
|
2017-08-04 01:08:31 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Check for immediate timeout before converting */
|
|
|
|
clock_gettime (clock_id, &tp);
|
|
|
|
if (tp.tv_sec > abstime->tv_sec
|
|
|
|
|| (tp.tv_sec == abstime->tv_sec
|
|
|
|
&& tp.tv_nsec > abstime->tv_nsec))
|
|
|
|
return ETIMEDOUT;
|
|
|
|
|
2018-02-07 20:07:44 +08:00
|
|
|
timeout->QuadPart = abstime->tv_sec * NS100PERSEC
|
|
|
|
+ (abstime->tv_nsec + (NSPERSEC/NS100PERSEC) - 1)
|
|
|
|
/ (NSPERSEC/NS100PERSEC);
|
2017-08-04 01:08:31 +08:00
|
|
|
switch (clock_id)
|
|
|
|
{
|
|
|
|
case CLOCK_REALTIME:
|
|
|
|
timeout->QuadPart += FACTOR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* other clocks must be handled as relative timeout */
|
2018-02-07 20:07:44 +08:00
|
|
|
timeout->QuadPart -= tp.tv_sec * NS100PERSEC + tp.tv_nsec
|
|
|
|
/ (NSPERSEC/NS100PERSEC);
|
2017-08-04 01:08:31 +08:00
|
|
|
timeout->QuadPart *= -1LL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-27 23:56:59 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_join (pthread_t thread, void **return_val)
|
|
|
|
{
|
|
|
|
return pthread::join (&thread, (void **) return_val, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_tryjoin_np (pthread_t thread, void **return_val)
|
|
|
|
{
|
2018-06-28 00:13:38 +08:00
|
|
|
LARGE_INTEGER timeout = { QuadPart:0LL };
|
2018-06-27 23:56:59 +08:00
|
|
|
|
|
|
|
return pthread::join (&thread, (void **) return_val, &timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_timedjoin_np (pthread_t thread, void **return_val,
|
|
|
|
const struct timespec *abstime)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
|
|
|
|
int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
return pthread::join (&thread, (void **) return_val, &timeout);
|
|
|
|
}
|
|
|
|
|
2011-05-03 09:13:37 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
|
|
|
|
{
|
2015-10-21 18:46:32 +08:00
|
|
|
THREAD_BASIC_INFORMATION tbi;
|
2011-12-22 19:02:36 +08:00
|
|
|
NTSTATUS status;
|
2011-05-03 09:13:37 +08:00
|
|
|
|
|
|
|
if (!pthread::is_good_object (&thread))
|
|
|
|
return ESRCH;
|
|
|
|
|
|
|
|
/* attr may not be pre-initialized */
|
|
|
|
if (!pthread_attr::is_good_object (attr))
|
|
|
|
{
|
|
|
|
int rv = pthread_attr_init (attr);
|
|
|
|
if (rv != 0)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*attr)->joinable = thread->attr.joinable;
|
|
|
|
(*attr)->contentionscope = thread->attr.contentionscope;
|
|
|
|
(*attr)->inheritsched = thread->attr.inheritsched;
|
|
|
|
(*attr)->schedparam = thread->attr.schedparam;
|
2011-05-16 02:49:40 +08:00
|
|
|
(*attr)->guardsize = thread->attr.guardsize;
|
2011-05-03 09:13:37 +08:00
|
|
|
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtQueryInformationThread (thread->win32_obj_id,
|
|
|
|
ThreadBasicInformation,
|
2015-10-21 18:46:32 +08:00
|
|
|
&tbi, sizeof (tbi), NULL);
|
2011-12-22 19:02:36 +08:00
|
|
|
if (NT_SUCCESS (status))
|
2011-05-03 09:13:37 +08:00
|
|
|
{
|
2015-10-21 18:46:32 +08:00
|
|
|
PTEB teb = (PTEB) tbi.TebBaseAddress;
|
2014-07-16 18:21:18 +08:00
|
|
|
/* stackaddr holds the uppermost stack address. See the comments
|
|
|
|
in pthread_attr_setstack and pthread_attr_setstackaddr for a
|
|
|
|
description. */
|
|
|
|
(*attr)->stackaddr = teb->Tib.StackBase;
|
2014-07-09 20:06:08 +08:00
|
|
|
(*attr)->stacksize = (uintptr_t) teb->Tib.StackBase
|
2014-07-16 18:21:18 +08:00
|
|
|
- (uintptr_t) (teb->DeallocationStack ?: teb->Tib.StackLimit);
|
2011-05-03 09:13:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_printf ("NtQueryInformationThread(ThreadBasicInformation), "
|
2013-04-23 17:44:36 +08:00
|
|
|
"status %y", status);
|
2011-05-03 09:13:37 +08:00
|
|
|
(*attr)->stackaddr = thread->attr.stackaddr;
|
|
|
|
(*attr)->stacksize = thread->attr.stacksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-23 01:43:05 +08:00
|
|
|
/* For Linux compatibility, the length of a thread name is 16 characters. */
|
|
|
|
#define THRNAMELEN 16
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_getname_np (pthread_t thread, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
if (!pthread::is_good_object (&thread))
|
|
|
|
return ESRCH;
|
|
|
|
|
|
|
|
if (!thread->attr.name)
|
|
|
|
name = program_invocation_short_name;
|
|
|
|
else
|
|
|
|
name = thread->attr.name;
|
|
|
|
|
|
|
|
/* Return ERANGE if the provided buffer is less than THRNAMELEN. Truncate
|
|
|
|
and zero-terminate the name to fit in buf. This means we always return
|
|
|
|
something if the buffer is THRNAMELEN or larger, but there is no way to
|
|
|
|
tell if we have the whole name. */
|
|
|
|
if (buflen < THRNAMELEN)
|
|
|
|
return ERANGE;
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
strlcpy (buf, name, buflen);
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
|
|
|
{
|
|
|
|
ret = EFAULT;
|
|
|
|
}
|
|
|
|
__endtry
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_setname_np (pthread_t thread, const char *name)
|
|
|
|
{
|
|
|
|
char *oldname, *cp;
|
|
|
|
|
|
|
|
if (!pthread::is_good_object (&thread))
|
|
|
|
return ESRCH;
|
|
|
|
|
|
|
|
if (strlen (name) > THRNAMELEN)
|
|
|
|
return ERANGE;
|
|
|
|
|
|
|
|
cp = strdup (name);
|
|
|
|
if (!cp)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
oldname = thread->attr.name;
|
|
|
|
thread->attr.name = cp;
|
|
|
|
|
2016-07-28 07:40:23 +08:00
|
|
|
SetThreadName (GetThreadId (thread->win32_obj_id), thread->attr.name);
|
|
|
|
|
2016-08-23 01:43:05 +08:00
|
|
|
if (oldname)
|
|
|
|
free (oldname);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:34:23 +08:00
|
|
|
/* Returns running thread's name; works for both cygthreads and pthreads */
|
|
|
|
char *
|
|
|
|
mythreadname (void)
|
|
|
|
{
|
|
|
|
char *result = (char *) cygthread::name ();
|
|
|
|
|
|
|
|
if (result == _my_tls.locals.unknown_thread_name)
|
|
|
|
{
|
|
|
|
result[0] = '\0';
|
|
|
|
pthread_getname_np (pthread_self (), result, (size_t) THRNAMELEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2016-08-23 01:43:05 +08:00
|
|
|
#undef THRNAMELEN
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* provided for source level compatability.
|
|
|
|
See http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_getconcurrency.html
|
|
|
|
*/
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
2005-07-05 11:16:46 +08:00
|
|
|
pthread_getconcurrency ()
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
|
|
|
return MT_INTERFACE->concurrency;
|
|
|
|
}
|
|
|
|
|
2011-05-18 01:08:10 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_getcpuclockid (pthread_t thread, clockid_t *clk_id)
|
|
|
|
{
|
|
|
|
if (!pthread::is_good_object (&thread))
|
|
|
|
return (ESRCH);
|
|
|
|
*clk_id = (clockid_t) THREADID_TO_CLOCKID (thread->getsequence_np ());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* keep this in sync with sched.cc */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_getschedparam (pthread_t thread, int *policy,
|
2001-04-12 12:04:53 +08:00
|
|
|
struct sched_param *param)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread::is_good_object (&thread))
|
2001-04-12 12:04:53 +08:00
|
|
|
return ESRCH;
|
|
|
|
*policy = SCHED_FIFO;
|
2016-05-20 23:45:24 +08:00
|
|
|
param->sched_priority = sched_get_thread_priority (thread->win32_obj_id);
|
2001-04-12 12:04:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-24 00:26:31 +08:00
|
|
|
/* Thread Specific Data */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_key_create (pthread_key_t *key, void (*destructor) (void *))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-12 12:04:53 +08:00
|
|
|
*key = new pthread_key (destructor);
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_key::is_good_object (key))
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
|
|
|
delete (*key);
|
|
|
|
*key = NULL;
|
|
|
|
return EAGAIN;
|
|
|
|
}
|
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_key_delete (pthread_key_t key)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_key::is_good_object (&key))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
delete (key);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* provided for source level compatability. See
|
|
|
|
http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_getconcurrency.html
|
|
|
|
*/
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_setconcurrency (int new_level)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
|
|
|
if (new_level < 0)
|
|
|
|
return EINVAL;
|
|
|
|
MT_INTERFACE->concurrency = new_level;
|
2001-03-21 10:17:58 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* keep syncronised with sched.cc */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_setschedparam (pthread_t thread, int policy,
|
2001-04-12 12:04:53 +08:00
|
|
|
const struct sched_param *param)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread::is_good_object (&thread))
|
2001-04-12 12:04:53 +08:00
|
|
|
return ESRCH;
|
|
|
|
if (policy != SCHED_FIFO)
|
|
|
|
return ENOTSUP;
|
|
|
|
if (!param)
|
|
|
|
return EINVAL;
|
|
|
|
int rv =
|
|
|
|
sched_set_thread_priority (thread->win32_obj_id, param->sched_priority);
|
|
|
|
if (!rv)
|
|
|
|
thread->attr.schedparam.sched_priority = param->sched_priority;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-04-15 17:22:14 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_setschedprio (pthread_t thread, int priority)
|
|
|
|
{
|
|
|
|
if (!pthread::is_good_object (&thread))
|
|
|
|
return ESRCH;
|
|
|
|
int rv =
|
|
|
|
sched_set_thread_priority (thread->win32_obj_id, priority);
|
|
|
|
if (!rv)
|
|
|
|
thread->attr.schedparam.sched_priority = priority;
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_setspecific (pthread_key_t key, const void *value)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_key::is_good_object (&key))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
(key)->set (value);
|
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" void *
|
|
|
|
pthread_getspecific (pthread_key_t key)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_key::is_good_object (&key))
|
2001-03-21 10:17:58 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (key)->get ();
|
|
|
|
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_cond_destroy (pthread_cond_t *cond)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_cond::is_initializer (cond))
|
2001-11-15 19:10:38 +08:00
|
|
|
return 0;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_cond::is_good_object (cond))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2001-03-17 09:14:58 +08:00
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* reads are atomic */
|
2001-03-21 10:17:58 +08:00
|
|
|
if ((*cond)->waiting)
|
|
|
|
return EBUSY;
|
2001-03-17 09:14:58 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
delete (*cond);
|
|
|
|
*cond = NULL;
|
2001-03-17 09:14:58 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-10 04:40:44 +08:00
|
|
|
pthread_cond::init (pthread_cond_t *cond, const pthread_condattr_t *attr)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2004-03-05 05:04:14 +08:00
|
|
|
pthread_cond_t new_cond;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (attr && !pthread_condattr::is_good_object (attr))
|
2001-03-17 09:14:58 +08:00
|
|
|
return EINVAL;
|
2003-10-25 03:34:47 +08:00
|
|
|
|
|
|
|
cond_initialization_lock.lock ();
|
2006-03-23 04:38:26 +08:00
|
|
|
|
2004-03-05 05:04:14 +08:00
|
|
|
new_cond = new pthread_cond (attr ? (*attr) : NULL);
|
|
|
|
if (!is_good_object (&new_cond))
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2004-03-05 05:04:14 +08:00
|
|
|
delete new_cond;
|
2003-03-28 03:52:20 +08:00
|
|
|
cond_initialization_lock.unlock ();
|
2001-03-21 10:17:58 +08:00
|
|
|
return EAGAIN;
|
|
|
|
}
|
2004-03-05 05:04:14 +08:00
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
*cond = new_cond;
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
2006-03-23 04:38:26 +08:00
|
|
|
{
|
|
|
|
delete new_cond;
|
2014-08-22 17:21:33 +08:00
|
|
|
ret = EINVAL;
|
2006-03-23 04:38:26 +08:00
|
|
|
}
|
2014-08-22 17:21:33 +08:00
|
|
|
__endtry
|
2003-03-28 03:52:20 +08:00
|
|
|
cond_initialization_lock.unlock ();
|
2014-08-22 17:21:33 +08:00
|
|
|
return ret;
|
2001-03-17 09:14:58 +08:00
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_cond_broadcast (pthread_cond_t *cond)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_cond::is_initializer (cond))
|
2003-03-19 03:49:38 +08:00
|
|
|
return 0;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_cond::is_good_object (cond))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2001-03-19 05:11:25 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
(*cond)->unblock (true);
|
2001-03-17 09:14:58 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_cond_signal (pthread_cond_t *cond)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_cond::is_initializer (cond))
|
2003-03-19 03:49:38 +08:00
|
|
|
return 0;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_cond::is_good_object (cond))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2001-03-17 09:14:58 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
(*cond)->unblock (false);
|
2001-03-17 09:14:58 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 03:49:38 +08:00
|
|
|
static int
|
2012-02-09 03:58:37 +08:00
|
|
|
__pthread_cond_wait_init (pthread_cond_t *cond, pthread_mutex_t *mutex)
|
2003-03-19 03:49:38 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutex::is_good_object (mutex))
|
2003-03-19 03:49:38 +08:00
|
|
|
return EINVAL;
|
2010-02-23 04:36:04 +08:00
|
|
|
if (!(*mutex)->can_be_unlocked ())
|
2003-03-19 03:49:38 +08:00
|
|
|
return EPERM;
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_cond::is_initializer (cond))
|
2003-01-10 04:40:44 +08:00
|
|
|
pthread_cond::init (cond, NULL);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_cond::is_good_object (cond))
|
2001-03-17 09:14:58 +08:00
|
|
|
return EINVAL;
|
2001-06-26 22:47:48 +08:00
|
|
|
|
2012-02-09 03:58:37 +08:00
|
|
|
return 0;
|
2001-03-17 09:14:58 +08:00
|
|
|
}
|
|
|
|
|
2001-09-29 17:01:01 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
|
|
|
|
const struct timespec *abstime)
|
2001-03-19 05:11:25 +08:00
|
|
|
{
|
2011-08-04 00:40:48 +08:00
|
|
|
LARGE_INTEGER timeout;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2005-07-03 11:25:19 +08:00
|
|
|
pthread_testcancel ();
|
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
int err = __pthread_cond_wait_init (cond, mutex);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-02-09 03:58:37 +08:00
|
|
|
|
2017-08-04 01:08:31 +08:00
|
|
|
err = pthread_convert_abstime ((*cond)->clock_id, abstime, &timeout);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2011-08-04 00:40:48 +08:00
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
return (*cond)->wait (*mutex, &timeout);
|
2011-08-04 00:40:48 +08:00
|
|
|
}
|
2014-08-22 17:21:33 +08:00
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
return EINVAL;
|
2001-09-29 17:01:01 +08:00
|
|
|
}
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2001-09-29 17:01:01 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
|
|
|
|
{
|
2003-03-19 03:49:38 +08:00
|
|
|
pthread_testcancel ();
|
|
|
|
|
2012-02-09 03:58:37 +08:00
|
|
|
int err = __pthread_cond_wait_init (cond, mutex);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
return (*cond)->wait (*mutex, NULL);
|
2001-03-17 09:14:58 +08:00
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_condattr_init (pthread_condattr_t *condattr)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2001-03-21 10:17:58 +08:00
|
|
|
*condattr = new pthread_condattr;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_condattr::is_good_object (condattr))
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
|
|
|
delete (*condattr);
|
|
|
|
*condattr = NULL;
|
2003-06-12 03:08:42 +08:00
|
|
|
return ENOMEM;
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2001-03-17 09:14:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_condattr::is_good_object (attr))
|
2001-03-17 09:14:58 +08:00
|
|
|
return EINVAL;
|
2001-03-21 10:17:58 +08:00
|
|
|
*pshared = (*attr)->shared;
|
2001-03-17 09:14:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_condattr::is_good_object (attr))
|
2001-03-17 09:14:58 +08:00
|
|
|
return EINVAL;
|
2001-03-21 10:17:58 +08:00
|
|
|
if ((pshared < 0) || (pshared > 1))
|
|
|
|
return EINVAL;
|
2002-09-30 09:19:45 +08:00
|
|
|
/* shared cond vars not currently supported */
|
2001-04-21 22:23:47 +08:00
|
|
|
if (pshared != PTHREAD_PROCESS_PRIVATE)
|
|
|
|
return EINVAL;
|
2001-03-21 10:17:58 +08:00
|
|
|
(*attr)->shared = pshared;
|
2001-03-17 09:14:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-21 17:39:22 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clock_id)
|
|
|
|
{
|
|
|
|
if (!pthread_condattr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
|
|
|
*clock_id = (*attr)->clock_id;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock_id)
|
|
|
|
{
|
|
|
|
if (!pthread_condattr::is_good_object (attr))
|
|
|
|
return EINVAL;
|
|
|
|
switch (clock_id)
|
|
|
|
{
|
|
|
|
case CLOCK_REALTIME:
|
|
|
|
case CLOCK_MONOTONIC:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
(*attr)->clock_id = clock_id;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_condattr_destroy (pthread_condattr_t *condattr)
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_condattr::is_good_object (condattr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
delete (*condattr);
|
|
|
|
*condattr = NULL;
|
2001-03-17 09:14:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return 0;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if ((*rwlock)->writer || (*rwlock)->readers ||
|
2003-03-28 03:52:20 +08:00
|
|
|
(*rwlock)->waiting_readers || (*rwlock)->waiting_writers)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
delete (*rwlock);
|
|
|
|
*rwlock = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_rwlock::init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
|
|
|
|
{
|
2004-03-05 05:04:14 +08:00
|
|
|
pthread_rwlock_t new_rwlock;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (attr && !pthread_rwlockattr::is_good_object (attr))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
2003-10-25 03:34:47 +08:00
|
|
|
|
|
|
|
rwlock_initialization_lock.lock ();
|
2006-03-23 04:38:26 +08:00
|
|
|
|
2004-03-05 05:04:14 +08:00
|
|
|
new_rwlock = new pthread_rwlock (attr ? (*attr) : NULL);
|
|
|
|
if (!is_good_object (&new_rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2004-03-05 05:04:14 +08:00
|
|
|
delete new_rwlock;
|
2003-03-28 03:52:20 +08:00
|
|
|
rwlock_initialization_lock.unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EAGAIN;
|
|
|
|
}
|
2004-03-05 05:04:14 +08:00
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
*rwlock = new_rwlock;
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
2006-03-23 04:38:26 +08:00
|
|
|
{
|
|
|
|
delete new_rwlock;
|
2014-08-22 17:21:33 +08:00
|
|
|
ret = EINVAL;
|
2006-03-23 04:38:26 +08:00
|
|
|
}
|
2014-08-22 17:21:33 +08:00
|
|
|
__endtry
|
2003-03-28 03:52:20 +08:00
|
|
|
rwlock_initialization_lock.unlock ();
|
2014-08-22 17:21:33 +08:00
|
|
|
return ret;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
pthread_testcancel ();
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
pthread_rwlock::init (rwlock, NULL);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
return (*rwlock)->rdlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2017-08-04 03:31:38 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock,
|
|
|
|
const struct timespec *abstime)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
|
|
|
|
pthread_testcancel ();
|
|
|
|
|
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
|
|
|
pthread_rwlock::init (rwlock, NULL);
|
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* According to SUSv3, abstime need not be checked for validity,
|
|
|
|
if the rwlock can be locked immediately. */
|
|
|
|
if (!(*rwlock)->tryrdlock ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return (*rwlock)->rdlock (&timeout);
|
|
|
|
}
|
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
pthread_rwlock::init (rwlock, NULL);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
return (*rwlock)->tryrdlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
pthread_testcancel ();
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
pthread_rwlock::init (rwlock, NULL);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
return (*rwlock)->wrlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2017-08-04 03:31:38 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock,
|
|
|
|
const struct timespec *abstime)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
|
|
|
|
pthread_testcancel ();
|
|
|
|
|
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
|
|
|
pthread_rwlock::init (rwlock, NULL);
|
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* According to SUSv3, abstime need not be checked for validity,
|
|
|
|
if the rwlock can be locked immediately. */
|
|
|
|
if (!(*rwlock)->trywrlock ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return (*rwlock)->wrlock (&timeout);
|
|
|
|
}
|
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
pthread_rwlock::init (rwlock, NULL);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
return (*rwlock)->trywrlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_rwlock::is_initializer (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return 0;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlock::is_good_object (rwlock))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
return (*rwlock)->unlock ();
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlockattr_init (pthread_rwlockattr_t *rwlockattr)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
*rwlockattr = new pthread_rwlockattr;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlockattr::is_good_object (rwlockattr))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
|
|
|
delete (*rwlockattr);
|
|
|
|
*rwlockattr = NULL;
|
2003-06-12 03:08:42 +08:00
|
|
|
return ENOMEM;
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *attr, int *pshared)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlockattr::is_good_object (attr))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
*pshared = (*attr)->shared;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlockattr_setpshared (pthread_rwlockattr_t *attr, int pshared)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlockattr::is_good_object (attr))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
if ((pshared < 0) || (pshared > 1))
|
|
|
|
return EINVAL;
|
|
|
|
/* shared rwlock vars not currently supported */
|
|
|
|
if (pshared != PTHREAD_PROCESS_PRIVATE)
|
|
|
|
return EINVAL;
|
|
|
|
(*attr)->shared = pshared;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_rwlockattr_destroy (pthread_rwlockattr_t *rwlockattr)
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_rwlockattr::is_good_object (rwlockattr))
|
* cygwin.din: Add pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* include/cygwin/version.h: Bump API minor number.
* include/pthread.h (PTHREAD_RWLOCK_INITIALIZER): Define a
reasonable value.
Add prototypes for pthread_rwlock_destroy, pthread_rwlock_init,
pthread_rwlock_rdlock, pthread_rwlock_tryrdlock,
pthread_rwlock_wrlock, pthread_rwlock_trywrlock,
pthread_rwlock_unlock, pthread_rwlockattr_init,
pthread_rwlockattr_getpshared, pthread_rwlockattr_setpshared,
and pthread_rwlockattr_destroy.
* thread.h (PTHREAD_ONCE_MAGIC): Remove superflous semicolon.
(PTHREAD_RWLOCK_MAGIC): New define.
(PTHREAD_RWLOCKATTR_MAGIC): Ditto.
(pthread_rwlockattr): New class.
(pthread_rwlock): Ditto.
(MTinterface::rwlocks): New member.
(MTinterface::MTinterface): Initialize rwlocks.
Add prototypes for __pthread_rwlock_destroy,
__pthread_rwlock_wrlock, __pthread_rwlock_trywrlock,
__pthread_rwlock_unlock, __pthread_rwlockattr_init,
__pthread_rwlockattr_getpshared, __pthread_rwlockattr_setpshared,
and __pthread_rwlockattr_destroy.
* thread.cc (MTinterface::Init): Initialize rwlock internal mutex.
(MTinterface::fixup_after_fork): Fixup rwlocks after fork.
(pthread_rwlockattr::isGoodObject): Implement.
(pthread_rwlockattr::pthread_rwlockattr): Ditto.
(pthread_rwlockattr::~pthread_rwlockattr): Ditto.
(pthread_rwlock::initMutex): Ditto.
(pthread_rwlock::pthread_rwlock): Ditto.
(pthread_rwlock::~pthread_rwlock): Ditto.
(pthread_rwlock::RdLock): Ditto.
(pthread_rwlock::TryRdLock): Ditto.
(pthread_rwlock::WrLock): Ditto.
(pthread_rwlock::TryWrLock): Ditto.
(pthread_rwlock::UnLock): Ditto.
(pthread_rwlock::addReader): Ditto.
(pthread_rwlock::removeReader): Ditto.
(pthread_rwlock::lookupReader): Ditto.
(pthread_rwlock::RdLockCleanup): Ditto.
(pthread_rwlock::WrLockCleanup): Ditto.
(pthread_rwlock::fixup_after_fork): Ditto.
(pthread_rwlock::isGoodObject): Ditto.
(pthread_rwlock::isGoodInitializer): Ditto.
(pthread_rwlock::isGoodInitializerOrObject): Ditto.
(pthread_rwlock::isGoodInitializerOrBadObject): Ditto.
(__pthread_rwlock_destroy): Ditto.
(pthread_rwlock::init): Ditto.
(__pthread_rwlock_rdlock): Ditto.
(__pthread_rwlock_tryrdlock): Ditto.
(__pthread_rwlock_wrlock): Ditto.
(__pthread_rwlock_trywrlock): Ditto.
2003-03-19 04:01:07 +08:00
|
|
|
return EINVAL;
|
|
|
|
delete (*rwlockattr);
|
|
|
|
*rwlockattr = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Thread signal */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_kill (pthread_t thread, int sig)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-09-30 09:19:45 +08:00
|
|
|
// lock myself, for the use of thread2signal
|
2001-09-10 06:39:35 +08:00
|
|
|
// two different kills might clash: FIXME
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread::is_good_object (&thread))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
|
|
|
|
2006-02-07 02:24:11 +08:00
|
|
|
siginfo_t si = {0};
|
2004-01-19 13:46:54 +08:00
|
|
|
si.si_signo = sig;
|
|
|
|
si.si_code = SI_USER;
|
2005-12-03 12:23:35 +08:00
|
|
|
si.si_pid = myself->pid;
|
|
|
|
si.si_uid = myself->uid;
|
2008-02-14 01:21:05 +08:00
|
|
|
int rval;
|
|
|
|
if (!thread->valid)
|
|
|
|
rval = ESRCH;
|
|
|
|
else if (sig)
|
2015-10-30 23:05:43 +08:00
|
|
|
{
|
|
|
|
rval = sig_send (NULL, si, thread->cygtls);
|
|
|
|
if (rval == -1)
|
|
|
|
rval = get_errno ();
|
|
|
|
}
|
2008-02-14 01:21:05 +08:00
|
|
|
else
|
|
|
|
switch (WaitForSingleObject (thread->win32_obj_id, 0))
|
|
|
|
{
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
rval = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rval = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-19 05:11:25 +08:00
|
|
|
// unlock myself
|
2000-02-18 03:38:33 +08:00
|
|
|
return rval;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_sigmask (int operation, const sigset_t *set, sigset_t *old_set)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-12-14 04:06:31 +08:00
|
|
|
int res = handle_sigprocmask (operation, set, old_set, _my_tls.sigmask);
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%d = pthread_sigmask(%d, %p, %p)",
|
|
|
|
res, operation, set, old_set);
|
2011-12-14 04:06:31 +08:00
|
|
|
return res;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2012-01-06 15:12:18 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_sigqueue (pthread_t *thread, int sig, const union sigval value)
|
|
|
|
{
|
|
|
|
siginfo_t si = {0};
|
|
|
|
|
|
|
|
if (!pthread::is_good_object (thread))
|
|
|
|
return EINVAL;
|
|
|
|
if (!(*thread)->valid)
|
|
|
|
return ESRCH;
|
|
|
|
|
|
|
|
si.si_signo = sig;
|
|
|
|
si.si_code = SI_QUEUE;
|
|
|
|
si.si_value = value;
|
|
|
|
si.si_pid = myself->pid;
|
|
|
|
si.si_uid = myself->uid;
|
|
|
|
return sig_send (NULL, si, (*thread)->cygtls);
|
|
|
|
}
|
|
|
|
|
2001-07-27 04:47:05 +08:00
|
|
|
/* ID */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
extern "C" int
|
2003-03-19 04:12:05 +08:00
|
|
|
pthread_equal (pthread_t t1, pthread_t t2)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-04-18 03:57:01 +08:00
|
|
|
return pthread::equal (t1, t2);
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Mutexes */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2002-09-30 07:47:45 +08:00
|
|
|
pthread_mutex::init (pthread_mutex_t *mutex,
|
2004-05-29 03:50:07 +08:00
|
|
|
const pthread_mutexattr_t *attr,
|
|
|
|
const pthread_mutex_t initializer)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-07-05 10:02:23 +08:00
|
|
|
if (attr && !pthread_mutexattr::is_good_object (attr))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2003-10-25 03:34:47 +08:00
|
|
|
|
|
|
|
mutex_initialization_lock.lock ();
|
2010-02-23 04:36:04 +08:00
|
|
|
if (initializer == NULL || pthread_mutex::is_initializer (mutex))
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
2010-02-10 15:25:26 +08:00
|
|
|
pthread_mutex_t new_mutex = new pthread_mutex (attr ? (*attr) : NULL);
|
|
|
|
if (!is_good_object (&new_mutex))
|
|
|
|
{
|
|
|
|
delete new_mutex;
|
|
|
|
mutex_initialization_lock.unlock ();
|
|
|
|
return EAGAIN;
|
|
|
|
}
|
2004-03-05 05:04:14 +08:00
|
|
|
|
2010-02-10 15:25:26 +08:00
|
|
|
if (!attr && initializer)
|
|
|
|
{
|
|
|
|
if (initializer == PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
|
|
|
|
new_mutex->type = PTHREAD_MUTEX_RECURSIVE;
|
|
|
|
else if (initializer == PTHREAD_NORMAL_MUTEX_INITIALIZER_NP)
|
|
|
|
new_mutex->type = PTHREAD_MUTEX_NORMAL;
|
|
|
|
else if (initializer == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP)
|
|
|
|
new_mutex->type = PTHREAD_MUTEX_ERRORCHECK;
|
|
|
|
}
|
2004-03-05 05:04:14 +08:00
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
*mutex = new_mutex;
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
2010-02-10 15:25:26 +08:00
|
|
|
{
|
|
|
|
delete new_mutex;
|
|
|
|
mutex_initialization_lock.unlock ();
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2014-08-22 17:21:33 +08:00
|
|
|
__endtry
|
2010-02-10 15:25:26 +08:00
|
|
|
}
|
2003-03-28 03:52:20 +08:00
|
|
|
mutex_initialization_lock.unlock ();
|
2010-02-23 04:36:04 +08:00
|
|
|
pthread_printf ("*mutex %p, attr %p, initializer %p", *mutex, attr, initializer);
|
2004-03-05 05:04:14 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutex_getprioceiling (const pthread_mutex_t *mutex,
|
2001-04-12 12:04:53 +08:00
|
|
|
int *prioceiling)
|
|
|
|
{
|
2002-09-30 09:19:45 +08:00
|
|
|
/* We don't define _POSIX_THREAD_PRIO_PROTECT because we do't currently support
|
|
|
|
mutex priorities.
|
|
|
|
|
|
|
|
We can support mutex priorities in the future though:
|
|
|
|
Store a priority with each mutex.
|
|
|
|
When the mutex is optained, set the thread priority as appropriate
|
|
|
|
When the mutex is released, reset the thread priority. */
|
2001-04-12 12:04:53 +08:00
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
extern "C" int
|
2003-03-19 04:12:05 +08:00
|
|
|
pthread_mutex_lock (pthread_mutex_t *mutex)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_mutex::is_initializer (mutex))
|
2004-03-05 05:04:14 +08:00
|
|
|
pthread_mutex::init (mutex, NULL, *mutex);
|
|
|
|
if (!pthread_mutex::is_good_object (mutex))
|
|
|
|
return EINVAL;
|
|
|
|
return (*mutex)->lock ();
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2017-08-04 01:13:21 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
|
|
|
|
if (pthread_mutex::is_initializer (mutex))
|
|
|
|
pthread_mutex::init (mutex, NULL, *mutex);
|
|
|
|
if (!pthread_mutex::is_good_object (mutex))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* According to SUSv3, abstime need not be checked for validity,
|
|
|
|
if the mutex can be locked immediately. */
|
|
|
|
if (!(*mutex)->trylock ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return (*mutex)->lock (&timeout);
|
|
|
|
}
|
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutex_trylock (pthread_mutex_t *mutex)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_mutex::is_initializer (mutex))
|
2004-03-05 05:04:14 +08:00
|
|
|
pthread_mutex::init (mutex, NULL, *mutex);
|
|
|
|
if (!pthread_mutex::is_good_object (mutex))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2004-03-05 05:04:14 +08:00
|
|
|
return (*mutex)->trylock ();
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutex_unlock (pthread_mutex_t *mutex)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_mutex::is_initializer (mutex))
|
2014-07-14 17:42:15 +08:00
|
|
|
pthread_mutex::init (mutex, NULL, *mutex);
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutex::is_good_object (mutex))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2003-03-28 03:52:20 +08:00
|
|
|
return (*mutex)->unlock ();
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutex_destroy (pthread_mutex_t *mutex)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-01-10 04:50:23 +08:00
|
|
|
int rv;
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
if (pthread_mutex::is_initializer (mutex))
|
2001-04-12 12:04:53 +08:00
|
|
|
return 0;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutex::is_good_object (mutex))
|
2001-03-21 10:17:58 +08:00
|
|
|
return EINVAL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
rv = (*mutex)->destroy ();
|
2003-01-10 04:50:23 +08:00
|
|
|
if (rv)
|
|
|
|
return rv;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
*mutex = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling,
|
2001-04-12 12:04:53 +08:00
|
|
|
int *old_ceiling)
|
|
|
|
{
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-03-29 18:32:40 +08:00
|
|
|
/* Spinlocks */
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_spinlock::init (pthread_spinlock_t *spinlock, int pshared)
|
|
|
|
{
|
|
|
|
pthread_spinlock_t new_spinlock = new pthread_spinlock (pshared);
|
|
|
|
if (!is_good_object (&new_spinlock))
|
|
|
|
{
|
|
|
|
delete new_spinlock;
|
|
|
|
return EAGAIN;
|
|
|
|
}
|
|
|
|
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
*spinlock = new_spinlock;
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
2011-03-29 18:32:40 +08:00
|
|
|
{
|
|
|
|
delete new_spinlock;
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2014-08-22 17:21:33 +08:00
|
|
|
__endtry
|
2011-03-29 18:32:40 +08:00
|
|
|
pthread_printf ("*spinlock %p, pshared %d", *spinlock, pshared);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_spin_lock (pthread_spinlock_t *spinlock)
|
|
|
|
{
|
|
|
|
if (!pthread_spinlock::is_good_object (spinlock))
|
|
|
|
return EINVAL;
|
|
|
|
return (*spinlock)->lock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_spin_trylock (pthread_spinlock_t *spinlock)
|
|
|
|
{
|
|
|
|
if (!pthread_spinlock::is_good_object (spinlock))
|
|
|
|
return EINVAL;
|
|
|
|
return (*spinlock)->trylock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_spin_unlock (pthread_spinlock_t *spinlock)
|
|
|
|
{
|
|
|
|
if (!pthread_spinlock::is_good_object (spinlock))
|
|
|
|
return EINVAL;
|
|
|
|
return (*spinlock)->unlock ();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
pthread_spin_destroy (pthread_spinlock_t *spinlock)
|
|
|
|
{
|
|
|
|
if (!pthread_spinlock::is_good_object (spinlock))
|
|
|
|
return EINVAL;
|
|
|
|
return (*spinlock)->destroy ();
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Win32 doesn't support mutex priorities - see __pthread_mutex_getprioceiling
|
|
|
|
for more detail */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr,
|
2001-04-12 12:04:53 +08:00
|
|
|
int *protocol)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr,
|
2001-04-12 12:04:53 +08:00
|
|
|
int *pshared)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
*pshared = (*attr)->pshared;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
*type = (*attr)->mutextype;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-10 04:50:23 +08:00
|
|
|
/* FIXME: write and test process shared mutex's. */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_init (pthread_mutexattr_t *attr)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
|
|
|
*attr = new pthread_mutexattr ();
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
|
|
|
delete (*attr);
|
|
|
|
*attr = NULL;
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
delete (*attr);
|
|
|
|
*attr = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Win32 doesn't support mutex priorities */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int protocol)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Win32 doesn't support mutex priorities */
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attr,
|
2001-04-12 12:04:53 +08:00
|
|
|
int prioceiling)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr,
|
2001-04-12 12:04:53 +08:00
|
|
|
int *prioceiling)
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int pshared)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
2002-09-30 09:19:45 +08:00
|
|
|
/* we don't use pshared for anything as yet. We need to test PROCESS_SHARED
|
2001-07-27 04:47:05 +08:00
|
|
|
*functionality
|
2001-04-12 12:04:53 +08:00
|
|
|
*/
|
2001-09-10 06:39:35 +08:00
|
|
|
if (pshared != PTHREAD_PROCESS_PRIVATE)
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
|
|
|
(*attr)->pshared = pshared;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:12:05 +08:00
|
|
|
/* see pthread_mutex_gettype */
|
|
|
|
extern "C" int
|
|
|
|
pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
|
2001-04-12 12:04:53 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!pthread_mutexattr::is_good_object (attr))
|
2001-04-12 12:04:53 +08:00
|
|
|
return EINVAL;
|
2003-01-15 04:31:47 +08:00
|
|
|
|
2003-01-10 04:50:23 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PTHREAD_MUTEX_ERRORCHECK:
|
|
|
|
case PTHREAD_MUTEX_RECURSIVE:
|
2003-03-19 03:39:21 +08:00
|
|
|
case PTHREAD_MUTEX_NORMAL:
|
2003-01-10 04:50:23 +08:00
|
|
|
(*attr)->mutextype = type;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* Semaphores */
|
2002-09-21 07:46:12 +08:00
|
|
|
|
2007-02-20 23:48:04 +08:00
|
|
|
List<semaphore> semaphore::semaphores;
|
|
|
|
|
|
|
|
semaphore::semaphore (int pshared, unsigned int value)
|
|
|
|
: verifyable_object (SEM_MAGIC),
|
|
|
|
shared (pshared),
|
2013-07-23 22:15:20 +08:00
|
|
|
currentvalue (-1),
|
|
|
|
startvalue (value),
|
2007-02-20 23:48:04 +08:00
|
|
|
fd (-1),
|
|
|
|
hash (0ULL),
|
|
|
|
sem (NULL)
|
|
|
|
{
|
|
|
|
SECURITY_ATTRIBUTES sa = (pshared != PTHREAD_PROCESS_PRIVATE)
|
|
|
|
? sec_all : sec_none_nih;
|
2013-04-23 17:44:36 +08:00
|
|
|
this->win32_obj_id = ::CreateSemaphore (&sa, value, INT32_MAX, NULL);
|
2007-02-20 23:48:04 +08:00
|
|
|
if (!this->win32_obj_id)
|
|
|
|
magic = 0;
|
|
|
|
|
|
|
|
semaphores.insert (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
semaphore::semaphore (unsigned long long shash, LUID sluid, int sfd,
|
|
|
|
sem_t *ssem, int oflag, mode_t mode, unsigned int value)
|
|
|
|
: verifyable_object (SEM_MAGIC),
|
|
|
|
shared (PTHREAD_PROCESS_SHARED),
|
2013-07-23 22:15:20 +08:00
|
|
|
currentvalue (-1), /* Unused for named semaphores. */
|
|
|
|
startvalue (value),
|
2007-02-20 23:48:04 +08:00
|
|
|
fd (sfd),
|
|
|
|
hash (shash),
|
|
|
|
luid (sluid),
|
|
|
|
sem (ssem)
|
|
|
|
{
|
2007-12-05 23:10:20 +08:00
|
|
|
char name[MAX_PATH];
|
2007-02-20 23:48:04 +08:00
|
|
|
|
2008-11-08 02:32:41 +08:00
|
|
|
__small_sprintf (name, "semaphore/%016X%08x%08x",
|
2007-02-20 23:48:04 +08:00
|
|
|
hash, luid.HighPart, luid.LowPart);
|
2013-04-23 17:44:36 +08:00
|
|
|
this->win32_obj_id = ::CreateSemaphore (&sec_all, value, INT32_MAX, name);
|
2007-02-20 23:48:04 +08:00
|
|
|
if (!this->win32_obj_id)
|
|
|
|
magic = 0;
|
|
|
|
if (GetLastError () == ERROR_ALREADY_EXISTS && (oflag & O_EXCL))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
CloseHandle (this->win32_obj_id);
|
|
|
|
magic = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
semaphores.insert (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
semaphore::~semaphore ()
|
|
|
|
{
|
|
|
|
if (win32_obj_id)
|
|
|
|
CloseHandle (win32_obj_id);
|
|
|
|
|
|
|
|
semaphores.remove (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
semaphore::_post ()
|
|
|
|
{
|
2013-07-23 22:15:20 +08:00
|
|
|
LONG dummy;
|
|
|
|
ReleaseSemaphore (win32_obj_id, 1, &dummy);
|
2007-02-20 23:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
semaphore::_getvalue (int *sval)
|
|
|
|
{
|
2013-07-23 22:15:20 +08:00
|
|
|
NTSTATUS status;
|
|
|
|
SEMAPHORE_BASIC_INFORMATION sbi;
|
2007-02-20 23:48:04 +08:00
|
|
|
|
2013-07-23 22:15:20 +08:00
|
|
|
status = NtQuerySemaphore (win32_obj_id, SemaphoreBasicInformation, &sbi,
|
|
|
|
sizeof sbi, NULL);
|
2013-09-25 22:44:45 +08:00
|
|
|
int res;
|
2013-07-23 22:15:20 +08:00
|
|
|
if (NT_SUCCESS (status))
|
2013-09-25 22:44:45 +08:00
|
|
|
{
|
|
|
|
*sval = sbi.CurrentCount;
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*sval = startvalue;
|
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
return res;
|
2007-02-20 23:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
semaphore::_trywait ()
|
|
|
|
{
|
|
|
|
/* FIXME: signals should be able to interrupt semaphores...
|
|
|
|
We probably need WaitForMultipleObjects here. */
|
|
|
|
if (WaitForSingleObject (win32_obj_id, 0) == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
set_errno (EAGAIN);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-08-04 01:08:31 +08:00
|
|
|
semaphore::_wait (PLARGE_INTEGER timeout)
|
2007-02-20 23:48:04 +08:00
|
|
|
{
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
2007-02-20 23:48:04 +08:00
|
|
|
{
|
2017-08-04 01:08:31 +08:00
|
|
|
switch (cygwait (win32_obj_id, timeout,
|
2015-02-26 01:50:13 +08:00
|
|
|
cw_cancel | cw_cancel_self | cw_sig_eintr))
|
2014-08-22 17:21:33 +08:00
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
break;
|
|
|
|
case WAIT_SIGNALED:
|
|
|
|
set_errno (EINTR);
|
|
|
|
return -1;
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
set_errno (ETIMEDOUT);
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
pthread_printf ("cygwait failed. %E");
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 01:08:31 +08:00
|
|
|
__except (NO_ERROR) {}
|
2014-08-22 17:21:33 +08:00
|
|
|
__endtry
|
2007-02-20 23:48:04 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-23 22:15:20 +08:00
|
|
|
void
|
|
|
|
semaphore::_fixup_before_fork ()
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
SEMAPHORE_BASIC_INFORMATION sbi;
|
|
|
|
|
|
|
|
status = NtQuerySemaphore (win32_obj_id, SemaphoreBasicInformation, &sbi,
|
|
|
|
sizeof sbi, NULL);
|
|
|
|
if (NT_SUCCESS (status))
|
|
|
|
currentvalue = sbi.CurrentCount;
|
|
|
|
else
|
|
|
|
currentvalue = startvalue;
|
|
|
|
}
|
|
|
|
|
2007-02-20 23:48:04 +08:00
|
|
|
void
|
|
|
|
semaphore::_fixup_after_fork ()
|
|
|
|
{
|
|
|
|
if (shared == PTHREAD_PROCESS_PRIVATE)
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
pthread_printf ("sem %p", this);
|
2013-07-11 04:58:33 +08:00
|
|
|
win32_obj_id = ::CreateSemaphore (&sec_none_nih, currentvalue,
|
2013-07-23 22:15:20 +08:00
|
|
|
INT32_MAX, NULL);
|
2007-02-20 23:48:04 +08:00
|
|
|
if (!win32_obj_id)
|
2013-07-23 22:15:20 +08:00
|
|
|
api_fatal ("failed to create new win32 semaphore, "
|
|
|
|
"currentvalue %ld, %E", currentvalue);
|
2007-02-20 23:48:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
semaphore::_terminate ()
|
|
|
|
{
|
|
|
|
int _sem_close (sem_t *, bool);
|
|
|
|
|
|
|
|
if (sem)
|
|
|
|
_sem_close (sem, false);
|
|
|
|
}
|
|
|
|
|
2002-09-21 07:46:12 +08:00
|
|
|
/* static members */
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
semaphore::init (sem_t *sem, int pshared, unsigned int value)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-04-20 02:51:20 +08:00
|
|
|
/*
|
|
|
|
We can't tell the difference between reinitialising an
|
|
|
|
existing semaphore and initialising a semaphore who's
|
|
|
|
contents happen to be a valid pointer
|
|
|
|
*/
|
2003-03-28 03:52:20 +08:00
|
|
|
if (is_good_object (sem))
|
2013-07-11 04:58:33 +08:00
|
|
|
paranoid_printf ("potential attempt to reinitialise a semaphore");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
if (value > SEM_VALUE_MAX)
|
2011-03-29 15:49:25 +08:00
|
|
|
{
|
|
|
|
set_errno(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
*sem = new semaphore (pshared, value);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (sem))
|
2001-03-21 10:17:58 +08:00
|
|
|
{
|
|
|
|
delete (*sem);
|
|
|
|
*sem = NULL;
|
2011-03-29 15:49:25 +08:00
|
|
|
set_errno(EAGAIN);
|
|
|
|
return -1;
|
2001-03-21 10:17:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
semaphore::destroy (sem_t *sem)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (sem))
|
2011-03-29 15:49:25 +08:00
|
|
|
{
|
|
|
|
set_errno(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-02-20 23:48:04 +08:00
|
|
|
/* It's invalid to destroy a semaphore not opened with sem_init. */
|
|
|
|
if ((*sem)->fd != -1)
|
2011-03-29 15:49:25 +08:00
|
|
|
{
|
|
|
|
set_errno(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-02-20 23:48:04 +08:00
|
|
|
|
2002-09-30 09:19:45 +08:00
|
|
|
/* FIXME - new feature - test for busy against threads... */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
delete (*sem);
|
|
|
|
*sem = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2007-02-20 23:48:04 +08:00
|
|
|
int
|
|
|
|
semaphore::close (sem_t *sem)
|
|
|
|
{
|
|
|
|
if (!is_good_object (sem))
|
2011-03-29 15:49:25 +08:00
|
|
|
{
|
|
|
|
set_errno(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-02-20 23:48:04 +08:00
|
|
|
|
|
|
|
/* It's invalid to close a semaphore not opened with sem_open. */
|
|
|
|
if ((*sem)->fd == -1)
|
2011-03-29 15:49:25 +08:00
|
|
|
{
|
|
|
|
set_errno(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-02-20 23:48:04 +08:00
|
|
|
|
|
|
|
delete (*sem);
|
|
|
|
delete sem;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-27 19:48:29 +08:00
|
|
|
sem_t *
|
2007-02-20 23:48:04 +08:00
|
|
|
semaphore::open (unsigned long long hash, LUID luid, int fd, int oflag,
|
|
|
|
mode_t mode, unsigned int value, bool &wasopen)
|
2003-10-27 19:48:29 +08:00
|
|
|
{
|
|
|
|
if (value > SEM_VALUE_MAX)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-20 23:48:04 +08:00
|
|
|
/* sem_open is supposed to return the same pointer, if the same named
|
|
|
|
semaphore is opened multiple times in the same process, as long as
|
|
|
|
the semaphore hasn't been closed or unlinked in the meantime. */
|
|
|
|
semaphores.mx.lock ();
|
|
|
|
for (semaphore *sema = semaphores.head; sema; sema = sema->next)
|
|
|
|
if (sema->fd >= 0 && sema->hash == hash
|
2011-06-06 13:02:13 +08:00
|
|
|
&& sema->luid.HighPart == luid.HighPart
|
2016-03-20 01:45:54 +08:00
|
|
|
&& sema->luid.LowPart == luid.LowPart)
|
2007-02-20 23:48:04 +08:00
|
|
|
{
|
|
|
|
wasopen = true;
|
|
|
|
semaphores.mx.unlock ();
|
|
|
|
return sema->sem;
|
|
|
|
}
|
|
|
|
semaphores.mx.unlock ();
|
|
|
|
|
|
|
|
wasopen = false;
|
2003-10-27 19:48:29 +08:00
|
|
|
sem_t *sem = new sem_t;
|
|
|
|
if (!sem)
|
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-20 23:48:04 +08:00
|
|
|
*sem = new semaphore (hash, luid, fd, sem, oflag, mode, value);
|
2003-10-27 19:48:29 +08:00
|
|
|
|
|
|
|
if (!is_good_object (sem))
|
|
|
|
{
|
|
|
|
delete *sem;
|
|
|
|
delete sem;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return sem;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
semaphore::wait (sem_t *sem)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-01-10 04:57:54 +08:00
|
|
|
pthread_testcancel ();
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (sem))
|
2002-02-28 21:50:41 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-02-24 19:33:15 +08:00
|
|
|
return (*sem)->_wait ();
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
semaphore::trywait (sem_t *sem)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (sem))
|
2002-02-28 21:50:41 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
return (*sem)->_trywait ();
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-10-27 19:48:29 +08:00
|
|
|
int
|
|
|
|
semaphore::timedwait (sem_t *sem, const struct timespec *abstime)
|
|
|
|
{
|
2017-08-04 01:08:31 +08:00
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
|
2003-10-27 19:48:29 +08:00
|
|
|
if (!is_good_object (sem))
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-08-04 01:08:31 +08:00
|
|
|
/* According to SUSv3, abstime need not be checked for validity,
|
|
|
|
if the semaphore can be locked immediately. */
|
|
|
|
if (!(*sem)->_trywait ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return (*sem)->_wait (&timeout);
|
|
|
|
}
|
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
return EINVAL;
|
2003-10-27 19:48:29 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2002-09-21 11:59:58 +08:00
|
|
|
semaphore::post (sem_t *sem)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!is_good_object (sem))
|
2003-10-27 19:48:29 +08:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
(*sem)->_post ();
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2000-10-17 07:55:58 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-10-27 19:48:29 +08:00
|
|
|
int
|
|
|
|
semaphore::getvalue (sem_t *sem, int *sval)
|
|
|
|
{
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
2003-10-27 19:48:29 +08:00
|
|
|
{
|
2014-08-22 17:21:33 +08:00
|
|
|
if (is_good_object (sem))
|
|
|
|
return (*sem)->_getvalue (sval);
|
2003-10-27 19:48:29 +08:00
|
|
|
}
|
2014-08-22 17:21:33 +08:00
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
2003-10-27 19:48:29 +08:00
|
|
|
}
|
|
|
|
|
2007-02-20 23:48:04 +08:00
|
|
|
int
|
|
|
|
semaphore::getinternal (sem_t *sem, int *sfd, unsigned long long *shash,
|
|
|
|
LUID *sluid, unsigned int *sval)
|
|
|
|
{
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
if (!is_good_object (sem))
|
|
|
|
__leave;
|
|
|
|
if ((*sfd = (*sem)->fd) < 0)
|
|
|
|
__leave;
|
|
|
|
*shash = (*sem)->hash;
|
|
|
|
*sluid = (*sem)->luid;
|
|
|
|
/* POSIX defines the value in calls to sem_init/sem_open as unsigned,
|
|
|
|
but the sem_getvalue gets a pointer to int to return the value.
|
|
|
|
Go figure! */
|
|
|
|
return (*sem)->_getvalue ((int *)sval);
|
|
|
|
}
|
|
|
|
__except (NO_ERROR) {}
|
|
|
|
__endtry
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
2007-02-20 23:48:04 +08:00
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
/* pthread_null */
|
2002-09-16 18:53:29 +08:00
|
|
|
pthread *
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::get_null_pthread ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
/* because of weird entry points */
|
|
|
|
_instance.magic = 0;
|
|
|
|
return &_instance;
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::pthread_null ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
2002-11-24 21:54:14 +08:00
|
|
|
attr.joinable = PTHREAD_CREATE_DETACHED;
|
2002-09-16 18:53:29 +08:00
|
|
|
/* Mark ourselves as invalid */
|
|
|
|
magic = 0;
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::~pthread_null ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-08-06 00:14:41 +08:00
|
|
|
bool
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::create (void *(*)(void *), pthread_attr *, void *)
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
2005-08-06 00:14:41 +08:00
|
|
|
return true;
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::exit (void *value_ptr)
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
2005-01-29 13:39:07 +08:00
|
|
|
_my_tls.remove (INFINITE);
|
2002-11-24 21:54:14 +08:00
|
|
|
ExitThread (0);
|
2002-09-16 18:53:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::cancel ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::testcancel ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::setcancelstate (int state, int *oldstate)
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::setcanceltype (int type, int *oldtype)
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::push_cleanup_handler (__pthread_cleanup_handler *handler)
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::pop_cleanup_handler (int const execute)
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
}
|
2003-01-15 04:31:47 +08:00
|
|
|
|
2002-09-16 18:53:29 +08:00
|
|
|
unsigned long
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null::getsequence_np ()
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null pthread_null::_instance;
|
POSIX barrier implementation, take 3
The attached patch should address all of the review comments.
Modifed change log:
Newlib:
* libc/include/sys/features.h (_POSIX_BARRIERS): Define for Cygwin.
* libc/include/sys/types.h (pthread_barrier_t)
(pthread_barrierattr_t): Do not define for Cygwin.
Cygwin:
* common.din (pthread_barrierattr_init)
(pthread_barrierattr_setpshared, pthread_barrierattr_getpshared)
(pthread_barrierattr_destroy, pthread_barrier_init)
(pthread_barrier_destroy, pthread_barrier_wait): Export.
* include/cygwin/types.h (pthread_barrierattr_t)
(pthread_barrier_t): Declare.
* include/pthread.h (PTHREAD_BARRIER_SERIAL_THREAD)
(pthread_barrierattr_init, pthread_barrierattr_setpshared)
(pthread_barrierattr_getpshared, pthread_barrierattr_destroy)
(pthread_barrier_init, pthread_barrier_destroy)
(pthread_barrier_wait): Declare.
* thread.h (PTHREAD_BARRIER_MAGIC)
(PTHREAD_BARRIERATTR_MAGIC): Define.
(class pthread_barrierattr, class pthread_barrier): Declare.
* thread.cc (delete_and_clear): New local helper function.
(class pthread_barrierattr, class pthread_barrier): Implement.
* miscfuncs.h (likely, unlikely): New macros.
--
VH
2016-02-13 05:25:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
pthread_barrierattr_init (pthread_barrierattr_t * battr)
|
|
|
|
{
|
|
|
|
if (unlikely (battr == NULL))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
*battr = new pthread_barrierattr;
|
|
|
|
(*battr)->shared = PTHREAD_PROCESS_PRIVATE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
pthread_barrierattr_setpshared (pthread_barrierattr_t * battr, int shared)
|
|
|
|
{
|
|
|
|
if (unlikely (! pthread_barrierattr::is_good_object (battr)))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if (unlikely (shared != PTHREAD_PROCESS_SHARED
|
|
|
|
&& shared != PTHREAD_PROCESS_PRIVATE))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
(*battr)->shared = shared;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
pthread_barrierattr_getpshared (const pthread_barrierattr_t * battr,
|
|
|
|
int * shared)
|
|
|
|
{
|
|
|
|
if (unlikely (! pthread_barrierattr::is_good_object (battr)
|
|
|
|
|| shared == NULL))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
*shared = (*battr)->shared;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
pthread_barrierattr_destroy (pthread_barrierattr_t * battr)
|
|
|
|
{
|
|
|
|
if (unlikely (! pthread_barrierattr::is_good_object (battr)))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
delete_and_clear (battr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
pthread_barrier_init (pthread_barrier_t * bar,
|
|
|
|
const pthread_barrierattr_t * attr, unsigned count)
|
|
|
|
{
|
|
|
|
if (unlikely (bar == NULL))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
*bar = new pthread_barrier;
|
|
|
|
return (*bar)->init (attr, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_barrier::init (const pthread_barrierattr_t * attr, unsigned count)
|
|
|
|
{
|
|
|
|
pthread_mutex_t * mutex = NULL;
|
|
|
|
|
|
|
|
if (unlikely ((attr != NULL
|
|
|
|
&& (! pthread_barrierattr::is_good_object (attr)
|
|
|
|
|| (*attr)->shared == PTHREAD_PROCESS_SHARED))
|
|
|
|
|| count == 0))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
int retval = pthread_mutex_init (&mtx, NULL);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
retval = pthread_cond_init (&cond, NULL);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
{
|
|
|
|
int ret = pthread_mutex_destroy (mutex);
|
|
|
|
if (ret != 0)
|
|
|
|
api_fatal ("pthread_mutex_destroy (%p) = %d", mutex, ret);
|
|
|
|
|
|
|
|
mtx = NULL;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt = count;
|
|
|
|
cyc = 0;
|
|
|
|
wt = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
pthread_barrier_destroy (pthread_barrier_t * bar)
|
|
|
|
{
|
|
|
|
if (unlikely (! pthread_barrier::is_good_object (bar)))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
ret = (*bar)->destroy ();
|
|
|
|
if (ret == 0)
|
|
|
|
delete_and_clear (bar);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_barrier::destroy ()
|
|
|
|
{
|
|
|
|
if (unlikely (wt != 0))
|
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
int retval = pthread_cond_destroy (&cond);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
return retval;
|
|
|
|
else
|
|
|
|
cond = NULL;
|
|
|
|
|
|
|
|
retval = pthread_mutex_destroy (&mtx);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
return retval;
|
|
|
|
else
|
|
|
|
mtx = NULL;
|
|
|
|
|
|
|
|
cnt = 0;
|
|
|
|
cyc = 0;
|
|
|
|
wt = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
pthread_barrier_wait (pthread_barrier_t * bar)
|
|
|
|
{
|
|
|
|
if (unlikely (! pthread_barrier::is_good_object (bar)))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
return (*bar)->wait ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_barrier::wait ()
|
|
|
|
{
|
|
|
|
int retval = pthread_mutex_lock (&mtx);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (unlikely (wt >= cnt))
|
|
|
|
{
|
|
|
|
api_fatal ("wt >= cnt (%u >= %u)", wt, cnt);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely (++wt == cnt))
|
|
|
|
{
|
|
|
|
++cyc;
|
|
|
|
/* This is the last thread to reach the barrier. Signal the waiting
|
|
|
|
threads to wake up and continue. */
|
|
|
|
retval = pthread_cond_broadcast (&cond);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
goto cond_error;
|
|
|
|
|
|
|
|
wt = 0;
|
|
|
|
retval = pthread_mutex_unlock (&mtx);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
return PTHREAD_BARRIER_SERIAL_THREAD;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint64_t cycle = cyc;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
retval = pthread_cond_wait (&cond, &mtx);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
goto cond_error;
|
|
|
|
}
|
|
|
|
while (unlikely (cycle == cyc));
|
|
|
|
|
|
|
|
retval = pthread_mutex_unlock (&mtx);
|
|
|
|
if (unlikely (retval != 0))
|
|
|
|
api_fatal ("pthread_mutex_unlock (%p) = %d", &mtx, retval);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cond_error:
|
|
|
|
{
|
|
|
|
--wt;
|
|
|
|
int ret = pthread_mutex_unlock (&mtx);
|
|
|
|
if (unlikely (ret != 0))
|
|
|
|
api_fatal ("pthread_mutex_unlock (%p) = %d", &mtx, ret);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|