Lines Matching refs:data
49 void *data; member
71 static inline uint32_t ps_sd_hash(const char *data, int len) in ps_sd_hash() argument
74 const char *e = data + len; in ps_sd_hash()
76 for (h = 2166136261U; data < e; ) { in ps_sd_hash()
78 h ^= *data++; in ps_sd_hash()
84 static void hash_split(ps_mm *data) in hash_split() argument
91 nmax = ((data->hash_max + 1) << 1) - 1; in hash_split()
92 nhash = mm_calloc(data->mm, nmax + 1, sizeof(*data->hash)); in hash_split()
99 ehash = data->hash + data->hash_max + 1; in hash_split()
100 for (ohash = data->hash; ohash < ehash; ohash++) { in hash_split()
107 mm_free(data->mm, data->hash); in hash_split()
109 data->hash = nhash; in hash_split()
110 data->hash_max = nmax; in hash_split()
113 static ps_sd *ps_sd_new(ps_mm *data, const char *key) in ps_sd_new() argument
121 sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen); in ps_sd_new()
124 …php_error_docref(NULL, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), m… in ps_sd_new()
129 slot = hv & data->hash_max; in ps_sd_new()
133 sd->data = NULL; in ps_sd_new()
138 sd->next = data->hash[slot]; in ps_sd_new()
139 data->hash[slot] = sd; in ps_sd_new()
141 data->hash_cnt++; in ps_sd_new()
144 if (data->hash_cnt >= data->hash_max) { in ps_sd_new()
145 hash_split(data); in ps_sd_new()
154 static void ps_sd_destroy(ps_mm *data, ps_sd *sd) in ps_sd_destroy() argument
158 slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max; in ps_sd_destroy()
160 if (data->hash[slot] == sd) { in ps_sd_destroy()
161 data->hash[slot] = sd->next; in ps_sd_destroy()
166 for (prev = data->hash[slot]; prev->next != sd; prev = prev->next); in ps_sd_destroy()
170 data->hash_cnt--; in ps_sd_destroy()
172 if (sd->data) { in ps_sd_destroy()
173 mm_free(data->mm, sd->data); in ps_sd_destroy()
176 mm_free(data->mm, sd); in ps_sd_destroy()
179 static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw) in ps_sd_lookup() argument
185 slot = hv & data->hash_max; in ps_sd_lookup()
187 for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) { in ps_sd_lookup()
193 if (ret && rw && ret != data->hash[slot]) { in ps_sd_lookup()
199 ret->next = data->hash[slot]; in ps_sd_lookup()
200 data->hash[slot] = ret; in ps_sd_lookup()
208 static int ps_mm_key_exists(ps_mm *data, const char *key) in ps_mm_key_exists() argument
215 sd = ps_sd_lookup(data, key, 0); in ps_mm_key_exists()
226 #define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
228 static int ps_mm_initialize(ps_mm *data, const char *path) in ps_mm_initialize() argument
230 data->owner = getpid(); in ps_mm_initialize()
231 data->mm = mm_create(0, path); in ps_mm_initialize()
232 if (!data->mm) { in ps_mm_initialize()
236 data->hash_cnt = 0; in ps_mm_initialize()
237 data->hash_max = 511; in ps_mm_initialize()
238 data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *)); in ps_mm_initialize()
239 if (!data->hash) { in ps_mm_initialize()
240 mm_destroy(data->mm); in ps_mm_initialize()
247 static void ps_mm_destroy(ps_mm *data) in ps_mm_destroy() argument
255 if (data->owner != getpid()) { in ps_mm_destroy()
259 for (h = 0; h < data->hash_max + 1; h++) { in ps_mm_destroy()
260 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
262 ps_sd_destroy(data, sd); in ps_mm_destroy()
266 mm_free(data->mm, data->hash); in ps_mm_destroy()
267 mm_destroy(data->mm); in ps_mm_destroy()
268 free(data); in ps_mm_destroy()
353 mm_lock(data->mm, MM_LOCK_RD); in PS_READ_FUNC()
357 && ps_mm_key_exists(data, key->val) == FAILURE) { in PS_READ_FUNC()
363 PS(id) = PS(mod)->s_create_sid((void **)&data); in PS_READ_FUNC()
374 sd = ps_sd_lookup(data, PS(id)->val, 0); in PS_READ_FUNC()
376 *val = zend_string_init(sd->data, sd->datalen, 0); in PS_READ_FUNC()
380 mm_unlock(data->mm); in PS_READ_FUNC()
390 mm_lock(data->mm, MM_LOCK_RW); in PS_WRITE_FUNC()
392 sd = ps_sd_lookup(data, key->val, 1); in PS_WRITE_FUNC()
394 sd = ps_sd_new(data, key->val); in PS_WRITE_FUNC()
400 if (data->mm) { in PS_WRITE_FUNC()
401 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
404 sd->data = mm_malloc(data->mm, sd->alloclen); in PS_WRITE_FUNC()
406 if (!sd->data) { in PS_WRITE_FUNC()
407 ps_sd_destroy(data, sd); in PS_WRITE_FUNC()
414 memcpy(sd->data, val->val, val->len); in PS_WRITE_FUNC()
419 mm_unlock(data->mm); in PS_WRITE_FUNC()
429 mm_lock(data->mm, MM_LOCK_RW); in PS_DESTROY_FUNC()
431 sd = ps_sd_lookup(data, key->val, 0); in PS_DESTROY_FUNC()
433 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
436 mm_unlock(data->mm); in PS_DESTROY_FUNC()
455 mm_lock(data->mm, MM_LOCK_RW); in PS_GC_FUNC()
457 ehash = data->hash + data->hash_max + 1; in PS_GC_FUNC()
458 for (ohash = data->hash; ohash < ehash; ohash++) { in PS_GC_FUNC()
463 ps_sd_destroy(data, sd); in PS_GC_FUNC()
469 mm_unlock(data->mm); in PS_GC_FUNC()
481 sid = php_session_create_id((void **)&data); in PS_CREATE_SID_FUNC()
483 if (ps_mm_key_exists(data, sid->val) == SUCCESS) { in PS_CREATE_SID_FUNC()