Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2006 - 2007 Pekka Riikonen
+ Copyright (C) 2006 - 2008 Pekka Riikonen
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
*/
-#include "silc.h"
+#include "silcruntime.h"
#include <e32base.h>
#include <e32std.h>
+/************************ Static utility functions **************************/
+
+static SilcTls silc_thread_tls_init_shared(SilcTls other);
+
/**************************** SILC Thread API *******************************/
extern "C" {
SilcThreadStart start_func;
void *context;
SilcBool waitable;
-#else
- void *tmp;
#endif
+ SilcTls tls;
};
/* The actual thread function */
SilcThreadStart start_func = tc->start_func;
void *user_context = tc->context;
SilcBool waitable = tc->waitable;
+ SilcTls tls, other = tc->tls;
void *ret = NULL;
- SilcTls tls;
silc_free(tc);
- tls = silc_thread_tls_init();
+ tls = silc_thread_tls_init_shared(other);
CTrapCleanup *cs = CTrapCleanup::New();
if (cs) {
delete cs;
}
+ if (tls->tls_variables)
+ silc_hash_table_free(tls->tls_variables);
silc_free(tls);
silc_thread_exit(ret);
Dll::SetTls(tls);
+ /* Allocate global lock */
+ silc_mutex_alloc(&tls->lock);
+
+ return tls;
+}
+
+static SilcTls silc_thread_tls_init_shared(SilcTls other)
+{
+ SilcTls tls;
+
+ if (silc_thread_get_tls())
+ return silc_thread_get_tls();
+
+ /* Allocate Tls for the thread */
+ tls = (SilcTls)silc_calloc(1, sizeof(*tls));
+ if (!tls)
+ return NULL;
+
+ Dll::SetTls(tls);
+
+ /* Take shared data */
+ tls->shared_data = 1;
+ tls->lock = other->lock;
+ tls->variables = other->variables;
+
return tls;
}
return STATIC_CAST(SilcTls, Dll::Tls());
}
+void silc_thread_tls_uninit(void)
+{
+ SilcTls tls = silc_thread_get_tls();
+
+ if (!tls || tls->shared_data)
+ return;
+
+ if (tls->tls_variables)
+ silc_hash_table_free(tls->tls_variables);
+ if (tls->variables)
+ silc_hash_table_free(tls->variables);
+ if (tls->lock)
+ silc_mutex_free(tls->lock);
+
+ tls->variables = NULL;
+ tls->lock = NULL;
+}
+
} /* extern "C" */