2000-02-17 20:38:33 +01:00
|
|
|
/* thread.h: Locking and threading module definitions
|
|
|
|
|
2013-01-21 05:38:31 +01:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
|
|
|
|
2010, 2011, 2012, 2013 Red Hat, Inc.
|
2001-06-26 16:47:48 +02:00
|
|
|
|
2000-02-17 20:38:33 +01: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. */
|
|
|
|
|
2012-01-11 20:07:11 +01:00
|
|
|
#pragma once
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-01-14 16:45:37 +01:00
|
|
|
#define LOCK_MMAP_LIST 1
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
#define WRITE_LOCK 1
|
|
|
|
#define READ_LOCK 2
|
|
|
|
|
2012-02-13 14:12:37 +01:00
|
|
|
/* Default is a 1 Megs stack with a 4K guardpage. The pthread stacksize
|
|
|
|
does not include the guardpage size, so we subtract the default guardpage
|
|
|
|
size. Additionally, the Windows stack handling disallows to use the last
|
|
|
|
two pages as guard page (tested on XP and W7). That results in a zone of
|
|
|
|
three pages which have to be subtract to get the actual stack size. */
|
|
|
|
#define PTHREAD_DEFAULT_STACKSIZE (1024 * 1024 - 3 * wincap.page_size ())
|
2012-02-11 18:37:02 +01:00
|
|
|
#define PTHREAD_DEFAULT_GUARDSIZE (wincap.page_size ())
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
#include <pthread.h>
|
2003-03-18 20:39:21 +01:00
|
|
|
#include <limits.h>
|
2009-01-03 06:12:22 +01:00
|
|
|
#include "security.h"
|
2003-12-23 17:26:31 +01:00
|
|
|
#include <errno.h>
|
2011-03-29 09:49:25 +02:00
|
|
|
#include "cygerrno.h"
|
2012-06-17 22:50:24 +02:00
|
|
|
#include "cygwait.h"
|
2005-06-09 07:11:51 +02:00
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
class fast_mutex
|
2003-01-09 21:40:44 +01:00
|
|
|
{
|
|
|
|
public:
|
2003-10-24 21:34:47 +02:00
|
|
|
fast_mutex () :
|
|
|
|
lock_counter (0), win32_obj_id (0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~fast_mutex ()
|
|
|
|
{
|
|
|
|
if(win32_obj_id)
|
|
|
|
CloseHandle (win32_obj_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool init ()
|
|
|
|
{
|
2003-10-27 22:12:42 +01:00
|
|
|
lock_counter = 0;
|
2010-02-10 08:25:26 +01:00
|
|
|
win32_obj_id = ::CreateEvent (&sec_none_nih, false, false, NULL);
|
2003-10-24 21:34:47 +02:00
|
|
|
if (!win32_obj_id)
|
|
|
|
{
|
2010-02-10 08:25:26 +01:00
|
|
|
debug_printf ("CreateEvent failed. %E");
|
2003-12-02 02:36:08 +01:00
|
|
|
return false;
|
2003-10-24 21:34:47 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lock ()
|
|
|
|
{
|
2012-10-23 12:17:29 +02:00
|
|
|
if (InterlockedIncrement (&lock_counter) != 1)
|
2012-08-15 21:07:42 +02:00
|
|
|
cygwait (win32_obj_id, cw_infinite, cw_sig);
|
2003-10-24 21:34:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void unlock ()
|
|
|
|
{
|
2012-10-23 12:17:29 +02:00
|
|
|
if (InterlockedDecrement (&lock_counter))
|
2010-02-10 08:25:26 +01:00
|
|
|
::SetEvent (win32_obj_id);
|
2003-10-24 21:34:47 +02:00
|
|
|
}
|
|
|
|
|
2003-01-09 21:40:44 +01:00
|
|
|
private:
|
2012-10-23 12:17:29 +02:00
|
|
|
LONG lock_counter;
|
2003-10-24 21:34:47 +02:00
|
|
|
HANDLE win32_obj_id;
|
2003-01-09 21:40:44 +01:00
|
|
|
};
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
class per_process;
|
|
|
|
class pinfo;
|
|
|
|
|
2001-03-21 03:17:58 +01: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-18 20:39:21 +01: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-18 21:01:07 +01:00
|
|
|
#define PTHREAD_RWLOCK_MAGIC PTHREAD_MAGIC+9
|
|
|
|
#define PTHREAD_RWLOCKATTR_MAGIC PTHREAD_MAGIC+10
|
2011-03-29 12:32:40 +02:00
|
|
|
#define PTHREAD_SPINLOCK_MAGIC PTHREAD_MAGIC+11
|
2001-04-12 06:04:53 +02:00
|
|
|
|
2009-06-30 23:18:44 +02:00
|
|
|
#define MUTEX_OWNER_ANONYMOUS ((pthread_t) -1)
|
2003-01-09 21:50:23 +01:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
typedef uint32_t thread_magic_t;
|
2010-02-12 21:07:13 +01:00
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
/* verifyable_object should not be defined here - it's a general purpose class */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-03-21 03:17:58 +01:00
|
|
|
class verifyable_object
|
|
|
|
{
|
|
|
|
public:
|
2010-02-12 21:07:13 +01:00
|
|
|
thread_magic_t magic;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2010-02-12 21:07:13 +01:00
|
|
|
verifyable_object (thread_magic_t verifyer): magic (verifyer) {}
|
|
|
|
virtual ~verifyable_object () { magic = 0; }
|
2001-03-21 03:17:58 +01:00
|
|
|
};
|
|
|
|
|
2001-11-05 07:09:15 +01:00
|
|
|
typedef enum
|
2001-09-29 11:01:01 +02:00
|
|
|
{
|
|
|
|
VALID_OBJECT,
|
|
|
|
INVALID_OBJECT,
|
|
|
|
VALID_STATIC_OBJECT
|
|
|
|
} verifyable_object_state;
|
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
template <class list_node> inline void
|
2003-12-01 23:10:57 +01:00
|
|
|
List_insert (list_node *&head, list_node *node)
|
2003-10-24 21:34:47 +02:00
|
|
|
{
|
|
|
|
if (!node)
|
|
|
|
return;
|
2003-12-01 23:10:57 +01:00
|
|
|
do
|
|
|
|
node->next = head;
|
2012-10-23 12:17:29 +02:00
|
|
|
while (InterlockedCompareExchangePointer ((PVOID volatile *) &head,
|
|
|
|
node, node->next) != node->next);
|
2003-10-24 21:34:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class list_node> inline void
|
2012-10-23 12:17:29 +02:00
|
|
|
List_remove (fast_mutex &mx, list_node *&head, list_node *node)
|
2003-10-24 21:34:47 +02:00
|
|
|
{
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
mx.lock ();
|
2003-12-01 23:10:57 +01:00
|
|
|
if (head)
|
2003-10-24 21:34:47 +02:00
|
|
|
{
|
2012-10-23 12:17:29 +02:00
|
|
|
if (InterlockedCompareExchangePointer ((PVOID volatile *) &head,
|
|
|
|
node->next, node) != node)
|
2003-12-02 02:36:08 +01:00
|
|
|
{
|
|
|
|
list_node *cur = head;
|
|
|
|
|
|
|
|
while (cur->next && node != cur->next)
|
|
|
|
cur = cur->next;
|
|
|
|
if (node == cur->next)
|
|
|
|
cur->next = cur->next->next;
|
|
|
|
}
|
2003-10-24 21:34:47 +02:00
|
|
|
}
|
|
|
|
mx.unlock ();
|
|
|
|
}
|
2003-11-28 21:55:59 +01:00
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
|
|
|
|
template <class list_node> class List
|
|
|
|
{
|
|
|
|
public:
|
2003-03-23 11:52:02 +01:00
|
|
|
List() : head(NULL)
|
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
mx_init ();
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
~List()
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
void fixup_after_fork ()
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
mx_init ();
|
|
|
|
}
|
2003-03-27 20:52:20 +01:00
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
void insert (list_node *node)
|
|
|
|
{
|
2003-12-01 23:10:57 +01:00
|
|
|
List_insert (head, node);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
void remove (list_node *node)
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
List_remove (mx, head, node);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
void for_each (void (list_node::*callback) ())
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
mx.lock ();
|
|
|
|
list_node *cur = head;
|
|
|
|
while (cur)
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
2003-12-02 02:36:08 +01:00
|
|
|
(cur->*callback) ();
|
|
|
|
cur = cur->next;
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
2003-10-24 21:34:47 +02:00
|
|
|
mx.unlock ();
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2007-02-20 16:48:04 +01:00
|
|
|
fast_mutex mx;
|
|
|
|
list_node *head;
|
|
|
|
|
2002-09-21 05:20:27 +02:00
|
|
|
protected:
|
2003-10-24 21:34:47 +02:00
|
|
|
void mx_init ()
|
|
|
|
{
|
|
|
|
if (!mx.init ())
|
|
|
|
api_fatal ("Could not create mutex for list synchronisation.");
|
|
|
|
}
|
2002-09-21 05:20:27 +02:00
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_key: public verifyable_object
|
2001-04-12 06:04:53 +02:00
|
|
|
{
|
2005-05-29 04:42:36 +02:00
|
|
|
DWORD tls_index;
|
2001-04-12 06:04:53 +02:00
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object (pthread_key_t const *);
|
2002-09-17 11:12:36 +02:00
|
|
|
|
2005-05-29 04:42:36 +02:00
|
|
|
int set (const void *value) {TlsSetValue (tls_index, (void *) value); return 0;}
|
|
|
|
void *get () const {return TlsGetValue (tls_index);}
|
2001-04-12 06:04:53 +02:00
|
|
|
|
2002-09-21 03:59:46 +02:00
|
|
|
pthread_key (void (*)(void *));
|
2002-09-29 04:19:35 +02:00
|
|
|
~pthread_key ();
|
2003-10-24 21:34:47 +02:00
|
|
|
static void fixup_before_fork ()
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
keys.for_each (&pthread_key::_fixup_before_fork);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
static void fixup_after_fork ()
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
keys.fixup_after_fork ();
|
|
|
|
keys.for_each (&pthread_key::_fixup_after_fork);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
static void run_all_destructors ()
|
2003-03-23 11:52:02 +01:00
|
|
|
{
|
2003-03-27 20:52:20 +01:00
|
|
|
keys.for_each (&pthread_key::run_destructor);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
2002-09-21 05:20:27 +02:00
|
|
|
|
|
|
|
/* List support calls */
|
|
|
|
class pthread_key *next;
|
2002-09-17 11:12:36 +02:00
|
|
|
private:
|
2002-09-21 05:20:27 +02:00
|
|
|
static List<pthread_key> keys;
|
2003-10-24 21:34:47 +02:00
|
|
|
void _fixup_before_fork ();
|
|
|
|
void _fixup_after_fork ();
|
2002-09-21 03:59:46 +02:00
|
|
|
void (*destructor) (void *);
|
2003-03-27 20:52:20 +01:00
|
|
|
void run_destructor ();
|
2002-09-21 05:20:27 +02:00
|
|
|
void *fork_buf;
|
2001-04-12 06:04:53 +02:00
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_attr: public verifyable_object
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-03-21 03:17:58 +01:00
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object(pthread_attr_t const *);
|
2001-03-21 03:17:58 +01:00
|
|
|
int joinable;
|
2001-04-12 06:04:53 +02:00
|
|
|
int contentionscope;
|
|
|
|
int inheritsched;
|
|
|
|
struct sched_param schedparam;
|
2011-05-03 03:13:37 +02:00
|
|
|
void *stackaddr;
|
2001-03-21 03:17:58 +01:00
|
|
|
size_t stacksize;
|
2011-05-15 20:49:40 +02:00
|
|
|
size_t guardsize;
|
2001-03-21 03:17:58 +01:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
pthread_attr ();
|
|
|
|
~pthread_attr ();
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_mutexattr: public verifyable_object
|
2002-06-10 04:40:13 +02:00
|
|
|
{
|
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object(pthread_mutexattr_t const *);
|
2002-06-10 04:40:13 +02:00
|
|
|
int pshared;
|
|
|
|
int mutextype;
|
2002-09-29 04:19:35 +02:00
|
|
|
pthread_mutexattr ();
|
|
|
|
~pthread_mutexattr ();
|
2002-06-10 04:40:13 +02:00
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_mutex: public verifyable_object
|
2002-06-10 04:40:13 +02:00
|
|
|
{
|
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static void init_mutex ();
|
2010-02-12 21:07:13 +01:00
|
|
|
static int init (pthread_mutex_t *, const pthread_mutexattr_t *attr,
|
|
|
|
const pthread_mutex_t);
|
2010-02-22 21:36:04 +01:00
|
|
|
static bool is_good_object (pthread_mutex_t const *);
|
|
|
|
static bool is_initializer (pthread_mutex_t const *);
|
|
|
|
static bool is_initializer_or_object (pthread_mutex_t const *);
|
|
|
|
static bool is_initializer_or_bad_object (pthread_mutex_t const *);
|
2002-06-10 04:40:13 +02:00
|
|
|
|
2010-02-10 08:25:26 +01:00
|
|
|
int lock ();
|
|
|
|
int trylock ();
|
|
|
|
int unlock ();
|
|
|
|
int destroy ();
|
2010-02-22 21:36:04 +01:00
|
|
|
void set_type (int in_type) {type = in_type;}
|
2003-03-18 20:39:21 +01:00
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
int lock_recursive ()
|
2003-03-18 20:39:21 +01:00
|
|
|
{
|
2010-02-22 21:36:04 +01:00
|
|
|
if (recursion_counter == UINT_MAX)
|
2003-03-18 20:39:21 +01:00
|
|
|
return EAGAIN;
|
2010-02-22 21:36:04 +01:00
|
|
|
recursion_counter++;
|
2003-03-18 20:39:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-22 21:36:04 +01:00
|
|
|
bool can_be_unlocked ();
|
|
|
|
|
2002-06-10 04:40:13 +02:00
|
|
|
pthread_mutex (pthread_mutexattr * = NULL);
|
|
|
|
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
|
|
|
|
~pthread_mutex ();
|
2003-01-09 21:40:44 +01:00
|
|
|
|
2010-02-22 21:36:04 +01:00
|
|
|
class pthread_mutex *next;
|
2003-03-23 11:52:02 +01:00
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
mutexes.fixup_after_fork ();
|
2003-03-27 20:52:20 +01:00
|
|
|
mutexes.for_each (&pthread_mutex::_fixup_after_fork);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2011-03-29 12:32:40 +02:00
|
|
|
protected:
|
2012-10-23 12:17:29 +02:00
|
|
|
LONG lock_counter;
|
2010-02-22 21:36:04 +01:00
|
|
|
HANDLE win32_obj_id;
|
|
|
|
pthread_t owner;
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
DWORD tid; /* the thread id of the owner */
|
|
|
|
#endif
|
|
|
|
|
2011-03-29 12:32:40 +02:00
|
|
|
void set_shared (int in_shared) { pshared = in_shared; }
|
2010-02-22 21:36:04 +01:00
|
|
|
void set_owner (pthread_t self)
|
|
|
|
{
|
|
|
|
recursion_counter = 1;
|
|
|
|
owner = self;
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
tid = GetCurrentThreadId ();
|
|
|
|
#endif
|
|
|
|
}
|
2011-03-29 12:32:40 +02:00
|
|
|
|
2010-02-22 21:36:04 +01:00
|
|
|
static const pthread_t _new_mutex;
|
|
|
|
static const pthread_t _unlocked_mutex;
|
|
|
|
static const pthread_t _destroyed_mutex;
|
|
|
|
|
2011-03-29 12:32:40 +02:00
|
|
|
private:
|
|
|
|
unsigned int recursion_counter;
|
|
|
|
LONG condwaits;
|
|
|
|
int type;
|
|
|
|
int pshared;
|
|
|
|
|
2010-02-22 21:36:04 +01:00
|
|
|
bool no_owner ();
|
2003-03-27 20:52:20 +01:00
|
|
|
void _fixup_after_fork ();
|
2003-03-18 20:39:21 +01:00
|
|
|
|
2003-03-23 11:52:02 +01:00
|
|
|
static List<pthread_mutex> mutexes;
|
2003-10-24 21:34:47 +02:00
|
|
|
static fast_mutex mutex_initialization_lock;
|
2010-02-22 21:36:04 +01:00
|
|
|
friend class pthread_cond;
|
2002-06-10 04:40:13 +02:00
|
|
|
};
|
|
|
|
|
2011-03-29 12:32:40 +02:00
|
|
|
class pthread_spinlock: public pthread_mutex
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static bool is_good_object (pthread_spinlock_t const *);
|
|
|
|
static int init (pthread_spinlock_t *, int);
|
|
|
|
|
|
|
|
int lock ();
|
|
|
|
int unlock ();
|
|
|
|
|
|
|
|
pthread_spinlock (int);
|
|
|
|
};
|
|
|
|
|
2004-02-12 04:01:58 +01:00
|
|
|
class _cygtls;
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread: public verifyable_object
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
public:
|
2001-03-21 03:17:58 +01:00
|
|
|
HANDLE win32_obj_id;
|
|
|
|
class pthread_attr attr;
|
|
|
|
void *(*function) (void *);
|
2000-10-15 03:37:07 +02:00
|
|
|
void *arg;
|
|
|
|
void *return_ptr;
|
2003-10-31 21:42:56 +01:00
|
|
|
bool valid;
|
2000-10-15 03:37:07 +02:00
|
|
|
bool suspended;
|
2011-04-30 12:20:25 +02:00
|
|
|
bool canceled;
|
2001-04-12 06:04:53 +02:00
|
|
|
int cancelstate, canceltype;
|
2004-02-12 04:01:58 +01:00
|
|
|
_cygtls *cygtls;
|
2002-07-04 16:17:30 +02:00
|
|
|
HANDLE cancel_event;
|
2002-06-05 14:39:55 +02:00
|
|
|
pthread_t joiner;
|
2001-04-12 06:04:53 +02:00
|
|
|
|
2005-08-05 18:14:41 +02:00
|
|
|
virtual bool create (void *(*)(void *), pthread_attr *, void *);
|
2002-09-16 12:53:29 +02:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
pthread ();
|
|
|
|
virtual ~pthread ();
|
2001-03-21 03:17:58 +01:00
|
|
|
|
2004-04-10 02:53:25 +02:00
|
|
|
static void init_mainthread ();
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object(pthread_t const *);
|
2002-09-29 04:19:35 +02:00
|
|
|
static void atforkprepare();
|
|
|
|
static void atforkparent();
|
|
|
|
static void atforkchild();
|
2001-03-21 03:17:58 +01:00
|
|
|
|
2002-09-29 04:19:35 +02: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 05:59:58 +02:00
|
|
|
void *(*start_routine) (void *), void *arg);
|
2002-09-29 04:19:35 +02: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 05:59:58 +02:00
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
virtual void exit (void *value_ptr) __attribute__ ((noreturn));
|
2002-07-04 16:17:30 +02:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
virtual int cancel ();
|
2002-09-30 04:51:22 +02:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
virtual void testcancel ();
|
2011-05-01 19:42:41 +02:00
|
|
|
static HANDLE get_cancel_event ();
|
2011-05-04 08:16:59 +02:00
|
|
|
static void static_cancel_self () __attribute__ ((noreturn));
|
2002-07-04 16:17:30 +02:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
virtual int setcancelstate (int state, int *oldstate);
|
|
|
|
virtual int setcanceltype (int type, int *oldtype);
|
2002-07-04 16:17:30 +02:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
virtual void push_cleanup_handler (__pthread_cleanup_handler *handler);
|
|
|
|
virtual void pop_cleanup_handler (int const execute);
|
2002-06-10 03:10:45 +02:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
static pthread* self ();
|
2003-12-14 08:09:22 +01:00
|
|
|
static DWORD WINAPI thread_init_wrapper (void *);
|
2002-06-10 03:10:45 +02:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
virtual unsigned long getsequence_np();
|
2002-09-16 12:53:29 +02:00
|
|
|
|
2003-04-17 21:57:01 +02:00
|
|
|
static int equal (pthread_t t1, pthread_t t2)
|
|
|
|
{
|
|
|
|
return t1 == t2;
|
|
|
|
}
|
|
|
|
|
2003-06-24 22:14:01 +02:00
|
|
|
/* List support calls */
|
|
|
|
class pthread *next;
|
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
threads.fixup_after_fork ();
|
2003-06-24 22:14:01 +02:00
|
|
|
threads.for_each (&pthread::_fixup_after_fork);
|
|
|
|
}
|
|
|
|
|
2003-10-31 21:42:56 +01:00
|
|
|
static void suspend_all_except_self ()
|
|
|
|
{
|
|
|
|
threads.for_each (&pthread::suspend_except_self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resume_all ()
|
|
|
|
{
|
|
|
|
threads.for_each (&pthread::resume);
|
|
|
|
}
|
|
|
|
|
2001-03-21 03:17:58 +01:00
|
|
|
private:
|
2003-06-24 22:14:01 +02:00
|
|
|
static List<pthread> threads;
|
2002-09-29 04:19:35 +02:00
|
|
|
DWORD thread_id;
|
|
|
|
__pthread_cleanup_handler *cleanup_stack;
|
|
|
|
pthread_mutex mutex;
|
2011-08-24 17:18:17 +02:00
|
|
|
sigset_t parent_sigmask;
|
2002-09-29 04:19:35 +02:00
|
|
|
|
2003-10-31 21:42:56 +01:00
|
|
|
void suspend_except_self ();
|
|
|
|
void resume ();
|
|
|
|
|
2003-06-24 22:14:01 +02:00
|
|
|
void _fixup_after_fork ();
|
|
|
|
|
2005-07-05 05:16:46 +02:00
|
|
|
void pop_all_cleanup_handlers ();
|
2002-09-29 04:19:35 +02:00
|
|
|
void precreate (pthread_attr *);
|
|
|
|
void postcreate ();
|
2003-12-12 05:15:32 +01:00
|
|
|
bool create_cancel_event ();
|
2013-03-31 14:35:44 +02:00
|
|
|
void set_tls_self_pointer ();
|
2011-05-04 08:16:59 +02:00
|
|
|
void cancel_self () __attribute__ ((noreturn));
|
2003-03-27 20:52:20 +01:00
|
|
|
DWORD get_thread_id ();
|
2002-09-16 12:53:29 +02:00
|
|
|
};
|
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
class pthread_null : public pthread
|
2002-09-16 12:53:29 +02:00
|
|
|
{
|
2002-09-16 18:09:54 +02:00
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static pthread *get_null_pthread();
|
|
|
|
~pthread_null();
|
2002-09-29 04:19:35 +02:00
|
|
|
|
|
|
|
/* From pthread These should never get called
|
|
|
|
* as the ojbect is not verifyable
|
|
|
|
*/
|
2005-08-05 18:14:41 +02:00
|
|
|
bool create (void *(*)(void *), pthread_attr *, void *);
|
2003-11-28 21:55:59 +01:00
|
|
|
void exit (void *value_ptr) __attribute__ ((noreturn));
|
2002-09-29 04:19:35 +02:00
|
|
|
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 12:53:29 +02:00
|
|
|
|
|
|
|
private:
|
2003-03-27 20:52:20 +01:00
|
|
|
pthread_null ();
|
|
|
|
static pthread_null _instance;
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_condattr: public verifyable_object
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object(pthread_condattr_t const *);
|
2000-10-15 03:37:07 +02:00
|
|
|
int shared;
|
2011-07-21 11:39:22 +02:00
|
|
|
clockid_t clock_id;
|
2001-03-21 03:17:58 +01:00
|
|
|
|
2001-06-26 16:47:48 +02:00
|
|
|
pthread_condattr ();
|
|
|
|
~pthread_condattr ();
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_cond: public verifyable_object
|
2001-03-17 02:14:58 +01:00
|
|
|
{
|
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object (pthread_cond_t const *);
|
2010-02-22 21:36:04 +01:00
|
|
|
static bool is_initializer (pthread_cond_t const *);
|
|
|
|
static bool is_initializer_or_object (pthread_cond_t const *);
|
|
|
|
static bool is_initializer_or_bad_object (pthread_cond_t const *);
|
2003-03-27 20:52:20 +01:00
|
|
|
static void init_mutex ();
|
2003-01-09 21:40:44 +01:00
|
|
|
static int init (pthread_cond_t *, const pthread_condattr_t *);
|
|
|
|
|
2001-03-17 02:14:58 +01:00
|
|
|
int shared;
|
2011-07-21 11:39:22 +02:00
|
|
|
clockid_t clock_id;
|
2003-03-18 20:49:38 +01:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
LONG waiting;
|
|
|
|
LONG pending;
|
2003-03-27 20:52:20 +01:00
|
|
|
HANDLE sem_wait;
|
2003-03-18 20:49:38 +01:00
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
pthread_mutex mtx_in;
|
|
|
|
pthread_mutex mtx_out;
|
2003-03-18 20:49:38 +01:00
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
pthread_mutex_t mtx_cond;
|
2003-03-18 20:49:38 +01:00
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
void unblock (const bool all);
|
2011-08-03 18:40:48 +02:00
|
|
|
int wait (pthread_mutex_t mutex, PLARGE_INTEGER timeout = NULL);
|
2001-03-21 03:17:58 +01:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
pthread_cond (pthread_condattr *);
|
|
|
|
~pthread_cond ();
|
2003-01-09 21:40:44 +01:00
|
|
|
|
2003-03-23 11:52:02 +01:00
|
|
|
class pthread_cond * next;
|
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
conds.fixup_after_fork ();
|
2003-03-27 20:52:20 +01:00
|
|
|
conds.for_each (&pthread_cond::_fixup_after_fork);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
|
|
|
|
2003-01-09 21:40:44 +01:00
|
|
|
private:
|
2003-03-27 20:52:20 +01:00
|
|
|
void _fixup_after_fork ();
|
|
|
|
|
2003-03-23 11:52:02 +01:00
|
|
|
static List<pthread_cond> conds;
|
2003-10-24 21:34:47 +02:00
|
|
|
static fast_mutex cond_initialization_lock;
|
2001-04-12 06:04:53 +02:00
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_rwlockattr: public verifyable_object
|
* 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-18 21:01:07 +01:00
|
|
|
{
|
|
|
|
public:
|
2003-03-27 20:52:20 +01: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-18 21:01:07 +01:00
|
|
|
int shared;
|
|
|
|
|
|
|
|
pthread_rwlockattr ();
|
|
|
|
~pthread_rwlockattr ();
|
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
class pthread_rwlock: public verifyable_object
|
* 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-18 21:01:07 +01:00
|
|
|
{
|
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object (pthread_rwlock_t const *);
|
2010-02-22 21:36:04 +01:00
|
|
|
static bool is_initializer (pthread_rwlock_t const *);
|
|
|
|
static bool is_initializer_or_object (pthread_rwlock_t const *);
|
|
|
|
static bool is_initializer_or_bad_object (pthread_rwlock_t const *);
|
2003-03-27 20:52:20 +01:00
|
|
|
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-18 21:01:07 +01:00
|
|
|
static int init (pthread_rwlock_t *, const pthread_rwlockattr_t *);
|
|
|
|
|
|
|
|
int shared;
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
uint32_t waiting_readers;
|
|
|
|
uint32_t 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-18 21:01:07 +01:00
|
|
|
pthread_t writer;
|
|
|
|
struct RWLOCK_READER
|
|
|
|
{
|
|
|
|
struct RWLOCK_READER *next;
|
|
|
|
pthread_t thread;
|
2013-04-23 11:44:36 +02:00
|
|
|
uint32_t n;
|
2013-01-07 17:01:10 +01:00
|
|
|
RWLOCK_READER (): next (NULL), thread (pthread::self ()), n (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-18 21:01:07 +01:00
|
|
|
} *readers;
|
2003-10-24 21:34:47 +02:00
|
|
|
fast_mutex readers_mx;
|
* 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-18 21:01:07 +01:00
|
|
|
|
2003-03-27 20:52:20 +01: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-18 21:01:07 +01:00
|
|
|
|
2003-03-27 20:52:20 +01: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-18 21:01:07 +01:00
|
|
|
|
2003-03-27 20:52:20 +01: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-18 21:01:07 +01:00
|
|
|
|
|
|
|
pthread_mutex mtx;
|
2003-03-27 20:52:20 +01: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-18 21:01:07 +01:00
|
|
|
|
|
|
|
pthread_rwlock (pthread_rwlockattr *);
|
|
|
|
~pthread_rwlock ();
|
|
|
|
|
2003-03-23 11:52:02 +01:00
|
|
|
class pthread_rwlock * next;
|
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
rwlocks.fixup_after_fork ();
|
2003-03-27 20:52:20 +01:00
|
|
|
rwlocks.for_each (&pthread_rwlock::_fixup_after_fork);
|
2003-03-23 11:52:02 +01: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-18 21:01:07 +01:00
|
|
|
private:
|
2003-03-23 11:52:02 +01:00
|
|
|
static List<pthread_rwlock> rwlocks;
|
|
|
|
|
2013-01-07 17:01:10 +01:00
|
|
|
RWLOCK_READER *add_reader ();
|
2003-03-27 20:52:20 +01:00
|
|
|
void remove_reader (struct RWLOCK_READER *rd);
|
2013-01-07 20:34:44 +01:00
|
|
|
struct RWLOCK_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-18 21:01:07 +01:00
|
|
|
|
2003-04-15 22:14:12 +02:00
|
|
|
void release ()
|
|
|
|
{
|
|
|
|
if (waiting_writers)
|
|
|
|
{
|
2003-12-02 02:36:08 +01:00
|
|
|
if (!readers)
|
|
|
|
cond_writers.unblock (false);
|
2003-04-15 22:14:12 +02:00
|
|
|
}
|
|
|
|
else if (waiting_readers)
|
|
|
|
cond_readers.unblock (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-27 20:52:20 +01: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-18 21:01:07 +01:00
|
|
|
|
2003-03-27 20:52:20 +01:00
|
|
|
void _fixup_after_fork ();
|
|
|
|
|
2003-10-24 21:34:47 +02:00
|
|
|
static fast_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-18 21:01:07 +01:00
|
|
|
};
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
class pthread_once
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
int state;
|
2001-03-17 02:14:58 +01:00
|
|
|
};
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-03-21 03:17:58 +01:00
|
|
|
/* shouldn't be here */
|
2003-11-28 21:55:59 +01:00
|
|
|
class semaphore: public verifyable_object
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-03-21 03:17:58 +01:00
|
|
|
public:
|
2003-03-27 20:52:20 +01:00
|
|
|
static bool is_good_object(sem_t const *);
|
2002-09-21 05:59:58 +02:00
|
|
|
/* API calls */
|
2007-02-20 16:48:04 +01:00
|
|
|
static int init (sem_t *sem, int pshared, unsigned int value);
|
|
|
|
static int destroy (sem_t *sem);
|
|
|
|
static sem_t *open (unsigned long long hash, LUID luid, int fd, int oflag,
|
|
|
|
mode_t mode, unsigned int value, bool &wasopen);
|
|
|
|
static int close (sem_t *sem);
|
|
|
|
static int wait (sem_t *sem);
|
|
|
|
static int post (sem_t *sem);
|
|
|
|
static int getvalue (sem_t *sem, int *sval);
|
|
|
|
static int trywait (sem_t *sem);
|
|
|
|
static int timedwait (sem_t *sem, const struct timespec *abstime);
|
|
|
|
|
|
|
|
static int getinternal (sem_t *sem, int *sfd, unsigned long long *shash,
|
|
|
|
LUID *sluid, unsigned int *sval);
|
2002-09-30 04:51:22 +02:00
|
|
|
|
2001-03-21 03:17:58 +01:00
|
|
|
HANDLE win32_obj_id;
|
|
|
|
int shared;
|
2013-04-23 11:44:36 +02:00
|
|
|
LONG currentvalue;
|
2013-07-23 16:15:20 +02:00
|
|
|
LONG startvalue;
|
2007-02-20 16:48:04 +01:00
|
|
|
int fd;
|
|
|
|
unsigned long long hash;
|
|
|
|
LUID luid;
|
|
|
|
sem_t *sem;
|
2001-03-21 03:17:58 +01:00
|
|
|
|
2002-09-29 04:19:35 +02:00
|
|
|
semaphore (int, unsigned int);
|
2007-02-20 16:48:04 +01:00
|
|
|
semaphore (unsigned long long, LUID, int, sem_t *, int, mode_t, unsigned int);
|
2002-09-29 04:19:35 +02:00
|
|
|
~semaphore ();
|
2003-03-23 11:52:02 +01:00
|
|
|
|
|
|
|
class semaphore * next;
|
2013-07-23 16:15:20 +02:00
|
|
|
static void fixup_before_fork ()
|
|
|
|
{
|
|
|
|
semaphores.for_each (&semaphore::_fixup_before_fork);
|
|
|
|
}
|
2003-03-23 11:52:02 +01:00
|
|
|
static void fixup_after_fork ()
|
|
|
|
{
|
2003-10-24 21:34:47 +02:00
|
|
|
semaphores.fixup_after_fork ();
|
2003-03-27 20:52:20 +01:00
|
|
|
semaphores.for_each (&semaphore::_fixup_after_fork);
|
2003-03-23 11:52:02 +01:00
|
|
|
}
|
2007-02-20 16:48:04 +01:00
|
|
|
static void terminate ()
|
|
|
|
{
|
2011-03-29 09:49:25 +02:00
|
|
|
save_errno save;
|
2007-02-20 16:48:04 +01:00
|
|
|
semaphores.for_each (&semaphore::_terminate);
|
|
|
|
}
|
2003-03-23 11:52:02 +01:00
|
|
|
|
|
|
|
private:
|
2004-02-24 12:33:15 +01:00
|
|
|
int _wait ();
|
2003-03-27 20:52:20 +01:00
|
|
|
void _post ();
|
2003-10-27 12:48:29 +01:00
|
|
|
int _getvalue (int *sval);
|
2003-03-27 20:52:20 +01:00
|
|
|
int _trywait ();
|
2003-10-27 12:48:29 +01:00
|
|
|
int _timedwait (const struct timespec *abstime);
|
2003-03-27 20:52:20 +01:00
|
|
|
|
2013-07-23 16:15:20 +02:00
|
|
|
void _fixup_before_fork ();
|
2003-03-27 20:52:20 +01:00
|
|
|
void _fixup_after_fork ();
|
2007-02-20 16:48:04 +01:00
|
|
|
void _terminate ();
|
2003-03-27 20:52:20 +01:00
|
|
|
|
2003-03-23 11:52:02 +01:00
|
|
|
static List<semaphore> semaphores;
|
2001-03-21 03:17:58 +01:00
|
|
|
};
|
|
|
|
|
2001-04-13 17:28:20 +02:00
|
|
|
class callback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void (*cb)(void);
|
|
|
|
class callback * next;
|
|
|
|
};
|
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
struct MTinterface
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-10-15 03:37:07 +02:00
|
|
|
// General
|
2001-04-12 06:04:53 +02:00
|
|
|
int concurrency;
|
2012-10-23 12:17:29 +02:00
|
|
|
LONG threadcount;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-04-13 17:28:20 +02:00
|
|
|
callback *pthread_prepare;
|
|
|
|
callback *pthread_child;
|
|
|
|
callback *pthread_parent;
|
2001-04-12 06:04:53 +02:00
|
|
|
|
2003-05-15 21:42:51 +02:00
|
|
|
void Init ();
|
2005-07-05 05:16:46 +02:00
|
|
|
void fixup_before_fork ();
|
|
|
|
void fixup_after_fork ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-12-23 17:26:31 +01:00
|
|
|
#if 0 // avoid initialization since zero is implied and
|
2002-11-24 14:54:14 +01:00
|
|
|
MTinterface () :
|
2003-11-28 21:55:59 +01:00
|
|
|
concurrency (0), threadcount (0),
|
2003-12-23 17:26:31 +01:00
|
|
|
pthread_prepare (NULL), pthread_child (NULL), pthread_parent (NULL)
|
2002-09-29 04:19:35 +02:00
|
|
|
{
|
|
|
|
}
|
2003-11-28 21:55:59 +01:00
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2002-11-24 14:54:14 +01:00
|
|
|
#define MT_INTERFACE user_data->threadinterface
|