-
Notifications
You must be signed in to change notification settings - Fork 0
/
cexplock.c
62 lines (47 loc) · 1.15 KB
/
cexplock.c
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
#define _XOPEN_SOURCE 500
#include "cexplock.h"
#ifdef USE_EPICS_OSI
#elif defined(HAVE_PTHREADS)
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
pthread_mutexattr_t cexpMutexAttributes;
int
cexpLockCreate(CexpLock *l)
{
int rval;
if ( ! (*l = malloc(sizeof(**l))) )
return -1;
if ( (rval = pthread_mutex_init(*l, &cexpMutexAttributes)) )
free(*l);
return rval;
}
int
cexpLockDestroy(CexpLock l)
{
int rval;
rval = pthread_mutex_destroy(l);
free(l);
return rval;
}
int
cexpLockingInitialize()
{
int rval;
memset(&cexpMutexAttributes, 0, sizeof(cexpMutexAttributes));
if ( (rval = pthread_mutexattr_init(&cexpMutexAttributes)) ) {
fprintf(stderr,"pthread_mutexattr_init failed: %s\n", strerror(rval));
return rval;
}
if ( (rval = pthread_mutexattr_setprotocol(&cexpMutexAttributes, PTHREAD_PRIO_INHERIT)) ) {
fprintf(stderr,"pthread_mutexattr_setprotocol failed: %s\n", strerror(rval));
return rval;
}
if ( (rval = pthread_mutexattr_settype(&cexpMutexAttributes, PTHREAD_MUTEX_RECURSIVE)) ) {
fprintf(stderr,"pthread_mutexattr_settype failed: %s\n", strerror(rval));
return rval;
}
return 0;
}
#endif