* 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.
This commit is contained in:
Thomas Pfaff
2003-03-18 20:01:07 +00:00
parent 5df1410028
commit 00d296a3f9
7 changed files with 761 additions and 3 deletions

View File

@@ -163,6 +163,8 @@ private:
#define PTHREAD_CONDATTR_MAGIC PTHREAD_MAGIC+6
#define SEM_MAGIC PTHREAD_MAGIC+7
#define PTHREAD_ONCE_MAGIC PTHREAD_MAGIC+8
#define PTHREAD_RWLOCK_MAGIC PTHREAD_MAGIC+9
#define PTHREAD_RWLOCKATTR_MAGIC PTHREAD_MAGIC+10
#define MUTEX_OWNER_ANONYMOUS ((pthread_t) -1)
@@ -517,6 +519,67 @@ private:
static nativeMutex condInitializationLock;
};
class pthread_rwlockattr:public verifyable_object
{
public:
static bool isGoodObject(pthread_rwlockattr_t const *);
int shared;
pthread_rwlockattr ();
~pthread_rwlockattr ();
};
class pthread_rwlock:public verifyable_object
{
public:
static bool isGoodObject (pthread_rwlock_t const *);
static bool isGoodInitializer (pthread_rwlock_t const *);
static bool isGoodInitializerOrObject (pthread_rwlock_t const *);
static bool isGoodInitializerOrBadObject (pthread_rwlock_t const *);
static void initMutex ();
static int init (pthread_rwlock_t *, const pthread_rwlockattr_t *);
int shared;
unsigned long waitingReaders;
unsigned long waitingWriters;
pthread_t writer;
struct RWLOCK_READER
{
struct RWLOCK_READER *next;
pthread_t thread;
} *readers;
int RdLock ();
int TryRdLock ();
int WrLock ();
int TryWrLock ();
int UnLock ();
pthread_mutex mtx;
pthread_cond condReaders;
pthread_cond condWriters;
class pthread_rwlock * next;
void fixup_after_fork ();
pthread_rwlock (pthread_rwlockattr *);
~pthread_rwlock ();
private:
void addReader (struct RWLOCK_READER *rd);
void removeReader (struct RWLOCK_READER *rd);
struct RWLOCK_READER *lookupReader (pthread_t thread);
static void RdLockCleanup (void *arg);
static void WrLockCleanup (void *arg);
static nativeMutex rwlockInitializationLock;
};
class pthread_once
{
public:
@@ -574,6 +637,7 @@ public:
// lists of pthread objects. USE THREADSAFE INSERTS AND DELETES.
class pthread_mutex * mutexs;
class pthread_cond * conds;
class pthread_rwlock * rwlocks;
class semaphore * semaphores;
pthread_key reent_key;
@@ -586,7 +650,7 @@ public:
MTinterface () :
concurrency (0), threadcount (1),
pthread_prepare (NULL), pthread_child (NULL), pthread_parent (NULL),
mutexs (NULL), conds (NULL), semaphores (NULL),
mutexs (NULL), conds (NULL), rwlocks (NULL), semaphores (NULL),
reent_key (NULL), thread_self_key (NULL)
{
}
@@ -632,6 +696,19 @@ int __pthread_condattr_getpshared (const pthread_condattr_t * attr,
int *pshared);
int __pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared);
/* RW locks */
int __pthread_rwlock_destroy (pthread_rwlock_t *rwlock);
int __pthread_rwlock_rdlock (pthread_rwlock_t *rwlock);
int __pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock);
int __pthread_rwlock_wrlock (pthread_rwlock_t *rwlock);
int __pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock);
int __pthread_rwlock_unlock (pthread_rwlock_t *rwlock);
int __pthread_rwlockattr_init (pthread_rwlockattr_t *rwlockattr);
int __pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *attr,
int *pshared);
int __pthread_rwlockattr_setpshared (pthread_rwlockattr_t *attr, int pshared);
int __pthread_rwlockattr_destroy (pthread_rwlockattr_t *rwlockattr);
/* Thread signal */
int __pthread_kill (pthread_t thread, int sig);
int __pthread_sigmask (int operation, const sigset_t * set,