aboutsummaryrefslogtreecommitdiffstats
path: root/src/libposixplz/pthread_mutex_tailock.c
blob: 736921c2e76b8b7ab5aea5f9791935d1f20376ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ISC license. */

#include <errno.h>
#include <time.h>
#include <pthread.h>

#include <skalibs/sysdeps.h>
#include <skalibs/tai.h>
#include <skalibs/pthread.h>

#ifdef SKALIBS_HASPTHREADMUTEXTIMEDLOCK

int pthread_mutex_tailock (pthread_mutex_t *mtx, tain const *deadline, tain *stamp)
{
  int e ;
  struct timespec ts ;
  tain tto ;
  if (!stamp) return pthread_mutex_lock(mtx) ;
  tain_sub(&tto, deadline, stamp) ;
  if (!timespec_from_tain_relative(&ts, &tto)) return errno ;
#ifdef SKALIBS_HASPTHREADMUTEXCLOCKLOCK
  if (&tain_now != &tain_wallclock_read)
    e = pthread_mutex_clocklock(mtx, CLOCK_MONOTONIC, &ts) ;
  else
#else
    e = pthread_mutex_timedlock(mtx, &ts) ;
#endif
  tain_now(stamp) ;
  return e ;
}

#else

int pthread_mutex_tailock (pthread_mutex_t *mtx, tain const *deadline, tain *stamp)
{
  (void)deadline ;
  (void)stamp ;
  return pthread_mutex_lock(mtx) ;
}

#endif