diff options
Diffstat (limited to 'src/core/ngx_atomic.h')
-rw-r--r-- | src/core/ngx_atomic.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/core/ngx_atomic.h b/src/core/ngx_atomic.h index 5511ea765..bbf4a7685 100644 --- a/src/core/ngx_atomic.h +++ b/src/core/ngx_atomic.h @@ -93,4 +93,18 @@ typedef volatile uint32_t ngx_atomic_t; #endif +static ngx_inline ngx_int_t ngx_trylock(ngx_atomic_t *lock) +{ + if (*lock) { + return NGX_BUSY; + } + + if (ngx_atomic_cmp_set(lock, 0, 1)) { + return NGX_OK; + } + + return NGX_BUSY; +} + + #endif /* _NGX_ATOMIC_H_INCLUDED_ */ |