Skip to content

Commit

Permalink
Lazy TLS init for static library case
Browse files Browse the repository at this point in the history
  • Loading branch information
bozzzzo committed Sep 17, 2014
1 parent 470ab70 commit 9712238
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libkqueue/src/windows/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static __thread struct event_buf iocp_buf;
* kevent_wait() and kevent_copyout().
*/
#define iocp_buf (*_iocp_buf())
static DWORD event_buf_tls;
static DWORD event_buf_tls = 0;
static int event_buf_tls_init = 0;


// workaround for implicit TLS initialization
Expand All @@ -54,6 +55,8 @@ void libkqueue_thread_attach(){
}

struct event_buf *_iocp_buf() {
if (!event_buf_tls_init)
libkqueue_process_attach();
struct event_buf* ev_buf = ((struct event_buf*)TlsGetValue(event_buf_tls));
if (!ev_buf) {
dbg_puts("AAARrrr, no iocp_buf? fixing up missing libkqueue_thread_attach");
Expand All @@ -70,6 +73,7 @@ void libkqueue_thread_detach(){

void libkqueue_process_attach(){
event_buf_tls = TlsAlloc();
event_buf_tls_init = 1;
libkqueue_thread_attach();
}

Expand Down

0 comments on commit 9712238

Please sign in to comment.