Mercurial > dwindows
diff gtk3/dw.c @ 1887:09860ba329a4
Divided thread initialization and deinitialization into separate
exported functions so they can be accessed from language bindings.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 09 Sep 2013 19:18:36 +0000 |
parents | f7d408a47752 |
children | 0f3df50bfc4f |
line wrap: on
line diff
--- a/gtk3/dw.c Thu Sep 05 17:58:40 2013 +0000 +++ b/gtk3/dw.c Mon Sep 09 19:18:36 2013 +0000 @@ -1783,15 +1783,6 @@ return NULL; } -void _init_thread(void) -{ - GdkRGBA *foreground = malloc(sizeof(GdkRGBA)); - - foreground->alpha = foreground->red = foreground->green = foreground->blue = 0.0; - pthread_setspecific(_dw_fg_color_key, foreground); - pthread_setspecific(_dw_bg_color_key, NULL); -} - /* Try to load the WebKitGtk shared libary */ #ifdef USE_WEBKIT void init_webkit(void) @@ -1879,7 +1870,7 @@ pthread_key_create(&_dw_bg_color_key, NULL); pthread_key_create(&_dw_mutex_key, NULL); - _init_thread(); + _dw_init_thread(); /* Create a global object for glib activities */ _DWObject = g_object_new(G_TYPE_OBJECT, NULL); @@ -8323,6 +8314,37 @@ return DW_ERROR_NONE; } +/* + * Generally an internal function called from a newly created + * thread to setup the Dynamic Windows environment for the thread. + * However it is exported so language bindings can call it when + * they create threads that require access to Dynamic Windows. + */ +void API _dw_init_thread(void) +{ + GdkRGBA *foreground = malloc(sizeof(GdkRGBA)); + + foreground->alpha = foreground->red = foreground->green = foreground->blue = 0.0; + pthread_setspecific(_dw_fg_color_key, foreground); + pthread_setspecific(_dw_bg_color_key, NULL); +} + +/* + * Generally an internal function called from a terminating + * thread to cleanup the Dynamic Windows environment for the thread. + * However it is exported so language bindings can call it when + * they exit threads that require access to Dynamic Windows. + */ +void API _dw_deinit_thread(void) +{ + GdkRGBA *foreground, *background; + + if((foreground = pthread_getspecific(_dw_fg_color_key))) + free(foreground); + if((background = pthread_getspecific(_dw_bg_color_key))) + free(background); +} + /* * Setup thread independent color sets. */ @@ -8330,21 +8352,17 @@ { void (*threadfunc)(void *) = NULL; void **tmp = (void **)data; - GdkRGBA *foreground, *background; threadfunc = (void (*)(void *))tmp[0]; /* Initialize colors */ - _init_thread(); + _dw_init_thread(); threadfunc(tmp[1]); free(tmp); /* Free colors */ - if((foreground = pthread_getspecific(_dw_fg_color_key))) - free(foreground); - if((background = pthread_getspecific(_dw_bg_color_key))) - free(background); + _dw_deinit_thread(); } /*