| 2213 | static _Atomic(go_stdlib_holder_t *) g_go_stdlib_shared; |
| 2214 | |
| 2215 | static const CBMTypeRegistry *go_stdlib_shared(void) { |
| 2216 | go_stdlib_holder_t *ready = atomic_load_explicit(&g_go_stdlib_shared, memory_order_acquire); |
| 2217 | if (ready) |
| 2218 | return &ready->reg; |
| 2219 | go_stdlib_holder_t *built = cbm_calloc(CBM_MEM_CLASS_OTHER, sizeof(*built)); |
| 2220 | if (!built) |
| 2221 | return NULL; |
| 2222 | cbm_arena_init(&built->arena); |
| 2223 | if (built->arena.nblocks == 0) { |
| 2224 | cbm_free(CBM_MEM_CLASS_OTHER, built); |
| 2225 | return NULL; |
| 2226 | } |
| 2227 | cbm_registry_init(&built->reg, &built->arena); |
| 2228 | cbm_go_stdlib_register(&built->reg, &built->arena); |
| 2229 | cbm_registry_finalize(&built->reg); |
| 2230 | built->reg.read_only = true; |
| 2231 | go_stdlib_holder_t *expected = NULL; |
| 2232 | if (atomic_compare_exchange_strong_explicit(&g_go_stdlib_shared, &expected, built, |
| 2233 | memory_order_acq_rel, memory_order_acquire)) { |
| 2234 | return &built->reg; |
| 2235 | } |
| 2236 | cbm_arena_destroy(&built->arena); |
| 2237 | cbm_free(CBM_MEM_CLASS_OTHER, built); |
| 2238 | return &expected->reg; |
| 2239 | } |
| 2240 | |
| 2241 | /* A per-file registry sees the stdlib: chained to the shared copy, or |
| 2242 | * registered into it when the shared copy cannot be built. */ |
no test coverage detected