MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / pthread_mutex_timedlock

Function pthread_mutex_timedlock

include/hamlib/winpthreads.h:945–979  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

943}
944
945static int pthread_mutex_timedlock(pthread_mutex_t *m, struct timespec *ts)
946{
947 unsigned long long t, ct;
948
949 struct _pthread_crit_t
950 {
951 void *debug;
952 LONG count;
953 LONG r_count;
954 HANDLE owner;
955 HANDLE sem;
956 ULONG_PTR spin;
957 };
958
959 /* Try to lock it without waiting */
960 if (!pthread_mutex_trylock(m)) return 0;
961
962 ct = (DWORD)_pthread_time_in_ms();
963 t = (DWORD)_pthread_time_in_ms_from_timespec(ts);
964
965 while (1)
966 {
967 /* Have we waited long enough? */
968 if (ct > t) return ETIMEDOUT;
969
970 /* Wait on semaphore within critical section */
971 WaitForSingleObject(((struct _pthread_crit_t *)m)->sem, (DWORD)(t - ct));
972
973 /* Try to grab lock */
974 if (!pthread_mutex_trylock(m)) return 0;
975
976 /* Get current time */
977 ct = _pthread_time_in_ms();
978 }
979}
980
981#define _PTHREAD_BARRIER_FLAG (1<<30)
982

Callers

nothing calls this directly

Calls 3

pthread_mutex_trylockFunction · 0.85
_pthread_time_in_msFunction · 0.85

Tested by

no test coverage detected