diff options
author | Chad Versace <chad.versace@linux.intel.com> | 2013-07-10 21:59:37 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@linux.intel.com> | 2013-07-19 19:14:21 -0700 |
commit | d56440ca5f26cabb4f05744650ef532faf060786 (patch) | |
tree | e983b7f54b39fe54519746f3848289dc0234fb1a | |
parent | 7fc45480fc6dadfdbdf55b4c9042edadb57c8376 (diff) |
core: Refactor wcore_tinfo.c
The refactor prepares for supporting environments without TLS and
introduces no behavioral change.
Tested on Mac OS with XCode 3.1 gcc and XCode 4.6.2 clang by Nigel.
Tested-by: Nigel Stewart <nigelstewart@gmail.com>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r-- | src/waffle/core/wcore_tinfo.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/waffle/core/wcore_tinfo.c b/src/waffle/core/wcore_tinfo.c index e40cb30..654802e 100644 --- a/src/waffle/core/wcore_tinfo.c +++ b/src/waffle/core/wcore_tinfo.c @@ -55,31 +55,32 @@ static __thread struct wcore_tinfo wcore_tinfo #endif ; +static void __attribute__((noreturn)) +wcore_tinfo_abort_init(void) +{ + printf("waffle: fatal-error: failed to initialize thread local info\n"); + abort(); +} + static void -wcore_tinfo_init(void) +wcore_tinfo_init(struct wcore_tinfo *tinfo) { - assert(!wcore_tinfo.is_init); + if (tinfo->is_init) + return; // FIXME: wcore_tinfo.error leaks at thread exit. To fix this, Waffle // FIXME: needs a function like eglTerminate(). - wcore_tinfo.error = wcore_error_tinfo_create(); - if (!wcore_tinfo.error) - goto error; + tinfo->error = wcore_error_tinfo_create(); + if (!tinfo->error) + wcore_tinfo_abort_init(); - wcore_tinfo.is_init = true; - return; - -error: - printf("waffle: fatal-error: failed to initialize thread local info\n"); - abort(); + tinfo->is_init = true; } struct wcore_tinfo* wcore_tinfo_get(void) { - if (!wcore_tinfo.is_init) - wcore_tinfo_init(); - + wcore_tinfo_init(&wcore_tinfo); return &wcore_tinfo; } |