/* temporary workaround to generate ids */ static void _gen_item_id(SEXP_t *item) { static uint32_t id = 0; SEXP_t sid, *name_ref, *tmp; SEXP_string_newf_r(&sid, "1%05u%u", getpid(), ++id); name_ref = SEXP_listref_first(item); tmp = SEXP_list_replace(name_ref, 3, &sid); SEXP_vfree(name_ref, tmp, NULL); SEXP_free_r(&sid); }
static void probe_icache_item_setID(SEXP_t *item, SEXP_ID_t item_ID) { SEXP_t *name_ref, *prev_id; SEXP_t uniq_id; uint32_t local_id; /* ((foo_item :id "<int>") ... ) */ assume_d(item != NULL, /* void */); assume_d(SEXP_listp(item), /* void */); #if defined(HAVE_ATOMIC_FUNCTIONS) local_id = __sync_fetch_and_add(&next_ID, 1); #else if (pthread_mutex_lock(&next_ID_mutex) != 0) { dE("Can't lock the next_ID_mutex: %u, %s", errno, strerror(errno)); abort(); } local_id = ++next_ID; if (pthread_mutex_unlock(&next_ID_mutex) != 0) { dE("Can't unlock the next_ID_mutex: %u, %s", errno, strerror(errno)); abort(); } #endif SEXP_string_newf_r(&uniq_id, "1%05u%u", getpid(), local_id); name_ref = SEXP_listref_first(item); prev_id = SEXP_list_replace(name_ref, 3, &uniq_id); SEXP_free(prev_id); SEXP_free_r(&uniq_id); SEXP_free(name_ref); return; }