-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathending.c
More file actions
60 lines (45 loc) · 774 Bytes
/
ending.c
File metadata and controls
60 lines (45 loc) · 774 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <pthread.h>
#include "ending.h"
/* - - - - - - - - - - - - - - - - - - - - */
struct ending_s {
bool ending;
pthread_mutex_t m;
};
/* - - - - - - - - - - - - - - - - - - - - */
ending_t
ending_new(bool b)
{
ending_t e;
e = malloc(sizeof(*e));
e->ending = b;
pthread_mutex_init(&e->m, NULL);
return e;
}
bool
ending_get(ending_t e)
{
bool b;
pthread_mutex_lock(&e->m);
b = e->ending;
pthread_mutex_unlock(&e->m);
return b;
}
bool
ending_set(ending_t e, bool b2)
{
bool b;
pthread_mutex_lock(&e->m);
b = e->ending;
e->ending = b2;
pthread_mutex_unlock(&e->m);
return b;
}
void
ending_free(ending_t e)
{
pthread_mutex_destroy(&e->m);
free(e);
}