Lines Matching refs:data
51 void *data; member
73 static inline php_uint32 ps_sd_hash(const char *data, int len) in ps_sd_hash() argument
76 const char *e = data + len; in ps_sd_hash()
78 for (h = 2166136261U; data < e; ) { in ps_sd_hash()
80 h ^= *data++; in ps_sd_hash()
86 static void hash_split(ps_mm *data) in hash_split() argument
93 nmax = ((data->hash_max + 1) << 1) - 1; in hash_split()
94 nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash)); in hash_split()
101 ehash = data->hash + data->hash_max + 1; in hash_split()
102 for (ohash = data->hash; ohash < ehash; ohash++) { in hash_split()
109 mm_free(data->mm, data->hash); in hash_split()
111 data->hash = nhash; in hash_split()
112 data->hash_max = nmax; in hash_split()
115 static ps_sd *ps_sd_new(ps_mm *data, const char *key) in ps_sd_new() argument
123 sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen); in ps_sd_new()
126 …php_error_docref(NULL, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), m… in ps_sd_new()
131 slot = hv & data->hash_max; in ps_sd_new()
135 sd->data = NULL; in ps_sd_new()
140 sd->next = data->hash[slot]; in ps_sd_new()
141 data->hash[slot] = sd; in ps_sd_new()
143 data->hash_cnt++; in ps_sd_new()
146 if (data->hash_cnt >= data->hash_max) { in ps_sd_new()
147 hash_split(data); in ps_sd_new()
156 static void ps_sd_destroy(ps_mm *data, ps_sd *sd) in ps_sd_destroy() argument
160 slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max; in ps_sd_destroy()
162 if (data->hash[slot] == sd) { in ps_sd_destroy()
163 data->hash[slot] = sd->next; in ps_sd_destroy()
168 for (prev = data->hash[slot]; prev->next != sd; prev = prev->next); in ps_sd_destroy()
172 data->hash_cnt--; in ps_sd_destroy()
174 if (sd->data) { in ps_sd_destroy()
175 mm_free(data->mm, sd->data); in ps_sd_destroy()
178 mm_free(data->mm, sd); in ps_sd_destroy()
181 static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw) in ps_sd_lookup() argument
187 slot = hv & data->hash_max; in ps_sd_lookup()
189 for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) { in ps_sd_lookup()
195 if (ret && rw && ret != data->hash[slot]) { in ps_sd_lookup()
201 ret->next = data->hash[slot]; in ps_sd_lookup()
202 data->hash[slot] = ret; in ps_sd_lookup()
210 static int ps_mm_key_exists(ps_mm *data, const char *key) in ps_mm_key_exists() argument
217 sd = ps_sd_lookup(data, key, 0); in ps_mm_key_exists()
228 #define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
230 static int ps_mm_initialize(ps_mm *data, const char *path) in ps_mm_initialize() argument
232 data->owner = getpid(); in ps_mm_initialize()
233 data->mm = mm_create(0, path); in ps_mm_initialize()
234 if (!data->mm) { in ps_mm_initialize()
238 data->hash_cnt = 0; in ps_mm_initialize()
239 data->hash_max = 511; in ps_mm_initialize()
240 data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *)); in ps_mm_initialize()
241 if (!data->hash) { in ps_mm_initialize()
242 mm_destroy(data->mm); in ps_mm_initialize()
249 static void ps_mm_destroy(ps_mm *data) in ps_mm_destroy() argument
257 if (data->owner != getpid()) { in ps_mm_destroy()
261 for (h = 0; h < data->hash_max + 1; h++) { in ps_mm_destroy()
262 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
264 ps_sd_destroy(data, sd); in ps_mm_destroy()
268 mm_free(data->mm, data->hash); in ps_mm_destroy()
269 mm_destroy(data->mm); in ps_mm_destroy()
270 free(data); in ps_mm_destroy()
355 mm_lock(data->mm, MM_LOCK_RD); in PS_READ_FUNC()
359 && ps_mm_key_exists(data, key->val) == FAILURE) { in PS_READ_FUNC()
365 PS(id) = PS(mod)->s_create_sid((void **)&data); in PS_READ_FUNC()
376 sd = ps_sd_lookup(data, PS(id)->val, 0); in PS_READ_FUNC()
378 *val = zend_string_init(sd->data, sd->datalen, 0); in PS_READ_FUNC()
382 mm_unlock(data->mm); in PS_READ_FUNC()
392 mm_lock(data->mm, MM_LOCK_RW); in PS_WRITE_FUNC()
394 sd = ps_sd_lookup(data, key->val, 1); in PS_WRITE_FUNC()
396 sd = ps_sd_new(data, key->val); in PS_WRITE_FUNC()
402 if (data->mm) { in PS_WRITE_FUNC()
403 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
406 sd->data = mm_malloc(data->mm, sd->alloclen); in PS_WRITE_FUNC()
408 if (!sd->data) { in PS_WRITE_FUNC()
409 ps_sd_destroy(data, sd); in PS_WRITE_FUNC()
416 memcpy(sd->data, val->val, val->len); in PS_WRITE_FUNC()
421 mm_unlock(data->mm); in PS_WRITE_FUNC()
431 mm_lock(data->mm, MM_LOCK_RW); in PS_DESTROY_FUNC()
433 sd = ps_sd_lookup(data, key->val, 0); in PS_DESTROY_FUNC()
435 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
438 mm_unlock(data->mm); in PS_DESTROY_FUNC()
457 mm_lock(data->mm, MM_LOCK_RW); in PS_GC_FUNC()
459 ehash = data->hash + data->hash_max + 1; in PS_GC_FUNC()
460 for (ohash = data->hash; ohash < ehash; ohash++) { in PS_GC_FUNC()
465 ps_sd_destroy(data, sd); in PS_GC_FUNC()
471 mm_unlock(data->mm); in PS_GC_FUNC()
483 sid = php_session_create_id((void **)&data); in PS_CREATE_SID_FUNC()
485 if (ps_mm_key_exists(data, sid->val) == SUCCESS) { in PS_CREATE_SID_FUNC()