@@ -264,7 +264,7 @@ static void _dictRehashStep(dict *d) {
264264/* Add an element to the target hash table */
265265int dictAdd (dict * d , void * key , void * val )
266266{
267- dictEntry * entry = dictAddRaw (d ,key ,NULL );
267+ dictEntry * entry = dictAddRaw (d ,key ,NULL , 0 );
268268
269269 if (!entry ) return DICT_ERR ;
270270 dictSetVal (d , entry , val );
@@ -289,7 +289,7 @@ int dictAdd(dict *d, void *key, void *val)
289289 *
290290 * If key was added, the hash entry is returned to be manipulated by the caller.
291291 */
292- dictEntry * dictAddRaw (dict * d , void * key , dictEntry * * existing )
292+ dictEntry * dictAddRaw (dict * d , void * key , dictEntry * * existing , int dictionaryEntriesOnPmem )
293293{
294294 long index ;
295295 dictEntry * entry ;
@@ -307,7 +307,10 @@ dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
307307 * system it is more likely that recently added entries are accessed
308308 * more frequently. */
309309 ht = dictIsRehashing (d ) ? & d -> ht [1 ] : & d -> ht [0 ];
310- entry = zmalloc (sizeof (* entry ));
310+ if (dictionaryEntriesOnPmem )
311+ entry = zmalloc_pmem (sizeof (* entry ));
312+ else
313+ entry = zmalloc (sizeof (* entry ));
311314 entry -> next = ht -> table [index ];
312315 ht -> table [index ] = entry ;
313316 ht -> used ++ ;
@@ -317,6 +320,29 @@ dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing)
317320 return entry ;
318321}
319322
323+ #ifdef USE_MEMKIND
324+ int dictAddPM (dict * d , void * key , void * val )
325+ {
326+ dictEntry * entry = dictAddRaw (d ,key ,NULL ,1 );
327+
328+ if (!entry ) return DICT_ERR ;
329+ dictSetVal (d , entry , val );
330+ return DICT_OK ;
331+ }
332+
333+ #else
334+ int dictAddPM (dict * d , void * key , void * val )
335+ {
336+ (void )(d );
337+ (void )(key );
338+ (void )(val );
339+ printf ("ERROR: dictAddPM is supported only by memkind\n" );
340+ exit (1 );
341+ /* unreachable */
342+ return NULL ;
343+ }
344+ #endif
345+
320346/* Add or Overwrite:
321347 * Add an element, discarding the old value if the key already exists.
322348 * Return 1 if the key was added from scratch, 0 if there was already an
@@ -328,7 +354,7 @@ int dictReplace(dict *d, void *key, void *val)
328354
329355 /* Try to add the element. If the key
330356 * does not exists dictAdd will succeed. */
331- entry = dictAddRaw (d ,key ,& existing );
357+ entry = dictAddRaw (d ,key ,& existing , 0 );
332358 if (entry ) {
333359 dictSetVal (d , entry , val );
334360 return 1 ;
@@ -352,9 +378,9 @@ int dictReplace(dict *d, void *key, void *val)
352378 * existing key is returned.)
353379 *
354380 * See dictAddRaw() for more information. */
355- dictEntry * dictAddOrFind (dict * d , void * key ) {
381+ dictEntry * dictAddOrFind (dict * d , void * key , int dictionaryEntriesOnPmem ) {
356382 dictEntry * entry , * existing ;
357- entry = dictAddRaw (d ,key ,& existing );
383+ entry = dictAddRaw (d ,key ,& existing , dictionaryEntriesOnPmem );
358384 return entry ? entry : existing ;
359385}
360386
0 commit comments