/** * Sets keys in a given set * @arg set_name The name of the set * @arg keys A list of points to character arrays to add * @arg num_keys The number of keys to add * * @return 0 on success, -1 if the set does not exist. * -2 on internal error. */ int setmgr_set_keys(hlld_setmgr *mgr, char *set_name, char **keys, int num_keys) { // Get the set hlld_set_wrapper *set = take_set(mgr, set_name); if (!set) return -1; // Acquire the READ lock. We use the read lock // since we can handle concurrent writes. pthread_rwlock_rdlock(&set->rwlock); // Set the keys, store the results int res = 0; for (int i=0; i<num_keys; i++) { res = hset_add(set->set, keys[i]); if (res) break; } // Mark as hot set->is_hot = 1; // Release the lock pthread_rwlock_unlock(&set->rwlock); return (res == -1) ? -2 : 0; }
inline char *motopp_strdup(MotoPP *ppenv, const char *s) { char *dup = estrdup((char*)s); hset_add(ppenv->ptrs, dup); return dup; }
void * moto_malloc(MotoEnv *env, size_t size) { void *r = emalloc(size); hset_add(env->ptrs, r); return r; }
MotoPPVal *motopp_createVal(MotoPP *ppenv) { MotoPPVal *val; val = ecalloc(1,sizeof(MotoPPVal)); hset_add(ppenv->vallist, val); return val; }
char * moto_strdup(MotoEnv *env, char *s) { char *dup = estrdup(s); hset_add(env->ptrs, dup); return dup; }