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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
//// Copyright 2002, Jonathan Bachrach. See file TERMS.
#include "grt.h"
#if defined(HAVE_POSIX_THREAD)
P YtimeSlockYPlock_create (P name) {
pthread_mutex_t *mutex = (pthread_mutex_t *)allocate(sizeof(pthread_mutex_t));
pthread_mutex_init(mutex, NULL);
return (P)mutex;
}
P YtimeSlockYPlock_lock (P handle) {
return (P)(PINT)pthread_mutex_lock((pthread_mutex_t *)handle);
}
P YtimeSlockYPlock_try_lock (P handle) {
return (P)(PINT)pthread_mutex_trylock((pthread_mutex_t *)handle);
}
P YtimeSlockYPlock_unlock (P handle) {
return (P)(PINT)pthread_mutex_unlock((pthread_mutex_t *)handle);
}
P YtimeSlockYPlock_destroy (P handle) {
return (P)(PINT)pthread_mutex_destroy((pthread_mutex_t *)handle);
}
#elif defined(MSVC_THREAD)
#undef PINT
#include <windows.h>
#undef PINT
#define PINT long
P YtimeSlockYPlock_create (P name) {
CRITICAL_SECTION* cs = (CRITICAL_SECTION*)allocate(sizeof(CRITICAL_SECTION));
InitializeCriticalSection(cs);
return (P)cs;
}
P YtimeSlockYPlock_lock (P handle) {
EnterCriticalSection((CRITICAL_SECTION*)handle);
return YPtrue;
}
P YtimeSlockYPlock_try_lock (P handle) {
// Not yet implemented
return (P)0;
}
P YtimeSlockYPlock_unlock (P handle) {
LeaveCriticalSection((CRITICAL_SECTION*)handle);
return YPtrue;
}
P YtimeSlockYPlock_destroy (P handle) {
DeleteCriticalSection((CRITICAL_SECTION*)handle);
return YPtrue;
}
#else
P YtimeSlockYPlock_create (P name) { return PNUL; }
P YtimeSlockYPlock_lock (P handle) { return PNUL; }
P YtimeSlockYPlock_try_lock (P handle) { return PNUL; }
P YtimeSlockYPlock_unlock (P handle) { return PNUL; }
P YtimeSlockYPlock_destroy (P handle) { return PNUL; }
#endif
|