Lines Matching refs:sd
118 ps_sd *sd; in ps_sd_new() local
123 sd = mm_malloc(data->mm, sizeof(ps_sd) + keylen); in ps_sd_new()
124 if (!sd) { in ps_sd_new()
134 sd->ctime = 0; in ps_sd_new()
135 sd->hv = hv; in ps_sd_new()
136 sd->data = NULL; in ps_sd_new()
137 sd->alloclen = sd->datalen = 0; in ps_sd_new()
139 memcpy(sd->key, key, keylen + 1); in ps_sd_new()
141 sd->next = data->hash[slot]; in ps_sd_new()
142 data->hash[slot] = sd; in ps_sd_new()
146 if (!sd->next) { in ps_sd_new()
152 ps_mm_debug(("inserting %s(%p) into slot %d\n", key, sd, slot)); in ps_sd_new()
154 return sd; 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()
170 prev->next = sd->next; 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()
239 ps_sd *sd, *next; in ps_mm_destroy() local
249 for (sd = data->hash[h]; sd; sd = next) { in ps_mm_destroy()
250 next = sd->next; in ps_mm_destroy()
251 ps_sd_destroy(data, sd); in ps_mm_destroy()
339 ps_sd *sd; in PS_READ_FUNC() local
344 sd = ps_sd_lookup(data, key, 0); in PS_READ_FUNC()
345 if (sd) { in PS_READ_FUNC()
346 *vallen = sd->datalen; in PS_READ_FUNC()
347 *val = emalloc(sd->datalen + 1); in PS_READ_FUNC()
348 memcpy(*val, sd->data, sd->datalen); in PS_READ_FUNC()
349 (*val)[sd->datalen] = '\0'; in PS_READ_FUNC()
361 ps_sd *sd; in PS_WRITE_FUNC() local
365 sd = ps_sd_lookup(data, key, 1); in PS_WRITE_FUNC()
366 if (!sd) { in PS_WRITE_FUNC()
367 sd = ps_sd_new(data, key); in PS_WRITE_FUNC()
371 if (sd) { in PS_WRITE_FUNC()
372 if (vallen >= sd->alloclen) { in PS_WRITE_FUNC()
374 mm_free(data->mm, sd->data); in PS_WRITE_FUNC()
376 sd->alloclen = vallen + 1; 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()
382 sd = NULL; in PS_WRITE_FUNC()
385 if (sd) { in PS_WRITE_FUNC()
386 sd->datalen = vallen; in PS_WRITE_FUNC()
387 memcpy(sd->data, val, vallen); in PS_WRITE_FUNC()
388 time(&sd->ctime); in PS_WRITE_FUNC()
394 return sd ? SUCCESS : FAILURE; in PS_WRITE_FUNC()
400 ps_sd *sd; in PS_DESTROY_FUNC() local
404 sd = ps_sd_lookup(data, key, 0); in PS_DESTROY_FUNC()
405 if (sd) { in PS_DESTROY_FUNC()
406 ps_sd_destroy(data, sd); in PS_DESTROY_FUNC()
419 ps_sd *sd, *next; in PS_GC_FUNC() local
432 for (sd = *ohash; sd; sd = next) { in PS_GC_FUNC()
433 next = sd->next; in PS_GC_FUNC()
434 if (sd->ctime < limit) { in PS_GC_FUNC()
435 ps_mm_debug(("purging %s\n", sd->key)); in PS_GC_FUNC()
436 ps_sd_destroy(data, sd); in PS_GC_FUNC()