/* * Copyright © 2024 Nick Bowler * * Helpers for hosts using standard C threading API. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include static tss_t tls_key; static bool tls_key_valid; static void init_once_cb(void); static void *tls_get(void) { return tss_get(tls_key); } static int tls_set(void *p) { return tss_set(tls_key, p) == thrd_success; } static void init_once_with_tls(void) { tls_key_valid = (tss_create(&tls_key, free) == thrd_success); init_once_cb(); } static int init_once(void) { static once_flag flag; call_once(&flag, init_once_with_tls); return 1; }