Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) Igor Sysoev |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | #include <ngx_config.h> |
| 8 | #include <ngx_core.h> |
| 9 | |
| 10 | |
| 11 | #if (NGX_HAVE_ATOMIC_OPS) |
| 12 | |
| 13 | |
| 14 | ngx_int_t |
Igor Sysoev | 67cd336 | 2006-11-20 08:51:45 +0000 | [diff] [blame] | 15 | ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name) |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 16 | { |
| 17 | mtx->lock = addr; |
| 18 | |
| 19 | return NGX_OK; |
| 20 | } |
| 21 | |
| 22 | #else |
| 23 | |
| 24 | |
| 25 | ngx_int_t |
Igor Sysoev | 67cd336 | 2006-11-20 08:51:45 +0000 | [diff] [blame] | 26 | ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name) |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 27 | { |
| 28 | if (mtx->name) { |
| 29 | |
| 30 | if (ngx_strcmp(name, mtx->name) == 0) { |
| 31 | mtx->name = name; |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 32 | return NGX_OK; |
| 33 | } |
| 34 | |
| 35 | ngx_shmtx_destory(mtx); |
| 36 | } |
| 37 | |
Igor Sysoev | 8e75011 | 2007-02-11 07:49:12 +0000 | [diff] [blame] | 38 | mtx->fd = ngx_open_file(name, NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN, |
| 39 | NGX_FILE_DEFAULT_ACCESS); |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 40 | |
| 41 | if (mtx->fd == NGX_INVALID_FILE) { |
Igor Sysoev | 67cd336 | 2006-11-20 08:51:45 +0000 | [diff] [blame] | 42 | ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 43 | ngx_open_file_n " \"%s\" failed", name); |
| 44 | return NGX_ERROR; |
| 45 | } |
| 46 | |
| 47 | if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
Igor Sysoev | 67cd336 | 2006-11-20 08:51:45 +0000 | [diff] [blame] | 48 | ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 49 | ngx_delete_file_n " \"%s\" failed", name); |
| 50 | } |
| 51 | |
| 52 | mtx->name = name; |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 53 | |
| 54 | return NGX_OK; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | void |
| 59 | ngx_shmtx_destory(ngx_shmtx_t *mtx) |
| 60 | { |
| 61 | if (ngx_close_file(mtx->fd) == NGX_FILE_ERROR) { |
Igor Sysoev | 67cd336 | 2006-11-20 08:51:45 +0000 | [diff] [blame] | 62 | ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
Igor Sysoev | ffe7144 | 2006-02-08 15:33:12 +0000 | [diff] [blame] | 63 | ngx_close_file_n " \"%s\" failed", mtx->name); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | |
| 68 | #endif |