Lines Matching refs:data
47 void *data; member
69 static inline uint32_t ps_sd_hash(const char *data, int len) in ps_sd_hash() argument
72 const char *e = data + len; in ps_sd_hash()
74 for (h = 2166136261U; data < e; ) { in ps_sd_hash()
76 h ^= *data++; in ps_sd_hash()
82 static void hash_split(ps_mm *data) in hash_split() argument
89 nmax = ((data->hash_max + 1) << 1) - 1; in hash_split()
90 nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash)); in hash_split()
97 ehash = data->hash + data->hash_max + 1; in hash_split()
98 for (ohash = data->hash; ohash < ehash; ohash++) { in hash_split()
105 mm_free(data->mm, data->hash); in hash_split()
107 data->hash = nhash; in hash_split()
108 data->hash_max = nmax; in hash_split()
111 static ps_sd *ps_sd_new(ps_mm *data, const char *key) in ps_sd_new() argument
119 sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen); in ps_sd_new()
122 …php_error_docref(NULL, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), m… in ps_sd_new()
127 slot = hv & data->hash_max; in ps_sd_new()
131 sd->data = NULL; in ps_sd_new()
136 sd->next = data->hash[slot]; in ps_sd_new()
137 data->hash[slot] = sd; in ps_sd_new()
139 data->hash_cnt++; in ps_sd_new()
142 if (data->hash_cnt >= data->hash_max) { in ps_sd_new()
143 hash_split(data); in ps_sd_new()
152 static void ps_sd_destroy(ps_mm *data, ps_sd *sd) in ps_sd_destroy() argument
156 slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max; in ps_sd_destroy()
158 if (data->hash[slot] == sd) { in ps_sd_destroy()
159 data->hash[slot] = sd->next; in ps_sd_destroy()
164 for (prev = data->hash[slot]; prev->next != sd; prev = prev->next); in ps_sd_destroy()
168 data->hash_cnt--; in ps_sd_destroy()
170 if (sd->data) { in ps_sd_destroy()
171 mm_free(data->mm, sd->data); in ps_sd_destroy()
174 mm_free(data->mm, sd); in ps_sd_destroy()
177 static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw) in ps_sd_lookup() argument
183 slot = hv & data->hash_max; in ps_sd_lookup()
185 for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) { in ps_sd_lookup()
191 if (ret && rw && ret != data->hash[slot]) { in ps_sd_lookup()
197 ret->next = data->hash[slot]; in ps_sd_lookup()
198 data->hash[slot] = ret; in ps_sd_lookup()
206 static int ps_mm_key_exists(ps_mm *data, const char *key) in ps_mm_key_exists() argument
213 sd = ps_sd_lookup(data, key, 0); in ps_mm_key_exists()
224 #define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
226 static int ps_mm_initialize(ps_mm *data, const char *path) in ps_mm_initialize() argument
228 data->owner = getpid(); in ps_mm_initialize()
229 data->mm = mm_create(0, path); in ps_mm_initialize()
230 if (!data->mm) { in ps_mm_initialize()
234 data->hash_cnt = 0; in ps_mm_initialize()
235 data->hash_max = 511; in ps_mm_initialize()
236 data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *)); in ps_mm_initialize()
237 if (!data->hash) { in ps_mm_initialize()
238 mm_destroy(data->mm); in ps_mm_initialize()
245 static void ps_mm_destroy(ps_mm *data) in ps_mm_destroy() argument
253 if (data->owner != getpid()) { in ps_mm_destroy()
257 for (h = 0; h < data->hash_max + 1; h++) { in ps_mm_destroy()
258 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
260 ps_sd_destroy(data, sd); in ps_mm_destroy()
264 mm_free(data->mm, data->hash); in ps_mm_destroy()
265 mm_destroy(data->mm); in ps_mm_destroy()
266 free(data); in ps_mm_destroy()
351 mm_lock(data->mm, MM_LOCK_RD); in PS_READ_FUNC()
355 && ps_mm_key_exists(data, key->val) == FAILURE) { in PS_READ_FUNC()
361 PS(id) = PS(mod)->s_create_sid((void **)&data); in PS_READ_FUNC()
372 sd = ps_sd_lookup(data, PS(id)->val, 0); in PS_READ_FUNC()
374 *val = zend_string_init(sd->data, sd->datalen, 0); in PS_READ_FUNC()
378 mm_unlock(data->mm); in PS_READ_FUNC()
388 mm_lock(data->mm, MM_LOCK_RW); in PS_WRITE_FUNC()
390 sd = ps_sd_lookup(data, key->val, 1); in PS_WRITE_FUNC()
392 sd = ps_sd_new(data, key->val); in PS_WRITE_FUNC()
398 if (data->mm) { in PS_WRITE_FUNC()
399 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
402 sd->data = mm_malloc(data->mm, sd->alloclen); in PS_WRITE_FUNC()
404 if (!sd->data) { in PS_WRITE_FUNC()
405 ps_sd_destroy(data, sd); in PS_WRITE_FUNC()
412 memcpy(sd->data, val->val, val->len); in PS_WRITE_FUNC()
417 mm_unlock(data->mm); in PS_WRITE_FUNC()
427 mm_lock(data->mm, MM_LOCK_RW); in PS_DESTROY_FUNC()
429 sd = ps_sd_lookup(data, key->val, 0); in PS_DESTROY_FUNC()
431 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
434 mm_unlock(data->mm); in PS_DESTROY_FUNC()
453 mm_lock(data->mm, MM_LOCK_RW); in PS_GC_FUNC()
455 ehash = data->hash + data->hash_max + 1; in PS_GC_FUNC()
456 for (ohash = data->hash; ohash < ehash; ohash++) { in PS_GC_FUNC()
461 ps_sd_destroy(data, sd); in PS_GC_FUNC()
467 mm_unlock(data->mm); in PS_GC_FUNC()
479 sid = php_session_create_id((void **)&data); in PS_CREATE_SID_FUNC()
481 if (ps_mm_key_exists(data, sid->val) == SUCCESS) { in PS_CREATE_SID_FUNC()