Mercurial > hg > nginx-quic
annotate src/core/ngx_shmtx.c @ 7246:04ebf29eaf5b
Configure: fixed static compilation with OpenSSL 1.1.1.
OpenSSL now uses pthread_atfork(), and this requires -lpthread on Linux
to compile. Introduced NGX_LIBPTHREAD to add it as appropriate, similar
to existing NGX_LIBDL.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 22 Mar 2018 15:55:57 +0300 |
parents | 860a1c37f3b2 |
children |
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)) { |
5970
74edc0ccf27a
Core: fixed a race resulting in extra sem_post()'s.
Roman Arutyunyan <arut@nginx.com>
parents:
4932
diff
changeset
|
104 (void) ngx_atomic_fetch_add(mtx->wait, -1); |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
105 return; |
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 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
108 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
|
109 "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
|
110 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
111 while (sem_wait(&mtx->sem) == -1) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
112 ngx_err_t err; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
113 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
114 err = ngx_errno; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
115 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
116 if (err != NGX_EINTR) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
117 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
|
118 "sem_wait() failed while waiting on shmtx"); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
119 break; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
120 } |
4932
0fce5bb53b2d
Fixed location of debug message in ngx_shmtx_lock().
Ruslan Ermilov <ru@nginx.com>
parents:
4738
diff
changeset
|
121 } |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
122 |
4932
0fce5bb53b2d
Fixed location of debug message in ngx_shmtx_lock().
Ruslan Ermilov <ru@nginx.com>
parents:
4738
diff
changeset
|
123 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
|
124 "shmtx awoke"); |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
125 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
126 continue; |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
129 #endif |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
130 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
131 ngx_sched_yield(); |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
136 void |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
137 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
|
138 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
139 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
|
140 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
|
141 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
142 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
143 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
|
144 ngx_shmtx_wakeup(mtx); |
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 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
149 ngx_uint_t |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
150 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
|
151 { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
152 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
|
153 "shmtx forced unlock"); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
154 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
155 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
|
156 ngx_shmtx_wakeup(mtx); |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
157 return 1; |
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 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
160 return 0; |
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 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
164 static void |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
165 ngx_shmtx_wakeup(ngx_shmtx_t *mtx) |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
166 { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
167 #if (NGX_HAVE_POSIX_SEM) |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
168 ngx_atomic_uint_t wait; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
169 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
170 if (!mtx->semaphore) { |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
171 return; |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
172 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
173 |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
174 for ( ;; ) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
175 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
176 wait = *mtx->wait; |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
177 |
5970
74edc0ccf27a
Core: fixed a race resulting in extra sem_post()'s.
Roman Arutyunyan <arut@nginx.com>
parents:
4932
diff
changeset
|
178 if ((ngx_atomic_int_t) wait <= 0) { |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
179 return; |
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 |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
182 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
|
183 break; |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
187 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
|
188 "shmtx wake %uA", wait); |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
189 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
190 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
|
191 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
|
192 "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
|
193 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
194 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
195 #endif |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
198 |
611 | 199 #else |
200 | |
201 | |
202 ngx_int_t | |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
203 ngx_shmtx_create(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr, u_char *name) |
611 | 204 { |
205 if (mtx->name) { | |
206 | |
207 if (ngx_strcmp(name, mtx->name) == 0) { | |
208 mtx->name = name; | |
209 return NGX_OK; | |
210 } | |
211 | |
4738
512c741fa841
Fixed typo in a function name.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
212 ngx_shmtx_destroy(mtx); |
611 | 213 } |
214 | |
1100
01884449985f
fix building on platforms with non-supported atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
215 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
|
216 NGX_FILE_DEFAULT_ACCESS); |
611 | 217 |
218 if (mtx->fd == NGX_INVALID_FILE) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
219 ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, |
611 | 220 ngx_open_file_n " \"%s\" failed", name); |
221 return NGX_ERROR; | |
222 } | |
223 | |
224 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
225 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
611 | 226 ngx_delete_file_n " \"%s\" failed", name); |
227 } | |
228 | |
229 mtx->name = name; | |
230 | |
231 return NGX_OK; | |
232 } | |
233 | |
234 | |
235 void | |
4738
512c741fa841
Fixed typo in a function name.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
236 ngx_shmtx_destroy(ngx_shmtx_t *mtx) |
611 | 237 { |
238 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
|
239 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
611 | 240 ngx_close_file_n " \"%s\" failed", mtx->name); |
241 } | |
242 } | |
243 | |
244 | |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
245 ngx_uint_t |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
246 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
|
247 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
248 ngx_err_t err; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
249 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
250 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
|
251 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
252 if (err == 0) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
253 return 1; |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
256 if (err == NGX_EAGAIN) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
257 return 0; |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
260 #if __osf__ /* Tru64 UNIX */ |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
261 |
5972
860a1c37f3b2
Core: fixed build on Tru64 UNIX.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5970
diff
changeset
|
262 if (err == NGX_EACCES) { |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
263 return 0; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
264 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
265 |
611 | 266 #endif |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
267 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
268 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
|
269 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
270 return 0; |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
274 void |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
275 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
|
276 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
277 ngx_err_t err; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
278 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
279 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
|
280 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
281 if (err == 0) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
282 return; |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
285 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
|
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
289 void |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
290 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
|
291 { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
292 ngx_err_t err; |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
293 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
294 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
|
295 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
296 if (err == 0) { |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
297 return; |
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 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
300 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
|
301 } |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
302 |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
303 |
4310
13f108b9f3cf
Fixed build without atomic operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
304 ngx_uint_t |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
305 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
|
306 { |
4310
13f108b9f3cf
Fixed build without atomic operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4309
diff
changeset
|
307 return 0; |
4309
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
308 } |
3f6040cd731e
Added shmtx interface to forcibly unlock mutexes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3909
diff
changeset
|
309 |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
1100
diff
changeset
|
310 #endif |