Lines Matching refs:data
45 void *data; member
67 static inline uint32_t ps_sd_hash(const zend_string *data) in ps_sd_hash() argument
70 const char *data_char = ZSTR_VAL(data); in ps_sd_hash()
71 const char *e = ZSTR_VAL(data) + ZSTR_LEN(data); in ps_sd_hash()
81 static void hash_split(ps_mm *data) in hash_split() argument
88 nmax = ((data->hash_max + 1) << 1) - 1; in hash_split()
89 nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash)); in hash_split()
96 ehash = data->hash + data->hash_max + 1; in hash_split()
97 for (ohash = data->hash; ohash < ehash; ohash++) { in hash_split()
104 mm_free(data->mm, data->hash); in hash_split()
106 data->hash = nhash; in hash_split()
107 data->hash_max = nmax; in hash_split()
110 static ps_sd *ps_sd_new(ps_mm *data, zend_string *key) in ps_sd_new() argument
115 sd = mm_malloc(data->mm, sizeof(ps_sd) + ZSTR_LEN(key)); in ps_sd_new()
118 …php_error_docref(NULL, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), m… in ps_sd_new()
123 slot = hv & data->hash_max; in ps_sd_new()
127 sd->data = NULL; in ps_sd_new()
132 sd->next = data->hash[slot]; in ps_sd_new()
133 data->hash[slot] = sd; in ps_sd_new()
135 data->hash_cnt++; in ps_sd_new()
138 if (data->hash_cnt >= data->hash_max) { in ps_sd_new()
139 hash_split(data); in ps_sd_new()
148 static void ps_sd_destroy(ps_mm *data, ps_sd *sd) in ps_sd_destroy() argument
152 slot = ps_sd_hash(sd->key) & data->hash_max; in ps_sd_destroy()
154 if (data->hash[slot] == sd) { in ps_sd_destroy()
155 data->hash[slot] = sd->next; in ps_sd_destroy()
160 for (prev = data->hash[slot]; prev->next != sd; prev = prev->next); in ps_sd_destroy()
164 data->hash_cnt--; in ps_sd_destroy()
166 if (sd->data) { in ps_sd_destroy()
167 mm_free(data->mm, sd->data); in ps_sd_destroy()
171 mm_free(data->mm, sd); in ps_sd_destroy()
174 static ps_sd *ps_sd_lookup(ps_mm *data, const zend_string *key, bool rw) in ps_sd_lookup() argument
180 slot = hv & data->hash_max; in ps_sd_lookup()
182 for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) { in ps_sd_lookup()
188 if (ret && rw && ret != data->hash[slot]) { in ps_sd_lookup()
194 ret->next = data->hash[slot]; in ps_sd_lookup()
195 data->hash[slot] = ret; in ps_sd_lookup()
203 static zend_result ps_mm_key_exists(ps_mm *data, const zend_string *key) in ps_mm_key_exists() argument
210 sd = ps_sd_lookup(data, key, 0); in ps_mm_key_exists()
221 #define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
223 static zend_result ps_mm_initialize(ps_mm *data, const char *path) in ps_mm_initialize() argument
225 data->owner = getpid(); in ps_mm_initialize()
226 data->mm = mm_create(0, path); in ps_mm_initialize()
227 if (!data->mm) { in ps_mm_initialize()
231 data->hash_cnt = 0; in ps_mm_initialize()
232 data->hash_max = 511; in ps_mm_initialize()
233 data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *)); in ps_mm_initialize()
234 if (!data->hash) { in ps_mm_initialize()
235 mm_destroy(data->mm); in ps_mm_initialize()
242 static void ps_mm_destroy(ps_mm *data) in ps_mm_destroy() argument
249 if (data->owner != getpid()) { in ps_mm_destroy()
253 for (int h = 0; h < data->hash_max + 1; h++) { in ps_mm_destroy()
254 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
256 ps_sd_destroy(data, sd); in ps_mm_destroy()
260 mm_free(data->mm, data->hash); in ps_mm_destroy()
261 mm_destroy(data->mm); in ps_mm_destroy()
262 free(data); in ps_mm_destroy()
347 mm_lock(data->mm, MM_LOCK_RD); in PS_READ_FUNC()
351 && ps_mm_key_exists(data, key) == FAILURE) { in PS_READ_FUNC()
357 PS(id) = PS(mod)->s_create_sid((void **)&data); in PS_READ_FUNC()
368 sd = ps_sd_lookup(data, PS(id), 0); in PS_READ_FUNC()
370 *val = zend_string_init(sd->data, sd->datalen, 0); in PS_READ_FUNC()
374 mm_unlock(data->mm); in PS_READ_FUNC()
384 mm_lock(data->mm, MM_LOCK_RW); in PS_WRITE_FUNC()
386 sd = ps_sd_lookup(data, key, 1); in PS_WRITE_FUNC()
388 sd = ps_sd_new(data, key); in PS_WRITE_FUNC()
394 if (data->mm) { in PS_WRITE_FUNC()
395 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
398 sd->data = mm_malloc(data->mm, sd->alloclen); in PS_WRITE_FUNC()
400 if (!sd->data) { in PS_WRITE_FUNC()
401 ps_sd_destroy(data, sd); in PS_WRITE_FUNC()
408 memcpy(sd->data, val->val, val->len); in PS_WRITE_FUNC()
413 mm_unlock(data->mm); in PS_WRITE_FUNC()
423 mm_lock(data->mm, MM_LOCK_RW); in PS_DESTROY_FUNC()
425 sd = ps_sd_lookup(data, key, 0); in PS_DESTROY_FUNC()
427 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
430 mm_unlock(data->mm); in PS_DESTROY_FUNC()
449 mm_lock(data->mm, MM_LOCK_RW); in PS_GC_FUNC()
451 ehash = data->hash + data->hash_max + 1; in PS_GC_FUNC()
452 for (ohash = data->hash; ohash < ehash; ohash++) { in PS_GC_FUNC()
457 ps_sd_destroy(data, sd); in PS_GC_FUNC()
463 mm_unlock(data->mm); in PS_GC_FUNC()
475 sid = php_session_create_id((void **)&data); in PS_CREATE_SID_FUNC()
477 if (ps_mm_key_exists(data, sid) == SUCCESS) { in PS_CREATE_SID_FUNC()