ngx_thread.h revision e18a033b
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#ifndef _NGX_THREAD_H_INCLUDED_
9#define _NGX_THREAD_H_INCLUDED_
10
11
12#include <ngx_config.h>
13#include <ngx_core.h>
14
15#if (NGX_THREADS)
16
17#include <pthread.h>
18
19
20typedef pthread_mutex_t  ngx_thread_mutex_t;
21
22ngx_int_t ngx_thread_mutex_create(ngx_thread_mutex_t *mtx, ngx_log_t *log);
23ngx_int_t ngx_thread_mutex_destroy(ngx_thread_mutex_t *mtx, ngx_log_t *log);
24ngx_int_t ngx_thread_mutex_lock(ngx_thread_mutex_t *mtx, ngx_log_t *log);
25ngx_int_t ngx_thread_mutex_unlock(ngx_thread_mutex_t *mtx, ngx_log_t *log);
26
27
28typedef pthread_cond_t  ngx_thread_cond_t;
29
30ngx_int_t ngx_thread_cond_create(ngx_thread_cond_t *cond, ngx_log_t *log);
31ngx_int_t ngx_thread_cond_destroy(ngx_thread_cond_t *cond, ngx_log_t *log);
32ngx_int_t ngx_thread_cond_signal(ngx_thread_cond_t *cond, ngx_log_t *log);
33ngx_int_t ngx_thread_cond_wait(ngx_thread_cond_t *cond, ngx_thread_mutex_t *mtx,
34    ngx_log_t *log);
35
36
37#if (NGX_LINUX)
38
39typedef pid_t      ngx_tid_t;
40#define NGX_TID_T_FMT         "%P"
41
42#elif (NGX_FREEBSD)
43
44typedef uint32_t   ngx_tid_t;
45#define NGX_TID_T_FMT         "%uD"
46
47#elif (NGX_DARWIN)
48
49typedef uint64_t   ngx_tid_t;
50#define NGX_TID_T_FMT         "%uA"
51
52#else
53
54typedef uint64_t   ngx_tid_t;
55#define NGX_TID_T_FMT         "%uA"
56
57#endif
58
59ngx_tid_t ngx_thread_tid(void);
60
61#define ngx_log_tid           ngx_thread_tid()
62
63#else
64
65#define ngx_log_tid           0
66#define NGX_TID_T_FMT         "%d"
67
68#endif
69
70
71#endif /* _NGX_THREAD_H_INCLUDED_ */
72