Mercurial > hg > nginx-quic
annotate src/core/ngx_shmtx.c @ 5361:7094d6da2806
Win32: $request_time fixed.
On win32, time_t is 64 bits wide by default, and passing an ngx_msec_int_t
argument for %T format specifier doesn't work. This doesn't manifest itself
on other platforms as time_t and ngx_msec_int_t are usually of the same size.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 04 Sep 2013 20:48:30 +0400 |
parents | 0fce5bb53b2d |
children | 74edc0ccf27a |
rev | line source |
---|---|
611 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
611 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 | |
11 | |
12 #if (NGX_HAVE_ATOMIC_OPS) | |
13 | |
14 | |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
15 static void ngx_shmtx_wakeup(ngx_shmtx_t *mtx); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
16 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
17 |
611 | 18 ngx_int_t |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
19 ngx_shmtx_create(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr, u_char *name) |
611 | 20 { |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
21 mtx->lock = &addr->lock; |
611 | 22 |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
23 if (mtx->spin == (ngx_uint_t) -1) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
24 return NGX_OK; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
25 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
26 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
27 mtx->spin = 2048; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
28 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
29 #if (NGX_HAVE_POSIX_SEM) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
30 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
31 mtx->wait = &addr->wait; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
32 |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
33 if (sem_init(&mtx->sem, 1, 0) == -1) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
34 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
35 "sem_init() failed"); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
36 } else { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
37 mtx->semaphore = 1; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
38 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
39 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
40 #endif |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
41 |
611 | 42 return NGX_OK; |
43 } | |
44 | |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
45 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
46 void |
4738
512c741fa841
Fixed typo in a function name.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
47 ngx_shmtx_destroy(ngx_shmtx_t *mtx) |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
48 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
49 #if (NGX_HAVE_POSIX_SEM) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
50 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
51 if (mtx->semaphore) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
52 if (sem_destroy(&mtx->sem) == -1) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
53 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
54 "sem_destroy() failed"); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
55 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
56 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
57 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
58 #endif |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
59 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
60 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
61 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
62 ngx_uint_t |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
63 ngx_shmtx_trylock(ngx_shmtx_t *mtx) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
64 { |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
65 return (*mtx->lock == 0 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid)); |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
66 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
67 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
68 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
69 void |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
70 ngx_shmtx_lock(ngx_shmtx_t *mtx) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
71 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
72 ngx_uint_t i, n; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
73 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
74 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, "shmtx lock"); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
75 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
76 for ( ;; ) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
77 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
78 if (*mtx->lock == 0 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid)) { |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
79 return; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
80 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
81 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
82 if (ngx_ncpu > 1) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
83 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
84 for (n = 1; n < mtx->spin; n <<= 1) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
85 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
86 for (i = 0; i < n; i++) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
87 ngx_cpu_pause(); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
88 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
89 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
90 if (*mtx->lock == 0 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
91 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid)) |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
92 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
93 return; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
94 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
95 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
96 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
97 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
98 #if (NGX_HAVE_POSIX_SEM) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
99 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
100 if (mtx->semaphore) { |
4315
424a1ac6af43
Added (void) as we intentionally ignore returned values.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4310
diff
changeset
|
101 (void) ngx_atomic_fetch_add(mtx->wait, 1); |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
102 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
103 if (*mtx->lock == 0 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid)) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
104 return; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
105 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
106 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
107 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
108 "shmtx wait %uA", *mtx->wait); |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
109 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
110 while (sem_wait(&mtx->sem) == -1) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
111 ngx_err_t err; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
112 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
113 err = ngx_errno; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
114 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
115 if (err != NGX_EINTR) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
116 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err, |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
117 "sem_wait() failed while waiting on shmtx"); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
118 break; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
119 } |
4932
0fce5bb53b2d
Fixed location of debug message in ngx_shmtx_lock().
Ruslan Ermilov <ru@nginx.com>
parents:
4738
diff
changeset
|
120 } |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
121 |
4932
0fce5bb53b2d
Fixed location of debug message in ngx_shmtx_lock().
Ruslan Ermilov <ru@nginx.com>
parents:
4738
diff
changeset
|
122 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, |
0fce5bb53b2d
Fixed location of debug message in ngx_shmtx_lock().
Ruslan Ermilov <ru@nginx.com>
parents:
4738
diff
changeset
|
123 "shmtx awoke"); |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
124 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
125 continue; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
126 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
127 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
128 #endif |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
129 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
130 ngx_sched_yield(); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
131 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
132 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
133 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
134 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
135 void |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
136 ngx_shmtx_unlock(ngx_shmtx_t *mtx) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
137 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
138 if (mtx->spin != (ngx_uint_t) -1) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
139 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, "shmtx unlock"); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
140 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
141 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
142 if (ngx_atomic_cmp_set(mtx->lock, ngx_pid, 0)) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
143 ngx_shmtx_wakeup(mtx); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
144 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
145 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
146 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
147 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
148 ngx_uint_t |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
149 ngx_shmtx_force_unlock(ngx_shmtx_t *mtx, ngx_pid_t pid) |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
150 { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
151 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
152 "shmtx forced unlock"); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
153 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
154 if (ngx_atomic_cmp_set(mtx->lock, pid, 0)) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
155 ngx_shmtx_wakeup(mtx); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
156 return 1; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
157 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
158 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
159 return 0; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
160 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
161 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
162 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
163 static void |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
164 ngx_shmtx_wakeup(ngx_shmtx_t *mtx) |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
165 { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
166 #if (NGX_HAVE_POSIX_SEM) |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
167 ngx_atomic_uint_t wait; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
168 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
169 if (!mtx->semaphore) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
170 return; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
171 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
172 |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
173 for ( ;; ) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
174 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
175 wait = *mtx->wait; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
176 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
177 if (wait == 0) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
178 return; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
179 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
180 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
181 if (ngx_atomic_cmp_set(mtx->wait, wait, wait - 1)) { |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
182 break; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
183 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
184 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
185 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
186 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
187 "shmtx wake %uA", wait); |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
188 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
189 if (sem_post(&mtx->sem) == -1) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
190 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
191 "sem_post() failed while wake shmtx"); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
192 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
193 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
194 #endif |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
195 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
196 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
197 |
611 | 198 #else |
199 | |
200 | |
201 ngx_int_t | |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
202 ngx_shmtx_create(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr, u_char *name) |
611 | 203 { |
204 if (mtx->name) { | |
205 | |
206 if (ngx_strcmp(name, mtx->name) == 0) { | |
207 mtx->name = name; | |
208 return NGX_OK; | |
209 } | |
210 | |
4738
512c741fa841
Fixed typo in a function name.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
211 ngx_shmtx_destroy(mtx); |
611 | 212 } |
213 | |
1100
01884449985f
fix building on platforms with non-supported atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
214 mtx->fd = ngx_open_file(name, NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN, |
01884449985f
fix building on platforms with non-supported atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
215 NGX_FILE_DEFAULT_ACCESS); |
611 | 216 |
217 if (mtx->fd == NGX_INVALID_FILE) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
218 ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, |
611 | 219 ngx_open_file_n " \"%s\" failed", name); |
220 return NGX_ERROR; | |
221 } | |
222 | |
223 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
224 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
611 | 225 ngx_delete_file_n " \"%s\" failed", name); |
226 } | |
227 | |
228 mtx->name = name; | |
229 | |
230 return NGX_OK; | |
231 } | |
232 | |
233 | |
234 void | |
4738
512c741fa841
Fixed typo in a function name.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
235 ngx_shmtx_destroy(ngx_shmtx_t *mtx) |
611 | 236 { |
237 if (ngx_close_file(mtx->fd) == NGX_FILE_ERROR) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
238 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
611 | 239 ngx_close_file_n " \"%s\" failed", mtx->name); |
240 } | |
241 } | |
242 | |
243 | |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
244 ngx_uint_t |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
245 ngx_shmtx_trylock(ngx_shmtx_t *mtx) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
246 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
247 ngx_err_t err; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
248 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
249 err = ngx_trylock_fd(mtx->fd); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
250 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
251 if (err == 0) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
252 return 1; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
253 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
254 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
255 if (err == NGX_EAGAIN) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
256 return 0; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
257 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
258 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
259 #if __osf__ /* Tru64 UNIX */ |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
260 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
261 if (err == NGX_EACCESS) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
262 return 0; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
263 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
264 |
611 | 265 #endif |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
266 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
267 ngx_log_abort(err, ngx_trylock_fd_n " %s failed", mtx->name); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
268 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
269 return 0; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
270 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
271 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
272 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
273 void |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
274 ngx_shmtx_lock(ngx_shmtx_t *mtx) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
275 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
276 ngx_err_t err; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
277 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
278 err = ngx_lock_fd(mtx->fd); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
279 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
280 if (err == 0) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
281 return; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
282 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
283 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
284 ngx_log_abort(err, ngx_lock_fd_n " %s failed", mtx->name); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
285 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
286 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
287 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
288 void |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
289 ngx_shmtx_unlock(ngx_shmtx_t *mtx) |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
290 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
291 ngx_err_t err; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
292 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
293 err = ngx_unlock_fd(mtx->fd); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
294 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
295 if (err == 0) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
296 return; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
297 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
298 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
299 ngx_log_abort(err, ngx_unlock_fd_n " %s failed", mtx->name); |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
300 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
301 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
302 |
4310
13f108b9f3cf
Fixed build without atomic operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
303 ngx_uint_t |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
304 ngx_shmtx_force_unlock(ngx_shmtx_t *mtx, ngx_pid_t pid) |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
305 { |
4310
13f108b9f3cf
Fixed build without atomic operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
306 return 0; |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
307 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
308 |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
309 #endif |