aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_shmtx.h
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2011-11-23 13:55:38 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2011-11-23 13:55:38 +0000
commit91ecc8f43c42c677cd7b2230a68f19b64b649ba5 (patch)
treef05df203ee000dde0ce2297cea01a6ef663513d4 /src/core/ngx_shmtx.h
parent1e5f2391704c252fcd01f798a18aa8558376cb1a (diff)
downloadnginx-91ecc8f43c42c677cd7b2230a68f19b64b649ba5.tar.gz
nginx-91ecc8f43c42c677cd7b2230a68f19b64b649ba5.zip
Added shmtx interface to forcibly unlock mutexes.
It is currently used from master process on abnormal worker termination to unlock accept mutex (unlocking of accept mutex was broken in 1.0.2). It is expected to be used in the future to unlock other mutexes as well. Shared mutex code was rewritten to make this possible in a safe way, i.e. with a check if lock was actually held by the exited process. We again use pid to lock mutex, and use separate atomic variable for a count of processes waiting in sem_wait().
Diffstat (limited to 'src/core/ngx_shmtx.h')
-rw-r--r--src/core/ngx_shmtx.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/core/ngx_shmtx.h b/src/core/ngx_shmtx.h
index 714f73aa6..3ee7d3a79 100644
--- a/src/core/ngx_shmtx.h
+++ b/src/core/ngx_shmtx.h
@@ -13,9 +13,18 @@
typedef struct {
+ ngx_atomic_t lock;
+#if (NGX_HAVE_POSIX_SEM)
+ ngx_atomic_t wait;
+#endif
+} ngx_shmtx_sh_t;
+
+
+typedef struct {
#if (NGX_HAVE_ATOMIC_OPS)
ngx_atomic_t *lock;
#if (NGX_HAVE_POSIX_SEM)
+ ngx_atomic_t *wait;
ngx_uint_t semaphore;
sem_t sem;
#endif
@@ -27,11 +36,13 @@ typedef struct {
} ngx_shmtx_t;
-ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name);
+ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr,
+ u_char *name);
void ngx_shmtx_destory(ngx_shmtx_t *mtx);
ngx_uint_t ngx_shmtx_trylock(ngx_shmtx_t *mtx);
void ngx_shmtx_lock(ngx_shmtx_t *mtx);
void ngx_shmtx_unlock(ngx_shmtx_t *mtx);
+ngx_uint_t ngx_shmtx_force_unlock(ngx_shmtx_t *mtx, ngx_pid_t pid);
#endif /* _NGX_SHMTX_H_INCLUDED_ */