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 …LL TSRMLS_CC, E_WARNING, "mm_malloc failed, avail %d, 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()
215 #define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
217 static int ps_mm_initialize(ps_mm *data, const char *path) in ps_mm_initialize() argument
219 data->owner = getpid(); in ps_mm_initialize()
220 data->mm = mm_create(0, path); in ps_mm_initialize()
221 if (!data->mm) { in ps_mm_initialize()
225 data->hash_cnt = 0; in ps_mm_initialize()
226 data->hash_max = 511; in ps_mm_initialize()
227 data->hash = mm_calloc(data->mm, data->hash_max + 1, sizeof(ps_sd *)); in ps_mm_initialize()
228 if (!data->hash) { in ps_mm_initialize()
229 mm_destroy(data->mm); in ps_mm_initialize()
236 static void ps_mm_destroy(ps_mm *data) in ps_mm_destroy() argument
244 if (data->owner != getpid()) { in ps_mm_destroy()
248 for (h = 0; h < data->hash_max + 1; h++) { in ps_mm_destroy()
249 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
251 ps_sd_destroy(data, sd); in ps_mm_destroy()
255 mm_free(data->mm, data->hash); in ps_mm_destroy()
256 mm_destroy(data->mm); in ps_mm_destroy()
257 free(data); in ps_mm_destroy()
342 mm_lock(data->mm, MM_LOCK_RD); in PS_READ_FUNC()
344 sd = ps_sd_lookup(data, key, 0); in PS_READ_FUNC()
348 memcpy(*val, sd->data, sd->datalen); in PS_READ_FUNC()
353 mm_unlock(data->mm); in PS_READ_FUNC()
363 mm_lock(data->mm, MM_LOCK_RW); in PS_WRITE_FUNC()
365 sd = ps_sd_lookup(data, key, 1); in PS_WRITE_FUNC()
367 sd = ps_sd_new(data, key); in PS_WRITE_FUNC()
373 if (data->mm) { in PS_WRITE_FUNC()
374 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
377 sd->data = mm_malloc(data->mm, sd->alloclen); in PS_WRITE_FUNC()
379 if (!sd->data) { in PS_WRITE_FUNC()
380 ps_sd_destroy(data, sd); in PS_WRITE_FUNC()
387 memcpy(sd->data, val, vallen); in PS_WRITE_FUNC()
392 mm_unlock(data->mm); in PS_WRITE_FUNC()
402 mm_lock(data->mm, MM_LOCK_RW); in PS_DESTROY_FUNC()
404 sd = ps_sd_lookup(data, key, 0); in PS_DESTROY_FUNC()
406 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
409 mm_unlock(data->mm); in PS_DESTROY_FUNC()
428 mm_lock(data->mm, MM_LOCK_RW); in PS_GC_FUNC()
430 ehash = data->hash + data->hash_max + 1; in PS_GC_FUNC()
431 for (ohash = data->hash; ohash < ehash; ohash++) { in PS_GC_FUNC()
436 ps_sd_destroy(data, sd); in PS_GC_FUNC()
442 mm_unlock(data->mm); in PS_GC_FUNC()