2000-02-18 03:38:33 +08:00
|
|
|
/* thread.h: Locking and threading module definitions
|
|
|
|
|
2003-01-10 20:32:49 +08:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
Written by Marco Fuykschot <marco@ddi.nl>
|
2001-03-21 10:17:58 +08:00
|
|
|
Major update 2001 Robert Collins <rbtcollins@hotmail.com>
|
2001-06-26 22:47:48 +08:00
|
|
|
|
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. */
|
|
|
|
|
|
|
|
#ifndef _CYGNUS_THREADS_
|
|
|
|
#define _CYGNUS_THREADS_
|
|
|
|
|
|
|
|
#define LOCK_FD_LIST 1
|
|
|
|
#define LOCK_MEMORY_LIST 2
|
|
|
|
#define LOCK_MMAP_LIST 3
|
|
|
|
#define LOCK_DLL_LIST 4
|
|
|
|
|
|
|
|
#define WRITE_LOCK 1
|
|
|
|
#define READ_LOCK 2
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#if defined (_CYG_THREAD_FAILSAFE) && defined (_MT_SAFE)
|
2001-04-12 12:04:53 +08:00
|
|
|
void AssertResourceOwner (int, int);
|
2000-02-18 03:38:33 +08:00
|
|
|
#else
|
2001-04-01 11:06:02 +08:00
|
|
|
#define AssertResourceOwner(i,ii)
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _MT_SAFE
|
|
|
|
|
|
|
|
#define SetResourceLock(i,n,c)
|
|
|
|
#define ReleaseResourceLock(i,n,c)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
#include <pthread.h>
|
2003-03-19 03:39:21 +08:00
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
2001-03-21 10:17:58 +08:00
|
|
|
#include <signal.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
2000-08-22 13:10:20 +08:00
|
|
|
#define _NOMNTENT_FUNCS
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <mntent.h>
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
extern "C"
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2001-04-01 11:06:02 +08:00
|
|
|
struct _winsup_t
|
|
|
|
{
|
|
|
|
/*
|
2001-04-12 12:04:53 +08:00
|
|
|
Needed for the group functions
|
|
|
|
*/
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
struct __group16 _grp;
|
2001-04-01 11:06:02 +08:00
|
|
|
char *_namearray[2];
|
|
|
|
int _grp_pos;
|
|
|
|
|
|
|
|
/* console.cc */
|
|
|
|
unsigned _rarg;
|
|
|
|
|
|
|
|
/* dlfcn.cc */
|
|
|
|
int _dl_error;
|
|
|
|
char _dl_buffer[256];
|
|
|
|
|
|
|
|
/* passwd.cc */
|
|
|
|
struct passwd _res;
|
|
|
|
char _pass[_PASSWORD_LEN];
|
|
|
|
int _pw_pos;
|
|
|
|
|
|
|
|
/* path.cc */
|
|
|
|
struct mntent mntbuf;
|
|
|
|
int _iteration;
|
|
|
|
DWORD available_drives;
|
2001-04-02 12:27:12 +08:00
|
|
|
char mnt_type[80];
|
|
|
|
char mnt_opts[80];
|
|
|
|
char mnt_fsname[MAX_PATH];
|
|
|
|
char mnt_dir[MAX_PATH];
|
2001-04-01 11:06:02 +08:00
|
|
|
|
|
|
|
/* strerror */
|
|
|
|
char _strerror_buf[20];
|
|
|
|
|
|
|
|
/* sysloc.cc */
|
|
|
|
char *_process_ident;
|
|
|
|
int _process_logopt;
|
|
|
|
int _process_facility;
|
|
|
|
int _process_logmask;
|
|
|
|
|
|
|
|
/* times.cc */
|
|
|
|
char timezone_buf[20];
|
|
|
|
struct tm _localtime_buf;
|
|
|
|
|
|
|
|
/* uinfo.cc */
|
2001-05-01 02:21:48 +08:00
|
|
|
char _username[UNLEN + 1];
|
2001-08-23 05:51:48 +08:00
|
|
|
|
|
|
|
/* net.cc */
|
|
|
|
char *_ntoa_buf;
|
|
|
|
struct protoent *_protoent_buf;
|
|
|
|
struct servent *_servent_buf;
|
|
|
|
struct hostent *_hostent_buf;
|
2001-04-01 11:06:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct __reent_t
|
|
|
|
{
|
|
|
|
struct _reent *_clib;
|
|
|
|
struct _winsup_t *_winsup;
|
|
|
|
};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-04-01 11:06:02 +08:00
|
|
|
_reent *_reent_clib ();
|
|
|
|
_winsup_t *_reent_winsup ();
|
|
|
|
void SetResourceLock (int, int, const char *) __attribute__ ((regparm (3)));
|
|
|
|
void ReleaseResourceLock (int, int, const char *)
|
|
|
|
__attribute__ ((regparm (3)));
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#ifdef _CYG_THREAD_FAILSAFE
|
2001-04-01 11:06:02 +08:00
|
|
|
void AssertResourceOwner (int, int);
|
2000-02-18 03:38:33 +08:00
|
|
|
#else
|
|
|
|
#define AssertResourceOwner(i,ii)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
class native_mutex
|
2003-01-10 04:40:44 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool init ();
|
|
|
|
bool lock ();
|
|
|
|
void unlock ();
|
|
|
|
private:
|
|
|
|
HANDLE theHandle;
|
|
|
|
};
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
class per_process;
|
|
|
|
class pinfo;
|
|
|
|
|
|
|
|
class ResourceLocks
|
|
|
|
{
|
|
|
|
public:
|
2001-04-12 12:04:53 +08:00
|
|
|
ResourceLocks ()
|
|
|
|
{
|
|
|
|
}
|
2000-10-15 09:37:07 +08:00
|
|
|
LPCRITICAL_SECTION Lock (int);
|
|
|
|
void Init ();
|
|
|
|
void Delete ();
|
2000-02-18 03:38:33 +08:00
|
|
|
#ifdef _CYG_THREAD_FAILSAFE
|
2000-10-15 09:37:07 +08:00
|
|
|
DWORD owner;
|
|
|
|
DWORD count;
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
2001-03-21 10:17:58 +08:00
|
|
|
private:
|
2000-10-15 09:37:07 +08:00
|
|
|
CRITICAL_SECTION lock;
|
|
|
|
bool inited;
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
#define PTHREAD_MAGIC 0xdf0df045
|
|
|
|
#define PTHREAD_MUTEX_MAGIC PTHREAD_MAGIC+1
|
|
|
|
#define PTHREAD_KEY_MAGIC PTHREAD_MAGIC+2
|
|
|
|
#define PTHREAD_ATTR_MAGIC PTHREAD_MAGIC+3
|
|
|
|
#define PTHREAD_MUTEXATTR_MAGIC PTHREAD_MAGIC+4
|
|
|
|
#define PTHREAD_COND_MAGIC PTHREAD_MAGIC+5
|
|
|
|
#define PTHREAD_CONDATTR_MAGIC PTHREAD_MAGIC+6
|
|
|
|
#define SEM_MAGIC PTHREAD_MAGIC+7
|
2003-03-19 03:39:21 +08:00
|
|
|
#define PTHREAD_ONCE_MAGIC PTHREAD_MAGIC+8
|
* 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
|
|
|
#define PTHREAD_RWLOCK_MAGIC PTHREAD_MAGIC+9
|
|
|
|
#define PTHREAD_RWLOCKATTR_MAGIC PTHREAD_MAGIC+10
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2003-03-19 03:39:21 +08:00
|
|
|
#define MUTEX_OWNER_ANONYMOUS ((pthread_t) -1)
|
2003-01-10 04:50:23 +08:00
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
/* verifyable_object should not be defined here - it's a general purpose class */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
class verifyable_object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
long magic;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
verifyable_object (long);
|
|
|
|
virtual ~verifyable_object ();
|
2001-03-21 10:17:58 +08:00
|
|
|
};
|
|
|
|
|
2001-11-05 14:09:15 +08:00
|
|
|
typedef enum
|
2001-09-29 17:01:01 +08:00
|
|
|
{
|
|
|
|
VALID_OBJECT,
|
|
|
|
INVALID_OBJECT,
|
|
|
|
VALID_STATIC_OBJECT
|
|
|
|
} verifyable_object_state;
|
|
|
|
|
|
|
|
verifyable_object_state verifyable_object_isvalid (void const *, long);
|
|
|
|
verifyable_object_state verifyable_object_isvalid (void const *, long, void *);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
template <class list_node> class List {
|
2002-09-21 11:20:27 +08:00
|
|
|
public:
|
2003-03-23 18:52:02 +08:00
|
|
|
List() : head(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
void insert (list_node *node)
|
2003-03-23 18:52:02 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!node)
|
2003-03-23 18:52:02 +08:00
|
|
|
return;
|
2003-03-28 03:52:20 +08:00
|
|
|
node->next = (list_node *) InterlockedExchangePointer (&head, node);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
list_node *remove ( list_node *node)
|
2003-03-23 18:52:02 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
if (!node || !head)
|
2003-03-23 18:52:02 +08:00
|
|
|
return NULL;
|
2003-03-28 03:52:20 +08:00
|
|
|
if (node == head)
|
|
|
|
return pop ();
|
|
|
|
|
|
|
|
list_node *result_prev = head;
|
|
|
|
while (result_prev && result_prev->next && !(node == result_prev->next))
|
|
|
|
result_prev = result_prev->next;
|
|
|
|
if (result_prev)
|
|
|
|
return (list_node *)InterlockedExchangePointer (&result_prev->next, result_prev->next->next);
|
2003-03-23 18:52:02 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
list_node *pop ()
|
2003-03-23 18:52:02 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
return (list_node *) InterlockedExchangePointer (&head, head->next);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* poor mans generic programming. */
|
2003-03-28 03:52:20 +08:00
|
|
|
void for_each (void (list_node::*callback) ())
|
2003-03-23 18:52:02 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
list_node *node = head;
|
|
|
|
while (node)
|
2003-03-23 18:52:02 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
(node->*callback) ();
|
|
|
|
node = node->next;
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-21 11:20:27 +08:00
|
|
|
protected:
|
2003-03-28 03:52:20 +08:00
|
|
|
list_node *head;
|
2002-09-21 11:20:27 +08:00
|
|
|
};
|
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
class pthread_key:public verifyable_object
|
|
|
|
{
|
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object (pthread_key_t const *);
|
|
|
|
DWORD tls_index;
|
2002-09-17 17:12:36 +08:00
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
int set (const void *);
|
2002-09-21 09:59:46 +08:00
|
|
|
void *get () const;
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2002-09-21 09:59:46 +08:00
|
|
|
pthread_key (void (*)(void *));
|
2002-09-29 10:19:35 +08:00
|
|
|
~pthread_key ();
|
2003-03-23 18:52:02 +08:00
|
|
|
static void fixup_before_fork()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
keys.for_each (&pthread_key::save_key_to_buffer);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fixup_after_fork()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
keys.for_each (&pthread_key::recreate_key_from_buffer);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
static void run_all_destructors ()
|
2003-03-23 18:52:02 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
keys.for_each (&pthread_key::run_destructor);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
2002-09-21 11:20:27 +08:00
|
|
|
|
|
|
|
/* List support calls */
|
|
|
|
class pthread_key *next;
|
2002-09-17 17:12:36 +08:00
|
|
|
private:
|
2002-09-21 11:20:27 +08:00
|
|
|
static List<pthread_key> keys;
|
2003-03-28 03:52:20 +08:00
|
|
|
void save_key_to_buffer ();
|
|
|
|
void recreate_key_from_buffer ();
|
2002-09-21 09:59:46 +08:00
|
|
|
void (*destructor) (void *);
|
2003-03-28 03:52:20 +08:00
|
|
|
void run_destructor ();
|
2002-09-21 11:20:27 +08:00
|
|
|
void *fork_buf;
|
2001-04-12 12:04:53 +08:00
|
|
|
};
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
class pthread_attr:public verifyable_object
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-03-21 10:17:58 +08:00
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object(pthread_attr_t const *);
|
2001-03-21 10:17:58 +08:00
|
|
|
int joinable;
|
2001-04-12 12:04:53 +08:00
|
|
|
int contentionscope;
|
|
|
|
int inheritsched;
|
|
|
|
struct sched_param schedparam;
|
2001-03-21 10:17:58 +08:00
|
|
|
size_t stacksize;
|
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
pthread_attr ();
|
|
|
|
~pthread_attr ();
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2002-06-10 10:40:13 +08:00
|
|
|
class pthread_mutexattr:public verifyable_object
|
|
|
|
{
|
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object(pthread_mutexattr_t const *);
|
2002-06-10 10:40:13 +08:00
|
|
|
int pshared;
|
|
|
|
int mutextype;
|
2002-09-29 10:19:35 +08:00
|
|
|
pthread_mutexattr ();
|
|
|
|
~pthread_mutexattr ();
|
2002-06-10 10:40:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class pthread_mutex:public verifyable_object
|
|
|
|
{
|
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object (pthread_mutex_t const *);
|
|
|
|
static bool is_good_initializer (pthread_mutex_t const *);
|
|
|
|
static bool is_good_initializer_or_object (pthread_mutex_t const *);
|
|
|
|
static bool is_good_initializer_or_bad_object (pthread_mutex_t const *mutex);
|
|
|
|
static bool can_be_unlocked (pthread_mutex_t const *mutex);
|
|
|
|
static void init_mutex ();
|
2002-09-30 07:47:45 +08:00
|
|
|
static int init (pthread_mutex_t *, const pthread_mutexattr_t *);
|
2002-09-30 10:51:22 +08:00
|
|
|
|
2003-03-19 03:39:21 +08:00
|
|
|
unsigned long lock_counter;
|
2002-06-10 10:40:13 +08:00
|
|
|
HANDLE win32_obj_id;
|
2003-01-10 04:50:23 +08:00
|
|
|
unsigned int recursion_counter;
|
2002-06-10 10:40:13 +08:00
|
|
|
LONG condwaits;
|
2003-01-10 04:50:23 +08:00
|
|
|
pthread_t owner;
|
|
|
|
int type;
|
2002-06-10 10:40:13 +08:00
|
|
|
int pshared;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_t get_pthread_self () const
|
2003-03-19 03:39:21 +08:00
|
|
|
{
|
|
|
|
return PTHREAD_MUTEX_NORMAL == type ? MUTEX_OWNER_ANONYMOUS :
|
|
|
|
::pthread_self ();
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
int lock ()
|
2003-03-19 03:39:21 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
return _lock (get_pthread_self ());
|
2003-03-19 03:39:21 +08:00
|
|
|
}
|
2003-03-28 03:52:20 +08:00
|
|
|
int trylock ()
|
2003-03-19 03:39:21 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
return _trylock (get_pthread_self ());
|
2003-03-19 03:39:21 +08:00
|
|
|
}
|
2003-03-28 03:52:20 +08:00
|
|
|
int unlock ()
|
2003-03-19 03:39:21 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
return _unlock (get_pthread_self ());
|
2003-03-19 03:39:21 +08:00
|
|
|
}
|
2003-03-28 03:52:20 +08:00
|
|
|
int destroy ()
|
2003-03-19 03:39:21 +08:00
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
return _destroy (get_pthread_self ());
|
2003-03-19 03:39:21 +08:00
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
void set_owner (pthread_t self)
|
2003-03-19 03:39:21 +08:00
|
|
|
{
|
|
|
|
recursion_counter = 1;
|
|
|
|
owner = self;
|
|
|
|
}
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
int lock_recursive ()
|
2003-03-19 03:39:21 +08:00
|
|
|
{
|
|
|
|
if (UINT_MAX == recursion_counter)
|
|
|
|
return EAGAIN;
|
|
|
|
++recursion_counter;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-10 10:40:13 +08:00
|
|
|
pthread_mutex (pthread_mutexattr * = NULL);
|
|
|
|
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
|
|
|
|
~pthread_mutex ();
|
2003-01-10 04:40:44 +08:00
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
class pthread_mutex * next;
|
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
mutexes.for_each (&pthread_mutex::_fixup_after_fork);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
2002-09-30 07:47:45 +08:00
|
|
|
private:
|
2003-03-28 03:52:20 +08:00
|
|
|
int _lock (pthread_t self);
|
|
|
|
int _trylock (pthread_t self);
|
|
|
|
int _unlock (pthread_t self);
|
|
|
|
int _destroy (pthread_t self);
|
|
|
|
|
|
|
|
void _fixup_after_fork ();
|
2003-03-19 03:39:21 +08:00
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
static List<pthread_mutex> mutexes;
|
2003-03-28 03:52:20 +08:00
|
|
|
static native_mutex mutex_initialization_lock;
|
2002-06-10 10:40:13 +08:00
|
|
|
};
|
|
|
|
|
2003-01-10 04:57:54 +08:00
|
|
|
#define WAIT_CANCELED (WAIT_OBJECT_0 + 1)
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
class pthread:public verifyable_object
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
public:
|
2001-03-21 10:17:58 +08:00
|
|
|
HANDLE win32_obj_id;
|
|
|
|
class pthread_attr attr;
|
|
|
|
void *(*function) (void *);
|
2000-10-15 09:37:07 +08:00
|
|
|
void *arg;
|
|
|
|
void *return_ptr;
|
|
|
|
bool suspended;
|
2001-04-12 12:04:53 +08:00
|
|
|
int cancelstate, canceltype;
|
2002-07-04 22:17:30 +08:00
|
|
|
HANDLE cancel_event;
|
2002-06-05 20:39:55 +08:00
|
|
|
pthread_t joiner;
|
2001-04-12 12:04:53 +08:00
|
|
|
// int joinable;
|
|
|
|
|
2000-10-15 09:37:07 +08:00
|
|
|
/* signal handling */
|
|
|
|
struct sigaction *sigs;
|
|
|
|
sigset_t *sigmask;
|
|
|
|
LONG *sigtodo;
|
2002-09-16 18:53:29 +08:00
|
|
|
virtual void create (void *(*)(void *), pthread_attr *, void *);
|
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
pthread ();
|
|
|
|
virtual ~pthread ();
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
static void init_mainthread (bool);
|
|
|
|
static bool is_good_object(pthread_t const *);
|
2002-09-29 10:19:35 +08:00
|
|
|
static void atforkprepare();
|
|
|
|
static void atforkparent();
|
|
|
|
static void atforkchild();
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
/* API calls */
|
|
|
|
static int cancel (pthread_t);
|
|
|
|
static int join (pthread_t * thread, void **return_val);
|
|
|
|
static int detach (pthread_t * thread);
|
|
|
|
static int create (pthread_t * thread, const pthread_attr_t * attr,
|
2002-09-21 11:59:58 +08:00
|
|
|
void *(*start_routine) (void *), void *arg);
|
2002-09-29 10:19:35 +08:00
|
|
|
static int once (pthread_once_t *, void (*)(void));
|
|
|
|
static int atfork(void (*)(void), void (*)(void), void (*)(void));
|
|
|
|
static int suspend (pthread_t * thread);
|
|
|
|
static int resume (pthread_t * thread);
|
2002-09-21 11:59:58 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
virtual void exit (void *value_ptr);
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
virtual int cancel ();
|
2002-09-30 10:51:22 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
virtual void testcancel ();
|
|
|
|
static void static_cancel_self ();
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2003-01-10 04:57:54 +08:00
|
|
|
static DWORD cancelable_wait (HANDLE object, DWORD timeout, const bool do_cancel = true);
|
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
virtual int setcancelstate (int state, int *oldstate);
|
|
|
|
virtual int setcanceltype (int type, int *oldtype);
|
2002-07-04 22:17:30 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
virtual void push_cleanup_handler (__pthread_cleanup_handler *handler);
|
|
|
|
virtual void pop_cleanup_handler (int const execute);
|
2002-06-10 09:10:45 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
static pthread* self ();
|
|
|
|
static void *thread_init_wrapper (void *);
|
2002-06-10 09:10:45 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
virtual unsigned long getsequence_np();
|
2002-09-16 18:53:29 +08:00
|
|
|
|
2003-04-18 03:57:01 +08:00
|
|
|
static int equal (pthread_t t1, pthread_t t2)
|
|
|
|
{
|
|
|
|
return t1 == t2;
|
|
|
|
}
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
private:
|
2002-09-29 10:19:35 +08:00
|
|
|
DWORD thread_id;
|
|
|
|
__pthread_cleanup_handler *cleanup_stack;
|
|
|
|
pthread_mutex mutex;
|
|
|
|
|
|
|
|
void pop_all_cleanup_handlers (void);
|
|
|
|
void precreate (pthread_attr *);
|
|
|
|
void postcreate ();
|
2003-03-28 03:52:20 +08:00
|
|
|
void set_thread_id_to_current ();
|
|
|
|
static void set_tls_self_pointer (pthread *);
|
|
|
|
static pthread *get_tls_self_pointer ();
|
2002-09-29 10:19:35 +08:00
|
|
|
void cancel_self ();
|
2003-03-28 03:52:20 +08:00
|
|
|
DWORD get_thread_id ();
|
|
|
|
void init_current_thread ();
|
2002-09-16 18:53:29 +08:00
|
|
|
};
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
class pthread_null : public pthread
|
2002-09-16 18:53:29 +08:00
|
|
|
{
|
2002-09-17 00:09:54 +08:00
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static pthread *get_null_pthread();
|
|
|
|
~pthread_null();
|
2002-09-29 10:19:35 +08:00
|
|
|
|
|
|
|
/* From pthread These should never get called
|
|
|
|
* as the ojbect is not verifyable
|
|
|
|
*/
|
|
|
|
void create (void *(*)(void *), pthread_attr *, void *);
|
|
|
|
void exit (void *value_ptr);
|
|
|
|
int cancel ();
|
|
|
|
void testcancel ();
|
|
|
|
int setcancelstate (int state, int *oldstate);
|
|
|
|
int setcanceltype (int type, int *oldtype);
|
|
|
|
void push_cleanup_handler (__pthread_cleanup_handler *handler);
|
|
|
|
void pop_cleanup_handler (int const execute);
|
|
|
|
unsigned long getsequence_np();
|
2002-09-16 18:53:29 +08:00
|
|
|
|
|
|
|
private:
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_null ();
|
|
|
|
static pthread_null _instance;
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
class pthread_condattr:public verifyable_object
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object(pthread_condattr_t const *);
|
2000-10-15 09:37:07 +08:00
|
|
|
int shared;
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2001-06-26 22:47:48 +08:00
|
|
|
pthread_condattr ();
|
|
|
|
~pthread_condattr ();
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
class pthread_cond:public verifyable_object
|
2001-03-17 09:14:58 +08:00
|
|
|
{
|
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object (pthread_cond_t const *);
|
|
|
|
static bool is_good_initializer (pthread_cond_t const *);
|
|
|
|
static bool is_good_initializer_or_object (pthread_cond_t const *);
|
|
|
|
static bool is_good_initializer_or_bad_object (pthread_cond_t const *);
|
|
|
|
static void init_mutex ();
|
2003-01-10 04:40:44 +08:00
|
|
|
static int init (pthread_cond_t *, const pthread_condattr_t *);
|
|
|
|
|
2001-03-17 09:14:58 +08:00
|
|
|
int shared;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
|
|
|
unsigned long waiting;
|
|
|
|
unsigned long pending;
|
2003-03-28 03:52:20 +08:00
|
|
|
HANDLE sem_wait;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_mutex mtx_in;
|
|
|
|
pthread_mutex mtx_out;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_mutex_t mtx_cond;
|
2003-03-19 03:49:38 +08:00
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
void unblock (const bool all);
|
|
|
|
int wait (pthread_mutex_t mutex, DWORD dwMilliseconds = INFINITE);
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
pthread_cond (pthread_condattr *);
|
|
|
|
~pthread_cond ();
|
2003-01-10 04:40:44 +08:00
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
class pthread_cond * next;
|
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
conds.for_each (&pthread_cond::_fixup_after_fork);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
2003-01-10 04:40:44 +08:00
|
|
|
private:
|
2003-03-28 03:52:20 +08:00
|
|
|
void _fixup_after_fork ();
|
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
static List<pthread_cond> conds;
|
2003-03-28 03:52:20 +08:00
|
|
|
static native_mutex cond_initialization_lock;
|
2001-04-12 12:04:53 +08:00
|
|
|
};
|
|
|
|
|
* 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
|
|
|
class pthread_rwlockattr:public verifyable_object
|
|
|
|
{
|
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object(pthread_rwlockattr_t const *);
|
* 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 shared;
|
|
|
|
|
|
|
|
pthread_rwlockattr ();
|
|
|
|
~pthread_rwlockattr ();
|
|
|
|
};
|
|
|
|
|
|
|
|
class pthread_rwlock:public verifyable_object
|
|
|
|
{
|
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object (pthread_rwlock_t const *);
|
|
|
|
static bool is_good_initializer (pthread_rwlock_t const *);
|
|
|
|
static bool is_good_initializer_or_object (pthread_rwlock_t const *);
|
|
|
|
static bool is_good_initializer_or_bad_object (pthread_rwlock_t const *);
|
|
|
|
static void 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
|
|
|
static int init (pthread_rwlock_t *, const pthread_rwlockattr_t *);
|
|
|
|
|
|
|
|
int shared;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
unsigned long waiting_readers;
|
|
|
|
unsigned long 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_t writer;
|
|
|
|
struct RWLOCK_READER
|
|
|
|
{
|
|
|
|
struct RWLOCK_READER *next;
|
|
|
|
pthread_t thread;
|
|
|
|
} *readers;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
int rdlock ();
|
|
|
|
int 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-28 03:52:20 +08:00
|
|
|
int wrlock ();
|
|
|
|
int 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-28 03:52:20 +08:00
|
|
|
int 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
|
|
|
|
|
|
|
pthread_mutex mtx;
|
2003-03-28 03:52:20 +08:00
|
|
|
pthread_cond cond_readers;
|
|
|
|
pthread_cond cond_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_rwlock (pthread_rwlockattr *);
|
|
|
|
~pthread_rwlock ();
|
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
class pthread_rwlock * next;
|
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
rwlocks.for_each (&pthread_rwlock::_fixup_after_fork);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
* 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
|
|
|
private:
|
2003-03-23 18:52:02 +08:00
|
|
|
static List<pthread_rwlock> rwlocks;
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
void add_reader (struct RWLOCK_READER *rd);
|
|
|
|
void remove_reader (struct RWLOCK_READER *rd);
|
|
|
|
struct RWLOCK_READER *lookup_reader (pthread_t thread);
|
* 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-04-16 04:14:12 +08:00
|
|
|
void release ()
|
|
|
|
{
|
|
|
|
if (waiting_writers)
|
|
|
|
{
|
|
|
|
if (!readers)
|
|
|
|
cond_writers.unblock (false);
|
|
|
|
}
|
|
|
|
else if (waiting_readers)
|
|
|
|
cond_readers.unblock (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
static void rdlock_cleanup (void *arg);
|
|
|
|
static void 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
|
|
|
|
2003-03-28 03:52:20 +08:00
|
|
|
void _fixup_after_fork ();
|
|
|
|
|
|
|
|
static native_mutex 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
|
|
|
};
|
|
|
|
|
2001-04-12 12:04:53 +08:00
|
|
|
class pthread_once
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
int state;
|
2001-03-17 09:14:58 +08:00
|
|
|
};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
/* shouldn't be here */
|
|
|
|
class semaphore:public verifyable_object
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-03-21 10:17:58 +08:00
|
|
|
public:
|
2003-03-28 03:52:20 +08:00
|
|
|
static bool is_good_object(sem_t const *);
|
2002-09-21 11:59:58 +08:00
|
|
|
/* API calls */
|
|
|
|
static int init (sem_t * sem, int pshared, unsigned int value);
|
|
|
|
static int destroy (sem_t * sem);
|
|
|
|
static int wait (sem_t * sem);
|
|
|
|
static int trywait (sem_t * sem);
|
|
|
|
static int post (sem_t * sem);
|
2002-09-30 10:51:22 +08:00
|
|
|
|
2001-03-21 10:17:58 +08:00
|
|
|
HANDLE win32_obj_id;
|
|
|
|
int shared;
|
2001-09-11 16:15:39 +08:00
|
|
|
long currentvalue;
|
2001-03-21 10:17:58 +08:00
|
|
|
|
2002-09-29 10:19:35 +08:00
|
|
|
semaphore (int, unsigned int);
|
|
|
|
~semaphore ();
|
2003-03-23 18:52:02 +08:00
|
|
|
|
|
|
|
class semaphore * next;
|
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-03-28 03:52:20 +08:00
|
|
|
semaphores.for_each (&semaphore::_fixup_after_fork);
|
2003-03-23 18:52:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2003-03-28 03:52:20 +08:00
|
|
|
void _wait ();
|
|
|
|
void _post ();
|
|
|
|
int _trywait ();
|
|
|
|
|
|
|
|
void _fixup_after_fork ();
|
|
|
|
|
2003-03-23 18:52:02 +08:00
|
|
|
static List<semaphore> semaphores;
|
2001-03-21 10:17:58 +08:00
|
|
|
};
|
|
|
|
|
2001-04-13 23:28:20 +08:00
|
|
|
class callback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void (*cb)(void);
|
|
|
|
class callback * next;
|
|
|
|
};
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
class MTinterface
|
|
|
|
{
|
|
|
|
public:
|
2000-10-15 09:37:07 +08:00
|
|
|
// General
|
2001-04-12 12:04:53 +08:00
|
|
|
int concurrency;
|
2001-04-14 15:06:02 +08:00
|
|
|
long int threadcount;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-15 09:37:07 +08:00
|
|
|
// Used for main thread data, and sigproc thread
|
|
|
|
struct __reent_t reents;
|
|
|
|
struct _winsup_t winsup_reent;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-04-13 23:28:20 +08:00
|
|
|
callback *pthread_prepare;
|
|
|
|
callback *pthread_child;
|
|
|
|
callback *pthread_parent;
|
2001-04-12 12:04:53 +08:00
|
|
|
|
2002-11-24 21:54:14 +08:00
|
|
|
pthread_key reent_key;
|
|
|
|
pthread_key thread_self_key;
|
|
|
|
|
2000-10-17 07:55:58 +08:00
|
|
|
void Init (int);
|
2002-09-17 17:12:36 +08:00
|
|
|
void fixup_before_fork (void);
|
2001-09-11 16:15:39 +08:00
|
|
|
void fixup_after_fork (void);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-11-24 21:54:14 +08:00
|
|
|
MTinterface () :
|
|
|
|
concurrency (0), threadcount (1),
|
|
|
|
pthread_prepare (NULL), pthread_child (NULL), pthread_parent (NULL),
|
|
|
|
reent_key (NULL), thread_self_key (NULL)
|
2002-09-29 10:19:35 +08:00
|
|
|
{
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2002-11-24 21:54:14 +08:00
|
|
|
#define MT_INTERFACE user_data->threadinterface
|
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
#endif // MT_SAFE
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
#endif // _CYGNUS_THREADS_
|