Lines Matching refs:data
45 void *data; member
67 static inline uint32_t ps_sd_hash(const char *data, int len) in ps_sd_hash() argument
70 const char *e = data + len; in ps_sd_hash()
72 for (h = 2166136261U; data < e; ) { in ps_sd_hash()
74 h ^= *data++; in ps_sd_hash()
80 static void hash_split(ps_mm *data) in hash_split() argument
87 nmax = ((data->hash_max + 1) << 1) - 1; in hash_split()
88 nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash)); in hash_split()
95 ehash = data->hash + data->hash_max + 1; in hash_split()
96 for (ohash = data->hash; ohash < ehash; ohash++) { in hash_split()
103 mm_free(data->mm, data->hash); in hash_split()
105 data->hash = nhash; in hash_split()
106 data->hash_max = nmax; in hash_split()
109 static ps_sd *ps_sd_new(ps_mm *data, const char *key) in ps_sd_new() argument
117 sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen); in ps_sd_new()
120 …php_error_docref(NULL, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), m… in ps_sd_new()
125 slot = hv & data->hash_max; in ps_sd_new()
129 sd->data = NULL; in ps_sd_new()
134 sd->next = data->hash[slot]; in ps_sd_new()
135 data->hash[slot] = sd; in ps_sd_new()
137 data->hash_cnt++; in ps_sd_new()
140 if (data->hash_cnt >= data->hash_max) { in ps_sd_new()
141 hash_split(data); in ps_sd_new()
150 static void ps_sd_destroy(ps_mm *data, ps_sd *sd) in ps_sd_destroy() argument
154 slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max; in ps_sd_destroy()
156 if (data->hash[slot] == sd) { in ps_sd_destroy()
157 data->hash[slot] = sd->next; in ps_sd_destroy()
162 for (prev = data->hash[slot]; prev->next != sd; prev = prev->next); in ps_sd_destroy()
166 data->hash_cnt--; in ps_sd_destroy()
168 if (sd->data) { in ps_sd_destroy()
169 mm_free(data->mm, sd->data); in ps_sd_destroy()
172 mm_free(data->mm, sd); in ps_sd_destroy()
175 static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw) in ps_sd_lookup() argument
181 slot = hv & data->hash_max; in ps_sd_lookup()
183 for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) { in ps_sd_lookup()
189 if (ret && rw && ret != data->hash[slot]) { in ps_sd_lookup()
195 ret->next = data->hash[slot]; in ps_sd_lookup()
196 data->hash[slot] = ret; in ps_sd_lookup()
204 static int ps_mm_key_exists(ps_mm *data, const char *key) in ps_mm_key_exists() argument
211 sd = ps_sd_lookup(data, key, 0); in ps_mm_key_exists()
222 #define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
224 static int ps_mm_initialize(ps_mm *data, const char *path) in ps_mm_initialize() argument
226 data->owner = getpid(); in ps_mm_initialize()
227 data->mm = mm_create(0, path); in ps_mm_initialize()
228 if (!data->mm) { in ps_mm_initialize()
232 data->hash_cnt = 0; in ps_mm_initialize()
233 data->hash_max = 511; in ps_mm_initialize()
234 data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *)); in ps_mm_initialize()
235 if (!data->hash) { in ps_mm_initialize()
236 mm_destroy(data->mm); in ps_mm_initialize()
243 static void ps_mm_destroy(ps_mm *data) in ps_mm_destroy() argument
251 if (data->owner != getpid()) { in ps_mm_destroy()
255 for (h = 0; h < data->hash_max + 1; h++) { in ps_mm_destroy()
256 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
258 ps_sd_destroy(data, sd); in ps_mm_destroy()
262 mm_free(data->mm, data->hash); in ps_mm_destroy()
263 mm_destroy(data->mm); in ps_mm_destroy()
264 free(data); in ps_mm_destroy()
349 mm_lock(data->mm, MM_LOCK_RD); in PS_READ_FUNC()
353 && ps_mm_key_exists(data, key->val) == FAILURE) { in PS_READ_FUNC()
359 PS(id) = PS(mod)->s_create_sid((void **)&data); in PS_READ_FUNC()
370 sd = ps_sd_lookup(data, PS(id)->val, 0); in PS_READ_FUNC()
372 *val = zend_string_init(sd->data, sd->datalen, 0); in PS_READ_FUNC()
376 mm_unlock(data->mm); in PS_READ_FUNC()
386 mm_lock(data->mm, MM_LOCK_RW); in PS_WRITE_FUNC()
388 sd = ps_sd_lookup(data, key->val, 1); in PS_WRITE_FUNC()
390 sd = ps_sd_new(data, key->val); in PS_WRITE_FUNC()
396 if (data->mm) { in PS_WRITE_FUNC()
397 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
400 sd->data = mm_malloc(data->mm, sd->alloclen); in PS_WRITE_FUNC()
402 if (!sd->data) { in PS_WRITE_FUNC()
403 ps_sd_destroy(data, sd); in PS_WRITE_FUNC()
410 memcpy(sd->data, val->val, val->len); in PS_WRITE_FUNC()
415 mm_unlock(data->mm); in PS_WRITE_FUNC()
425 mm_lock(data->mm, MM_LOCK_RW); in PS_DESTROY_FUNC()
427 sd = ps_sd_lookup(data, key->val, 0); in PS_DESTROY_FUNC()
429 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
432 mm_unlock(data->mm); in PS_DESTROY_FUNC()
451 mm_lock(data->mm, MM_LOCK_RW); in PS_GC_FUNC()
453 ehash = data->hash + data->hash_max + 1; in PS_GC_FUNC()
454 for (ohash = data->hash; ohash < ehash; ohash++) { in PS_GC_FUNC()
459 ps_sd_destroy(data, sd); in PS_GC_FUNC()
465 mm_unlock(data->mm); in PS_GC_FUNC()
477 sid = php_session_create_id((void **)&data); in PS_CREATE_SID_FUNC()
479 if (ps_mm_key_exists(data, sid->val) == SUCCESS) { in PS_CREATE_SID_FUNC()