Mercurial > hg > nginx
comparison src/core/ngx_shmtx.c @ 860:201d017ea470
slab allocator in shared memory
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 20 Nov 2006 08:51:45 +0000 |
parents | 3f8a2132b93d |
children | 01884449985f |
comparison
equal
deleted
inserted
replaced
859:d1e8c59a50ee | 860:201d017ea470 |
---|---|
10 | 10 |
11 #if (NGX_HAVE_ATOMIC_OPS) | 11 #if (NGX_HAVE_ATOMIC_OPS) |
12 | 12 |
13 | 13 |
14 ngx_int_t | 14 ngx_int_t |
15 ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name, ngx_log_t *log) | 15 ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name) |
16 { | 16 { |
17 mtx->lock = addr; | 17 mtx->lock = addr; |
18 | 18 |
19 return NGX_OK; | 19 return NGX_OK; |
20 } | 20 } |
21 | 21 |
22 #else | 22 #else |
23 | 23 |
24 | 24 |
25 ngx_int_t | 25 ngx_int_t |
26 ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name, ngx_log_t *log) | 26 ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name) |
27 { | 27 { |
28 if (mtx->name) { | 28 if (mtx->name) { |
29 | 29 |
30 if (ngx_strcmp(name, mtx->name) == 0) { | 30 if (ngx_strcmp(name, mtx->name) == 0) { |
31 mtx->name = name; | 31 mtx->name = name; |
32 mtx->log = log; | |
33 | |
34 return NGX_OK; | 32 return NGX_OK; |
35 } | 33 } |
36 | 34 |
37 ngx_shmtx_destory(mtx); | 35 ngx_shmtx_destory(mtx); |
38 } | 36 } |
39 | 37 |
40 mtx->fd = ngx_open_file(name, NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN); | 38 mtx->fd = ngx_open_file(name, NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN); |
41 | 39 |
42 if (mtx->fd == NGX_INVALID_FILE) { | 40 if (mtx->fd == NGX_INVALID_FILE) { |
43 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | 41 ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, |
44 ngx_open_file_n " \"%s\" failed", name); | 42 ngx_open_file_n " \"%s\" failed", name); |
45 return NGX_ERROR; | 43 return NGX_ERROR; |
46 } | 44 } |
47 | 45 |
48 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | 46 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
49 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 47 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
50 ngx_delete_file_n " \"%s\" failed", name); | 48 ngx_delete_file_n " \"%s\" failed", name); |
51 } | 49 } |
52 | 50 |
53 mtx->name = name; | 51 mtx->name = name; |
54 mtx->log = log; | |
55 | 52 |
56 return NGX_OK; | 53 return NGX_OK; |
57 } | 54 } |
58 | 55 |
59 | 56 |
60 void | 57 void |
61 ngx_shmtx_destory(ngx_shmtx_t *mtx) | 58 ngx_shmtx_destory(ngx_shmtx_t *mtx) |
62 { | 59 { |
63 if (ngx_close_file(mtx->fd) == NGX_FILE_ERROR) { | 60 if (ngx_close_file(mtx->fd) == NGX_FILE_ERROR) { |
64 ngx_log_error(NGX_LOG_ALERT, mtx->log, ngx_errno, | 61 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
65 ngx_close_file_n " \"%s\" failed", mtx->name); | 62 ngx_close_file_n " \"%s\" failed", mtx->name); |
66 } | 63 } |
67 } | 64 } |
68 | 65 |
69 | 66 |