summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_semaphore.h
blob: d1985342c5cfb9d1d9391d37d42fe64bd2bf1573 (plain) (blame)
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

/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_UNIX_SEMAPHORE_H_INCLUDED_
#define _NXT_UNIX_SEMAPHORE_H_INCLUDED_


#if (NXT_HAVE_SEM_TIMEDWAIT)

typedef sem_t           nxt_sem_t;

#else

typedef struct {
    nxt_atomic_t        count;
    nxt_thread_mutex_t  mutex;
    nxt_thread_cond_t   cond;
} nxt_sem_t;

#endif


NXT_EXPORT nxt_int_t nxt_sem_init(nxt_sem_t *sem, nxt_uint_t count);
NXT_EXPORT void nxt_sem_destroy(nxt_sem_t *sem);
NXT_EXPORT nxt_int_t nxt_sem_post(nxt_sem_t *sem);
NXT_EXPORT nxt_err_t nxt_sem_wait(nxt_sem_t *sem, nxt_nsec_t timeout);


#endif /* _NXT_UNIX_SEMAPHORE_H_INCLUDED_ */