CBMC
semaphore.c
Go to the documentation of this file.
1 /* FUNCTION: sem_init */
2 
3 #include <semaphore.h>
4 
5 int sem_init(sem_t *sem, int pshared, unsigned int value)
6 {
7  __CPROVER_HIDE:;
8  (void)pshared;
9  (void)value;
10  (void)sem;
11 
12  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
13  __CPROVER_set_must(sem, "sem-init");
14  __CPROVER_clear_may(sem, "sem-destroyed");
15  #endif
16 
17  return 0;
18 }
19 
20 /* FUNCTION: sem_wait */
21 
22 #include <semaphore.h>
23 
24 int sem_wait(sem_t *sem)
25 {
26  __CPROVER_HIDE:;
27  (void)sem;
28 
29  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
30  __CPROVER_assert(__CPROVER_get_must(sem, "sem-init"),
31  "semaphore must be initialized");
32  __CPROVER_assert(!__CPROVER_get_may(sem, "sem-destroyed"),
33  "semaphore must not be destroyed");
34  #endif
35 
36  return 0;
37 }
38 
39 /* FUNCTION: sem_timedwait */
40 
41 #include <semaphore.h>
42 
43 int sem_timedwait(sem_t *sem, const struct timespec *abstime)
44 {
45  __CPROVER_HIDE:;
46  (void)sem;
47  (void)abstime;
48 
49  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
50  __CPROVER_assert(__CPROVER_get_must(sem, "sem-init"),
51  "semaphore must be initialized");
52  __CPROVER_assert(!__CPROVER_get_may(sem, "sem-destroyed"),
53  "semaphore must not be destroyed");
54  #endif
55 
56  return 0;
57 }
58 
59 /* FUNCTION: sem_trywait */
60 
61 #include <semaphore.h>
62 
63 int sem_trywait(sem_t *sem)
64 {
65  __CPROVER_HIDE:;
66  (void)sem;
67 
68  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
69  __CPROVER_assert(__CPROVER_get_must(sem, "sem-init"),
70  "semaphore must be initialized");
71  __CPROVER_assert(!__CPROVER_get_may(sem, "sem-destroyed"),
72  "semaphore must not be destroyed");
73  #endif
74 
75  return 0;
76 }
77 
78 /* FUNCTION: sem_post */
79 
80 #include <semaphore.h>
81 
82 int sem_post(sem_t *sem)
83 {
84  __CPROVER_HIDE:;
85  (void)sem;
86 
87  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
88  __CPROVER_assert(__CPROVER_get_must(sem, "sem-init"),
89  "semaphore must be initialized");
90  __CPROVER_assert(!__CPROVER_get_may(sem, "sem-destroyed"),
91  "semaphore must not be destroyed");
92  #endif
93 
94  return 0;
95 }
96 
97 /* FUNCTION: sem_post_multiple */
98 
99 #include <semaphore.h>
100 
101 int sem_post_multiple(sem_t *sem, int number)
102 {
103  __CPROVER_HIDE:;
104  (void)sem;
105  (void)number;
106 
107  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
108  __CPROVER_assert(__CPROVER_get_must(sem, "sem-init"),
109  "semaphore must be initialized");
110  __CPROVER_assert(!__CPROVER_get_may(sem, "sem-destroyed"),
111  "semaphore must not be destroyed");
112  #endif
113 
114  return 0;
115 }
116 
117 /* FUNCTION: sem_getvalue */
118 
119 #include <semaphore.h>
120 
121 int sem_getvalue(sem_t *sem, int *sval)
122 {
123  __CPROVER_HIDE:;
124  (void)sem;
125  (void)sval;
126 
127  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
128  __CPROVER_assert(__CPROVER_get_must(sem, "sem-init"),
129  "semaphore must be initialized");
130  __CPROVER_assert(!__CPROVER_get_may(sem, "sem-destroyed"),
131  "semaphore must not be destroyed");
132  #endif
133 
134  return 0;
135 }
136 
137 /* FUNCTION: sem_destroy */
138 
139 #include <semaphore.h>
140 
141 int sem_destroy(sem_t *sem)
142 {
143  __CPROVER_HIDE:;
144  (void)sem;
145 
146  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
147  __CPROVER_assert(__CPROVER_get_must(sem, "sem-init"),
148  "semaphore must be initialized");
149  __CPROVER_assert(!__CPROVER_get_may(sem, "sem-destroyed"),
150  "semaphore must not be destroyed");
151  __CPROVER_set_may(sem, "sem-destroyed");
152  #endif
153 
154  return 0;
155 }
void __CPROVER_assert(__CPROVER_bool assertion, const char *description)
__CPROVER_bool __CPROVER_get_must(const void *, const char *)
void __CPROVER_set_may(const void *, const char *)
void __CPROVER_clear_may(const void *, const char *)
__CPROVER_bool __CPROVER_get_may(const void *, const char *)
void __CPROVER_set_must(const void *, const char *)
int sem_post(sem_t *sem)
Definition: semaphore.c:82
int sem_trywait(sem_t *sem)
Definition: semaphore.c:63
int sem_init(sem_t *sem, int pshared, unsigned int value)
Definition: semaphore.c:5
int sem_destroy(sem_t *sem)
Definition: semaphore.c:141
int sem_post_multiple(sem_t *sem, int number)
Definition: semaphore.c:101
int sem_getvalue(sem_t *sem, int *sval)
Definition: semaphore.c:121
int sem_timedwait(sem_t *sem, const struct timespec *abstime)
Definition: semaphore.c:43
int sem_wait(sem_t *sem)
Definition: semaphore.c:24