cygwin: Implement pthread_mutex_timedlock
- pthread_mutex::lock now takes a PLARGE_INTEGER timeout pointer and uses that in the call to cygwait. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
68217c3178
commit
37738448a0
|
@ -1068,6 +1068,7 @@ pthread_mutex_getprioceiling SIGFE
|
|||
pthread_mutex_init SIGFE
|
||||
pthread_mutex_lock SIGFE
|
||||
pthread_mutex_setprioceiling SIGFE
|
||||
pthread_mutex_timedlock SIGFE
|
||||
pthread_mutex_trylock SIGFE
|
||||
pthread_mutex_unlock SIGFE
|
||||
pthread_mutexattr_destroy SIGFE
|
||||
|
|
|
@ -479,12 +479,13 @@ details. */
|
|||
312: Export strverscmp, versionsort.
|
||||
313: Export fls, flsl, flsll.
|
||||
314: Export explicit_bzero.
|
||||
315: Export pthread_mutex_timedlock.
|
||||
|
||||
Note that we forgot to bump the api for ualarm, strtoll, strtoull,
|
||||
sigaltstack, sethostname. */
|
||||
|
||||
#define CYGWIN_VERSION_API_MAJOR 0
|
||||
#define CYGWIN_VERSION_API_MINOR 314
|
||||
#define CYGWIN_VERSION_API_MINOR 315
|
||||
|
||||
/* There is also a compatibity version number associated with the shared memory
|
||||
regions. It is incremented when incompatible changes are made to the shared
|
||||
|
|
|
@ -163,6 +163,7 @@ int pthread_mutex_getprioceiling (const pthread_mutex_t *, int *);
|
|||
int pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
|
||||
int pthread_mutex_lock (pthread_mutex_t *);
|
||||
int pthread_mutex_setprioceiling (pthread_mutex_t *, int, int *);
|
||||
int pthread_mutex_timedlock (pthread_mutex_t *, const struct timespec *);
|
||||
int pthread_mutex_trylock (pthread_mutex_t *);
|
||||
int pthread_mutex_unlock (pthread_mutex_t *);
|
||||
int pthread_mutexattr_destroy (pthread_mutexattr_t *);
|
||||
|
|
|
@ -1765,7 +1765,7 @@ pthread_mutex::~pthread_mutex ()
|
|||
}
|
||||
|
||||
int
|
||||
pthread_mutex::lock ()
|
||||
pthread_mutex::lock (PLARGE_INTEGER timeout)
|
||||
{
|
||||
pthread_t self = ::pthread_self ();
|
||||
int result = 0;
|
||||
|
@ -1775,7 +1775,7 @@ pthread_mutex::lock ()
|
|||
else if (type == PTHREAD_MUTEX_NORMAL /* potentially causes deadlock */
|
||||
|| !pthread::equal (owner, self))
|
||||
{
|
||||
cygwait (win32_obj_id, cw_infinite, cw_sig | cw_sig_restart);
|
||||
cygwait (win32_obj_id, timeout, cw_sig | cw_sig_restart);
|
||||
set_owner (self);
|
||||
}
|
||||
else
|
||||
|
@ -3284,6 +3284,34 @@ pthread_mutex_lock (pthread_mutex_t *mutex)
|
|||
return (*mutex)->lock ();
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime)
|
||||
{
|
||||
LARGE_INTEGER timeout;
|
||||
|
||||
if (pthread_mutex::is_initializer (mutex))
|
||||
pthread_mutex::init (mutex, NULL, *mutex);
|
||||
if (!pthread_mutex::is_good_object (mutex))
|
||||
return EINVAL;
|
||||
|
||||
/* According to SUSv3, abstime need not be checked for validity,
|
||||
if the mutex can be locked immediately. */
|
||||
if (!(*mutex)->trylock ())
|
||||
return 0;
|
||||
|
||||
__try
|
||||
{
|
||||
int err = pthread_convert_abstime (CLOCK_REALTIME, abstime, &timeout);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return (*mutex)->lock (&timeout);
|
||||
}
|
||||
__except (NO_ERROR) {}
|
||||
__endtry
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pthread_mutex_trylock (pthread_mutex_t *mutex)
|
||||
{
|
||||
|
|
|
@ -267,7 +267,7 @@ public:
|
|||
static bool is_initializer_or_object (pthread_mutex_t const *);
|
||||
static bool is_initializer_or_bad_object (pthread_mutex_t const *);
|
||||
|
||||
int lock ();
|
||||
int lock (PLARGE_INTEGER timeout = NULL);
|
||||
int trylock ();
|
||||
int unlock ();
|
||||
int destroy ();
|
||||
|
|
Loading…
Reference in New Issue