96 {
97
101
102
103
104
105
106 for (;;) {
108
109
110 int len = snprintf(
nullptr, 0,
"gensym_%" PRIu64,
id);
112
113
115 (void)snprintf(name,
len + 1,
"gensym_%" PRIu64,
id);
116
119
121
123 hmap_t *table = atomic_load_explicit(&ns->sym_table, memory_order_relaxed);
124
125 if (hmap_lookup(table, &k, nullptr) == nullptr) {
126
127
128
129 sym = srn_symbol_make(ns->root_context, metadata, ns, AS_STRING(sym_name));
130
131 hmap_t *next = ALLOC_OR_PANIC(ns->root_context, hmap_t);
132 *next = hmap_insert(table, &k, (void *)sym);
133 atomic_store_explicit(&ns->sym_table, next, memory_order_release);
134 }
135 });
136
137
138 if (sym != nullptr) {
139 return sym;
140 }
141 }
142}
void * srn_allocate(const srn_context_t *ctx, size_t size, size_t alignment)
Allocate size bytes aligned to alignment from the context's memory block.
#define AS_STRING(value_ref)
srn_object_id_t srn_allocate_object_id(srn_engine_t *engine)
#define WITH_LOCK(lock, body)
Run body with lock held.
srn_value_t * srn_string_make(srn_context_t *ctx, srn_metadata_t *metadata, const char *src)
Create a string from a null terminated C string.
Note: For key equality we use the memcpy function.
srn_engine_t * engine
Long term state of the compiler.
srn_fiber_mutex_t * sym_table_lock
Only when setting the sym_table hmap it self.
#define PANIC_IF_NULL(ptr)
#define PANIC_IF(cond, msg)