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 ngx_log_abort(err, ngx_trylock_fd_n " failed");
66 static ngx_inline void
67 ngx_shmtx_lock(ngx_shmtx_t *mtx)
71 err = ngx_lock_fd(mtx->fd);
77 ngx_log_abort(err, ngx_lock_fd_n " failed");
81 static ngx_inline void
82 ngx_shmtx_unlock(ngx_shmtx_t *mtx)
86 err = ngx_unlock_fd(mtx->fd);
92 ngx_log_abort(err, ngx_unlock_fd_n " failed");
96 void ngx_shmtx_destory(ngx_shmtx_t *mtx);
101 #endif /* _NGX_SHMTX_H_INCLUDED_ */