2000-02-17 20:38:33 +01:00
|
|
|
/* pthread.cc: posix pthread interface for Cygwin
|
|
|
|
|
2001-03-18 22:11:25 +01:00
|
|
|
Originally written by Marco Fuykschot <marco@ddi.nl>
|
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. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "thread.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-03-21 03:17:58 +01:00
|
|
|
extern "C"
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-03-21 03:17:58 +01:00
|
|
|
/* ThreadCreation */
|
2001-04-09 02:44:25 +02:00
|
|
|
int
|
2008-10-08 01:28:30 +02:00
|
|
|
pthread_create (pthread_t *thread, const pthread_attr_t *attr,
|
2001-04-12 06:04:53 +02:00
|
|
|
void *(*start_routine) (void *), void *arg)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return pthread::create (thread, attr, start_routine, arg);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
int
|
|
|
|
pthread_once (pthread_once_t * once_control, void (*init_routine) (void))
|
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return pthread::once (once_control, init_routine);
|
2001-04-12 06:04:53 +02:00
|
|
|
}
|
|
|
|
|
2001-04-13 17:28:20 +02:00
|
|
|
int
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_atfork (void (*prepare)(void), void (*parent)(void), void (*child)(void))
|
2001-04-13 17:28:20 +02:00
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
return pthread::atfork (prepare, parent, child);
|
2001-04-13 17:28:20 +02:00
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Thread Exit */
|
2001-04-12 06:04:53 +02:00
|
|
|
void
|
|
|
|
pthread_exit (void *value_ptr)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2013-01-16 20:20:59 +01:00
|
|
|
pthread::self ()->exit (value_ptr);
|
|
|
|
__builtin_unreachable (); /* FIXME: don't know why this is necessary */
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
int
|
|
|
|
pthread_detach (pthread_t thread)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return pthread::detach (&thread);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
|
|
|
|
/* This isn't a posix call... should we keep it? */
|
|
|
|
int
|
|
|
|
pthread_suspend (pthread_t thread)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return pthread::suspend (&thread);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
/* same */
|
|
|
|
int
|
|
|
|
pthread_continue (pthread_t thread)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return pthread::resume (&thread);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
unsigned long
|
|
|
|
pthread_getsequence_np (pthread_t * thread)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2003-03-27 20:52:20 +01:00
|
|
|
if (!pthread::is_good_object (thread))
|
2002-09-16 12:53:29 +02:00
|
|
|
return EINVAL;
|
2002-09-22 05:38:57 +02:00
|
|
|
return (*thread)->getsequence_np ();
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* ID */
|
|
|
|
|
2001-04-09 02:44:25 +02:00
|
|
|
pthread_t pthread_self ()
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
return pthread::self ();
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Mutexes */
|
2001-04-09 02:44:25 +02:00
|
|
|
int
|
2001-04-12 06:04:53 +02:00
|
|
|
pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2010-02-12 21:07:13 +01:00
|
|
|
return pthread_mutex::init (mutex, attr, NULL);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2011-03-29 12:32:40 +02:00
|
|
|
/* Spinlocks */
|
|
|
|
int
|
|
|
|
pthread_spin_init (pthread_spinlock_t *spinlock, int pshared)
|
|
|
|
{
|
|
|
|
return pthread_spinlock::init (spinlock, pshared);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-17 02:14:58 +01:00
|
|
|
/* Synchronisation */
|
2001-04-09 02:44:25 +02:00
|
|
|
int
|
2001-04-12 06:04:53 +02:00
|
|
|
pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2003-01-09 21:40:44 +01:00
|
|
|
return pthread_cond::init (cond, attr);
|
2001-04-09 02:44:25 +02: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
|
|
|
/* RW Locks */
|
|
|
|
int
|
|
|
|
pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
|
|
|
|
{
|
|
|
|
return pthread_rwlock::init (rwlock, attr);
|
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
/* Cancelability */
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_cancel (pthread_t thread)
|
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return pthread::cancel (thread);
|
2001-04-12 06:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_setcancelstate (int state, int *oldstate)
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
return pthread::self ()->setcancelstate (state, oldstate);
|
2001-04-12 06:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pthread_setcanceltype (int type, int *oldtype)
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
return pthread::self ()->setcanceltype (type, oldtype);
|
2001-04-12 06:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-05 05:16:46 +02:00
|
|
|
pthread_testcancel ()
|
2001-04-12 06:04:53 +02:00
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread::self ()->testcancel ();
|
2001-04-12 06:04:53 +02:00
|
|
|
}
|
|
|
|
|
2002-06-10 03:10:45 +02:00
|
|
|
void
|
|
|
|
_pthread_cleanup_push (__pthread_cleanup_handler *handler)
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread::self ()->push_cleanup_handler (handler);
|
2002-06-10 03:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_pthread_cleanup_pop (int execute)
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread::self ()->pop_cleanup_handler (execute);
|
2002-06-10 03:10:45 +02:00
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Semaphores */
|
2001-04-12 06:04:53 +02:00
|
|
|
int
|
|
|
|
sem_init (sem_t * sem, int pshared, unsigned int value)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return semaphore::init (sem, pshared, value);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
int
|
|
|
|
sem_destroy (sem_t * sem)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return semaphore::destroy (sem);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
int
|
|
|
|
sem_wait (sem_t * sem)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return semaphore::wait (sem);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
int
|
|
|
|
sem_trywait (sem_t * sem)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return semaphore::trywait (sem);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
|
|
|
|
2003-10-27 12:48:29 +01:00
|
|
|
int
|
|
|
|
sem_timedwait (sem_t * sem, const struct timespec *abstime)
|
|
|
|
{
|
|
|
|
return semaphore::timedwait (sem, abstime);
|
|
|
|
}
|
|
|
|
|
2001-04-12 06:04:53 +02:00
|
|
|
int
|
2013-09-25 16:44:45 +02:00
|
|
|
sem_post (sem_t *sem)
|
2001-04-09 02:44:25 +02:00
|
|
|
{
|
2002-09-21 05:59:58 +02:00
|
|
|
return semaphore::post (sem);
|
2001-04-09 02:44:25 +02:00
|
|
|
}
|
2001-04-12 06:04:53 +02:00
|
|
|
|
2003-10-27 12:48:29 +01:00
|
|
|
int
|
|
|
|
sem_getvalue (sem_t * sem, int *sval)
|
|
|
|
{
|
|
|
|
return semaphore::getvalue (sem, sval);
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|