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()
127 …L TSRMLS_CC, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), mm_error()); in ps_sd_new()
132 slot = hv & data->hash_max; in ps_sd_new()
136 sd->data = NULL; in ps_sd_new()
141 sd->next = data->hash[slot]; in ps_sd_new()
142 data->hash[slot] = sd; in ps_sd_new()
144 data->hash_cnt++; in ps_sd_new()
147 if (data->hash_cnt >= data->hash_max) { in ps_sd_new()
148 hash_split(data); in ps_sd_new()
157 static void ps_sd_destroy(ps_mm *data, ps_sd *sd) in ps_sd_destroy() argument
161 slot = ps_sd_hash(sd->key, strlen(sd->key)) & data->hash_max; in ps_sd_destroy()
163 if (data->hash[slot] == sd) { in ps_sd_destroy()
164 data->hash[slot] = sd->next; in ps_sd_destroy()
169 for (prev = data->hash[slot]; prev->next != sd; prev = prev->next); in ps_sd_destroy()
173 data->hash_cnt--; in ps_sd_destroy()
175 if (sd->data) { in ps_sd_destroy()
176 mm_free(data->mm, sd->data); in ps_sd_destroy()
179 mm_free(data->mm, sd); in ps_sd_destroy()
182 static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw) in ps_sd_lookup() argument
188 slot = hv & data->hash_max; in ps_sd_lookup()
190 for (prev = NULL, ret = data->hash[slot]; ret; prev = ret, ret = ret->next) { in ps_sd_lookup()
196 if (ret && rw && ret != data->hash[slot]) { in ps_sd_lookup()
202 ret->next = data->hash[slot]; in ps_sd_lookup()
203 data->hash[slot] = ret; in ps_sd_lookup()
211 static int ps_mm_key_exists(ps_mm *data, const char *key TSRMLS_DC) in ps_mm_key_exists() argument
218 sd = ps_sd_lookup(data, key, 0); in ps_mm_key_exists()
229 #define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
231 static int ps_mm_initialize(ps_mm *data, const char *path) in ps_mm_initialize() argument
233 data->owner = getpid(); in ps_mm_initialize()
234 data->mm = mm_create(0, path); in ps_mm_initialize()
235 if (!data->mm) { in ps_mm_initialize()
239 data->hash_cnt = 0; in ps_mm_initialize()
240 data->hash_max = 511; in ps_mm_initialize()
241 data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *)); in ps_mm_initialize()
242 if (!data->hash) { in ps_mm_initialize()
243 mm_destroy(data->mm); in ps_mm_initialize()
250 static void ps_mm_destroy(ps_mm *data) in ps_mm_destroy() argument
258 if (data->owner != getpid()) { in ps_mm_destroy()
262 for (h = 0; h < data->hash_max + 1; h++) { in ps_mm_destroy()
263 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
265 ps_sd_destroy(data, sd); in ps_mm_destroy()
269 mm_free(data->mm, data->hash); in ps_mm_destroy()
270 mm_destroy(data->mm); in ps_mm_destroy()
271 free(data); in ps_mm_destroy()
356 mm_lock(data->mm, MM_LOCK_RD); in PS_READ_FUNC()
360 && ps_mm_key_exists(data, key TSRMLS_CC) == FAILURE) { in PS_READ_FUNC()
366 PS(id) = PS(mod)->s_create_sid((void **)&data, NULL TSRMLS_CC); in PS_READ_FUNC()
377 sd = ps_sd_lookup(data, PS(id), 0); in PS_READ_FUNC()
381 memcpy(*val, sd->data, sd->datalen); in PS_READ_FUNC()
386 mm_unlock(data->mm); in PS_READ_FUNC()
396 mm_lock(data->mm, MM_LOCK_RW); in PS_WRITE_FUNC()
398 sd = ps_sd_lookup(data, key, 1); in PS_WRITE_FUNC()
400 sd = ps_sd_new(data, key); in PS_WRITE_FUNC()
406 if (data->mm) { in PS_WRITE_FUNC()
407 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
410 sd->data = mm_malloc(data->mm, sd->alloclen); in PS_WRITE_FUNC()
412 if (!sd->data) { in PS_WRITE_FUNC()
413 ps_sd_destroy(data, sd); in PS_WRITE_FUNC()
420 memcpy(sd->data, val, vallen); in PS_WRITE_FUNC()
425 mm_unlock(data->mm); in PS_WRITE_FUNC()
435 mm_lock(data->mm, MM_LOCK_RW); in PS_DESTROY_FUNC()
437 sd = ps_sd_lookup(data, key, 0); in PS_DESTROY_FUNC()
439 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
442 mm_unlock(data->mm); in PS_DESTROY_FUNC()
461 mm_lock(data->mm, MM_LOCK_RW); in PS_GC_FUNC()
463 ehash = data->hash + data->hash_max + 1; in PS_GC_FUNC()
464 for (ohash = data->hash; ohash < ehash; ohash++) { in PS_GC_FUNC()
469 ps_sd_destroy(data, sd); in PS_GC_FUNC()
475 mm_unlock(data->mm); in PS_GC_FUNC()
487 sid = php_session_create_id((void **)&data, newlen TSRMLS_CC); in PS_CREATE_SID_FUNC()
489 if (ps_mm_key_exists(data, sid TSRMLS_CC) == SUCCESS) { in PS_CREATE_SID_FUNC()