3 * Copyright (C) Igor Sysoev
7 #ifndef _NGX_SHMTX_H_INCLUDED_
8 #define _NGX_SHMTX_H_INCLUDED_
11 #include <ngx_config.h>
16 #if (NGX_HAVE_ATOMIC_OPS)
25 ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name);
28 #if (NGX_HAVE_ATOMIC_OPS)
30 static ngx_inline ngx_uint_t
31 ngx_shmtx_trylock(ngx_shmtx_t *mtx)
33 return (*mtx->lock == 0 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid));
36 #define ngx_shmtx_lock(mtx) ngx_spinlock((mtx)->lock, ngx_pid, 1024)
38 #define ngx_shmtx_unlock(mtx) (void) ngx_atomic_cmp_set((mtx)->lock, ngx_pid, 0)
40 #define ngx_shmtx_destory(mtx)
45 static ngx_inline ngx_uint_t
46 ngx_shmtx_trylock(ngx_shmtx_t *mtx)
50 err = ngx_trylock_fd(mtx->fd);
56 if (err == NGX_EAGAIN) {
60 #if __osf__ /* Tru64 UNIX */
62 if (err == NGX_EACCESS) {
68 ngx_log_abort(err, ngx_trylock_fd_n " %s failed", mtx->name);
74 static ngx_inline void
75 ngx_shmtx_lock(ngx_shmtx_t *mtx)
79 err = ngx_lock_fd(mtx->fd);
85 ngx_log_abort(err, ngx_lock_fd_n " %s failed", mtx->name);
89 static ngx_inline void
90 ngx_shmtx_unlock(ngx_shmtx_t *mtx)
94 err = ngx_unlock_fd(mtx->fd);
100 ngx_log_abort(err, ngx_unlock_fd_n " %s failed", mtx->name);
104 void ngx_shmtx_destory(ngx_shmtx_t *mtx);
109 #endif /* _NGX_SHMTX_H_INCLUDED_ */