Skip to content

Commit b626ef6

Browse files
committed
update new change for cache feature
1 parent 4fbbe68 commit b626ef6

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ngx_feature_incs="#include <ngx_http_c_func_module.h>"
2424
ngx_feature_path=
2525
ngx_feature_libs=
2626
# ngx_feature_exit_if_not_found=yes
27-
ngx_feature_test="int ngx_http_c_func_module_current_version_=ngx_http_c_func_module_version_4;"
27+
ngx_feature_test="int ngx_http_c_func_module_current_version_=ngx_http_c_func_module_version_5;"
2828
. auto/feature
2929

3030
if [ $ngx_found != yes ]; then

src/ngx_http_c_func_module.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ void ngx_http_c_func_shmtx_lock(void *shared_mem);
152152
void ngx_http_c_func_shmtx_unlock(void *shared_mem);
153153
void* ngx_http_c_func_shm_alloc(void *shared_mem, size_t size);
154154
void ngx_http_c_func_shm_free(void *shared_mem, void *ptr);
155+
void* ngx_http_c_func_shm_alloc_locked(void *shared_mem, size_t size);
156+
void ngx_http_c_func_shm_free_locked(void *shared_mem, void *ptr);
155157
void* ngx_http_c_func_cache_get(void *shared_mem, const char* key);
156158
void* ngx_http_c_func_cache_put(void *shared_mem, const char* key, void* value);
157159
void* ngx_http_c_func_cache_new(void *shared_mem, const char* key, size_t size);
158-
void ngx_http_c_func_cache_remove(void *shared_mem, const char* key);
160+
void* ngx_http_c_func_cache_remove(void *shared_mem, const char* key);
159161

160162
void ngx_http_c_func_write_resp(
161163
ngx_http_c_func_ctx_t *ctx,
@@ -499,7 +501,7 @@ ngx_http_c_func_post_configuration(ngx_conf_t *cf) {
499501
static ngx_int_t
500502
ngx_http_c_func_pre_configuration(ngx_conf_t *cf) {
501503

502-
#ifndef ngx_http_c_func_module_version_4
504+
#ifndef ngx_http_c_func_module_version_5
503505
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "the latest ngx_http_c_func_module.h not found in the c header path, \
504506
please copy latest ngx_http_c_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
505507
with read and write permission.");
@@ -1137,13 +1139,22 @@ ngx_http_c_func_shmtx_unlock(void *shared_mem) {
11371139

11381140
void*
11391141
ngx_http_c_func_shm_alloc(void *shared_mem, size_t size) {
1140-
return ngx_slab_alloc_locked(((ngx_http_c_func_http_shm_t*)shared_mem)->shpool, size);
1142+
return ngx_slab_alloc(((ngx_http_c_func_http_shm_t*)shared_mem)->shpool, size);
11411143
}
11421144

11431145
void
11441146
ngx_http_c_func_shm_free(void *shared_mem, void *ptr) {
1147+
ngx_slab_free(((ngx_http_c_func_http_shm_t*)shared_mem)->shpool, ptr);
1148+
}
1149+
1150+
void*
1151+
ngx_http_c_func_shm_alloc_locked(void *shared_mem, size_t size) {
1152+
return ngx_slab_alloc_locked(((ngx_http_c_func_http_shm_t*)shared_mem)->shpool, size);
1153+
}
1154+
1155+
void
1156+
ngx_http_c_func_shm_free_locked(void *shared_mem, void *ptr) {
11451157
ngx_slab_free_locked(((ngx_http_c_func_http_shm_t*)shared_mem)->shpool, ptr);
1146-
// ngx_spinlock((ngx_atomic_t*) ctx->__shm_t__->multi_processes_lock, 1, 2048);
11471158
}
11481159

11491160
void*
@@ -1210,16 +1221,22 @@ ngx_http_c_func_cache_new(void *shared_mem, const char* key, size_t size) {
12101221
return cvnt->value;
12111222
}
12121223

1213-
void
1224+
void*
12141225
ngx_http_c_func_cache_remove(void *shared_mem, const char* key) {
1226+
void *old_value;
12151227
ngx_str_t str_key = ngx_string(key);
12161228
uint32_t hash = ngx_crc32_long(str_key.data, str_key.len);
12171229
ngx_http_c_func_http_shm_t *_cache = (ngx_http_c_func_http_shm_t *)shared_mem;
12181230
ngx_http_c_func_http_cache_value_node_t *cvnt = (ngx_http_c_func_http_cache_value_node_t *)
12191231
ngx_str_rbtree_lookup(&_cache->rbtree, &str_key, hash);
12201232

1221-
if (cvnt)
1233+
if (cvnt) {
1234+
old_value = cvnt->value;
12221235
ngx_rbtree_delete(&_cache->rbtree, &cvnt->sn.node);
1236+
return old_value;
1237+
}
1238+
1239+
return NULL;
12231240
}
12241241

12251242
void

src/ngx_http_c_func_module.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <stdlib.h>
3636
#include <stdint.h>
3737

38-
#define ngx_http_c_func_module_version_4 4
38+
#define ngx_http_c_func_module_version_5 5
3939

4040

4141
#define ngx_http_c_func_content_type_plaintext "text/plain"
@@ -86,7 +86,9 @@ extern void ngx_http_c_func_shmtx_lock(void *shared_mem);
8686
extern void ngx_http_c_func_shmtx_unlock(void *shared_mem);
8787
extern void* ngx_http_c_func_shm_alloc(void *shared_mem, size_t size);
8888
extern void ngx_http_c_func_shm_free(void *shared_mem, void *ptr);
89+
extern void* ngx_http_c_func_shm_alloc_locked(void *shared_mem, size_t size);
90+
extern void ngx_http_c_func_shm_free_locked(void *shared_mem, void *ptr);
8991
extern void* ngx_http_c_func_cache_get(void *shared_mem, const char* key);
9092
extern void* ngx_http_c_func_cache_put(void *shared_mem, const char* key, void* value);
9193
extern void* ngx_http_c_func_cache_new(void *shared_mem, const char* key, size_t size);
92-
extern void ngx_http_c_func_cache_remove(void *shared_mem, const char* key);
94+
extern void* ngx_http_c_func_cache_remove(void *shared_mem, const char* key);

0 commit comments

Comments
 (0)