Mercurial > hg > nginx-quic
annotate src/core/ngx_shmtx.c @ 903:89428c0b5a1c
release-0.5.2 tag
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 11 Dec 2006 15:23:28 +0000 |
parents | 201d017ea470 |
children | 01884449985f |
rev | line source |
---|---|
611 | 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 | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
15 ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name) |
611 | 16 { |
17 mtx->lock = addr; | |
18 | |
19 return NGX_OK; | |
20 } | |
21 | |
22 #else | |
23 | |
24 | |
25 ngx_int_t | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
26 ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name) |
611 | 27 { |
28 if (mtx->name) { | |
29 | |
30 if (ngx_strcmp(name, mtx->name) == 0) { | |
31 mtx->name = name; | |
32 return NGX_OK; | |
33 } | |
34 | |
35 ngx_shmtx_destory(mtx); | |
36 } | |
37 | |
38 mtx->fd = ngx_open_file(name, NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN); | |
39 | |
40 if (mtx->fd == NGX_INVALID_FILE) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
41 ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, |
611 | 42 ngx_open_file_n " \"%s\" failed", name); |
43 return NGX_ERROR; | |
44 } | |
45 | |
46 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
47 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
611 | 48 ngx_delete_file_n " \"%s\" failed", name); |
49 } | |
50 | |
51 mtx->name = name; | |
52 | |
53 return NGX_OK; | |
54 } | |
55 | |
56 | |
57 void | |
58 ngx_shmtx_destory(ngx_shmtx_t *mtx) | |
59 { | |
60 if (ngx_close_file(mtx->fd) == NGX_FILE_ERROR) { | |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
611
diff
changeset
|
61 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, |
611 | 62 ngx_close_file_n " \"%s\" failed", mtx->name); |
63 } | |
64 } | |
65 | |
66 | |
67 #endif |