comparison src/core/ngx_shmtx.h @ 160:73e8476f9142 NGINX_0_3_27

nginx 0.3.27 *) Change: the "variables_hash_max_size" and "variables_hash_bucket_size" directives. *) Feature: the $body_bytes_sent variable can be used not only in the "log_format" directive. *) Feature: the $ssl_protocol and $ssl_cipher variables. *) Feature: the cache line size detection for widespread CPUs at start time. *) Feature: now the "accept_mutex" directive is supported using fcntl(2) on platforms different from i386, amd64, sparc64, and ppc. *) Feature: the "lock_file" directive and the --with-lock-path=PATH autoconfiguration directive. *) Bugfix: if the HTTPS protocol was used in the "proxy_pass" directive then the requests with the body was not transferred.
author Igor Sysoev <http://sysoev.ru>
date Wed, 08 Feb 2006 00:00:00 +0300
parents
children 6ae1357b7b7c
comparison
equal deleted inserted replaced
159:25c27e983933 160:73e8476f9142
1
2 /*
3 * Copyright (C) Igor Sysoev
4 */
5
6
7 #ifndef _NGX_SHMTX_H_INCLUDED_
8 #define _NGX_SHMTX_H_INCLUDED_
9
10
11 #include <ngx_config.h>
12 #include <ngx_core.h>
13
14
15 typedef struct {
16 #if (NGX_HAVE_ATOMIC_OPS)
17 ngx_atomic_t *lock;
18 #else
19 ngx_fd_t fd;
20 u_char *name;
21 ngx_log_t *log;
22 #endif
23 } ngx_shmtx_t;
24
25
26 ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name,
27 ngx_log_t *log);
28
29
30 #if (NGX_HAVE_ATOMIC_OPS)
31
32 static ngx_inline ngx_uint_t
33 ngx_shmtx_trylock(ngx_shmtx_t *mtx)
34 {
35 if (*mtx->lock == 0 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid)) {
36 return 1;
37 }
38
39 return 0;
40 }
41
42 #define ngx_shmtx_lock(mtx) ngx_spinlock((mtx)->lock, ngx_pid, 1024)
43
44 #define ngx_shmtx_unlock(mtx) (void) ngx_atomic_cmp_set((mtx)->lock, ngx_pid, 0)
45
46 #define ngx_shmtx_destory(mtx)
47
48
49 #else
50
51 static ngx_inline ngx_uint_t
52 ngx_shmtx_trylock(ngx_shmtx_t *mtx)
53 {
54 ngx_err_t err;
55
56 err = ngx_trylock_fd(mtx->fd);
57
58 if (err == 0) {
59 return 1;
60 }
61
62 if (err == NGX_EAGAIN) {
63 return 0;
64 }
65
66 ngx_log_error(NGX_LOG_ALERT, mtx->log, err, ngx_trylock_fd_n " failed");
67
68 ngx_abort();
69 }
70
71
72 static ngx_inline void
73 ngx_shmtx_lock(ngx_shmtx_t *mtx)
74 {
75 ngx_err_t err;
76
77 err = ngx_lock_fd(mtx->fd);
78
79 if (err == 0) {
80 return;
81 }
82
83 ngx_log_error(NGX_LOG_ALERT, mtx->log, err, ngx_lock_fd_n " failed");
84
85 ngx_abort();
86 }
87
88
89 static ngx_inline void
90 ngx_shmtx_unlock(ngx_shmtx_t *mtx)
91 {
92 ngx_err_t err;
93
94 err = ngx_unlock_fd(mtx->fd);
95
96 if (err == 0) {
97 return;
98 }
99
100 ngx_log_error(NGX_LOG_ALERT, mtx->log, err, ngx_unlock_fd_n " failed");
101
102 ngx_abort();
103 }
104
105
106 void ngx_shmtx_destory(ngx_shmtx_t *mtx);
107
108 #endif
109
110
111 #endif /* _NGX_SHMTX_H_INCLUDED_ */