comparison src/core/ngx_shmtx.h @ 4309:3f6040cd731e

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().
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 23 Nov 2011 13:55:38 +0000
parents 0daede16d68b
children d620f497c50f
comparison
equal deleted inserted replaced
4308:39982fa69482 4309:3f6040cd731e
11 #include <ngx_config.h> 11 #include <ngx_config.h>
12 #include <ngx_core.h> 12 #include <ngx_core.h>
13 13
14 14
15 typedef struct { 15 typedef struct {
16 ngx_atomic_t lock;
17 #if (NGX_HAVE_POSIX_SEM)
18 ngx_atomic_t wait;
19 #endif
20 } ngx_shmtx_sh_t;
21
22
23 typedef struct {
16 #if (NGX_HAVE_ATOMIC_OPS) 24 #if (NGX_HAVE_ATOMIC_OPS)
17 ngx_atomic_t *lock; 25 ngx_atomic_t *lock;
18 #if (NGX_HAVE_POSIX_SEM) 26 #if (NGX_HAVE_POSIX_SEM)
27 ngx_atomic_t *wait;
19 ngx_uint_t semaphore; 28 ngx_uint_t semaphore;
20 sem_t sem; 29 sem_t sem;
21 #endif 30 #endif
22 #else 31 #else
23 ngx_fd_t fd; 32 ngx_fd_t fd;
25 #endif 34 #endif
26 ngx_uint_t spin; 35 ngx_uint_t spin;
27 } ngx_shmtx_t; 36 } ngx_shmtx_t;
28 37
29 38
30 ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name); 39 ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr,
40 u_char *name);
31 void ngx_shmtx_destory(ngx_shmtx_t *mtx); 41 void ngx_shmtx_destory(ngx_shmtx_t *mtx);
32 ngx_uint_t ngx_shmtx_trylock(ngx_shmtx_t *mtx); 42 ngx_uint_t ngx_shmtx_trylock(ngx_shmtx_t *mtx);
33 void ngx_shmtx_lock(ngx_shmtx_t *mtx); 43 void ngx_shmtx_lock(ngx_shmtx_t *mtx);
34 void ngx_shmtx_unlock(ngx_shmtx_t *mtx); 44 void ngx_shmtx_unlock(ngx_shmtx_t *mtx);
45 ngx_uint_t ngx_shmtx_force_unlock(ngx_shmtx_t *mtx, ngx_pid_t pid);
35 46
36 47
37 #endif /* _NGX_SHMTX_H_INCLUDED_ */ 48 #endif /* _NGX_SHMTX_H_INCLUDED_ */