1/* Copyright 2016 Google Inc.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. */
14
15#ifndef NSYNC_INTERNAL_SEM_H_
16#define NSYNC_INTERNAL_SEM_H_
17
18/* A semaphore.
19 It may be counting or binary, and it need have no destructor. */
20
21#include "nsync_cpp.h"
22
23NSYNC_CPP_START_
24
25typedef struct nsync_semaphore_s_ {
26 void *sem_space[32]; /* space used by implementation */
27} nsync_semaphore;
28
29/* Initialize *s; the initial value is 0. */
30void nsync_mu_semaphore_init (nsync_semaphore *s);
31
32/* Wait until the count of *s exceeds 0, and decrement it. */
33void nsync_mu_semaphore_p (nsync_semaphore *s);
34
35/* Wait until one of:
36 the count of *s is non-zero, in which case decrement *s and return 0;
37 or abs_deadline expires, in which case return ETIMEDOUT. */
38int nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, nsync_time abs_deadline);
39
40/* Ensure that the count of *s is at least 1. */
41void nsync_mu_semaphore_v (nsync_semaphore *s);
42
43NSYNC_CPP_END_
44
45#endif /*NSYNC_INTERNAL_SEM_H_*/
46