[seed] Use POSIX thread-local storage API instead of GCC extensions
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seed] Use POSIX thread-local storage API instead of GCC extensions
- Date: Wed, 30 Dec 2009 08:13:34 +0000 (UTC)
commit 1118eb7835ba0b94aee09f9f576342fcce344128
Author: Tim Horton <hortont424 gmail com>
Date: Wed Dec 30 02:39:26 2009 -0500
Use POSIX thread-local storage API instead of GCC extensions
This is necessary to make Seed build on platforms where the GCC
TLS API is not available, such as Mac OS X.
libseed/seed-engine.c | 16 ++++++++++------
libseed/seed-engine.h | 2 +-
libseed/seed-types.c | 7 ++++---
3 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index eda95b3..4c61eb2 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -24,6 +24,7 @@
#include <sys/wait.h>
#include <stdarg.h>
#include <string.h>
+#include <pthread.h>
#include "config.h"
@@ -49,8 +50,7 @@ GQuark js_ref_quark;
guint seed_debug_flags = 0; /* global seed debug flag */
gboolean seed_arg_print_version = FALSE; // Flag to print version and quit
-__thread JSObjectRef seed_next_gobject_wrapper = NULL;
-
+pthread_key_t seed_next_gobject_wrapper_key;
#ifdef SEED_ENABLE_DEBUG
static const GDebugKey seed_debug_keys[] = {
@@ -187,7 +187,9 @@ seed_gobject_constructor_invoked (JSContextRef ctx,
SEED_NOTE (INITIALIZATION, "Constructing object of type %s",
g_type_name (type));
- seed_next_gobject_wrapper = seed_make_wrapper_for_type (ctx, type);
+
+ pthread_setspecific (seed_next_gobject_wrapper_key,
+ seed_make_wrapper_for_type (ctx, type));
while (i < nparams)
{
@@ -206,7 +208,7 @@ seed_gobject_constructor_invoked (JSContextRef ctx,
if (param_spec == NULL)
{
- JSObjectSetProperty (ctx, seed_next_gobject_wrapper, jsprop_name,
+ JSObjectSetProperty (ctx, pthread_getspecific(seed_next_gobject_wrapper_key), jsprop_name,
jsprop_value, 0, NULL);
++i;
continue;
@@ -225,7 +227,7 @@ seed_gobject_constructor_invoked (JSContextRef ctx,
{
g_free (params);
JSPropertyNameArrayRelease (jsprops);
- seed_next_gobject_wrapper = NULL;
+ pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
return 0;
}
params[ri].name = prop_name;
@@ -936,7 +938,8 @@ seed_gobject_set_property (JSContextRef context,
gsize length;
gsize i, len;
- if (seed_next_gobject_wrapper || JSValueIsNull (context, value))
+ if (pthread_getspecific(seed_next_gobject_wrapper_key) ||
+ JSValueIsNull (context, value))
return 0;
@@ -1445,6 +1448,7 @@ SeedEngine *
seed_init (gint * argc, gchar *** argv)
{
context_group = JSContextGroupCreate ();
+ pthread_key_create(&seed_next_gobject_wrapper_key, NULL);
return seed_init_with_context_group (argc, argv, context_group);
}
diff --git a/libseed/seed-engine.h b/libseed/seed-engine.h
index 665578f..ce7dcea 100644
--- a/libseed/seed-engine.h
+++ b/libseed/seed-engine.h
@@ -29,7 +29,7 @@ extern JSClassRef gobject_named_constructor_class;
extern JSClassRef seed_struct_constructor_class;
extern JSClassRef gobject_init_method_class;
-extern __thread JSObjectRef seed_next_gobject_wrapper;
+extern pthread_key_t seed_next_gobject_wrapper_key;
extern JSClassRef seed_callback_class;
extern SeedEngine *eng;
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index 77b709a..01d9c51 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -19,6 +19,7 @@
#include "seed-private.h"
#include <dlfcn.h>
+#include <pthread.h>
JSClassRef gobject_class;
JSClassRef gobject_method_class;
@@ -99,8 +100,8 @@ seed_wrap_object (JSContextRef ctx, GObject * object)
if (user_data)
return user_data;
- if (seed_next_gobject_wrapper)
- js_ref = seed_next_gobject_wrapper;
+ if (pthread_getspecific(seed_next_gobject_wrapper_key))
+ js_ref = pthread_getspecific(seed_next_gobject_wrapper_key);
else
js_ref = seed_make_wrapper_for_type (ctx, type);
@@ -114,7 +115,7 @@ seed_wrap_object (JSContextRef ctx, GObject * object)
seed_add_signals_to_object (ctx, js_ref, object);
- seed_next_gobject_wrapper = NULL;
+ pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
return js_ref;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]