comparison 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
comparison
equal deleted inserted replaced
1886:f7d408a47752 1887:09860ba329a4
1781 return icon_pixbuf; 1781 return icon_pixbuf;
1782 } 1782 }
1783 return NULL; 1783 return NULL;
1784 } 1784 }
1785 1785
1786 void _init_thread(void)
1787 {
1788 GdkRGBA *foreground = malloc(sizeof(GdkRGBA));
1789
1790 foreground->alpha = foreground->red = foreground->green = foreground->blue = 0.0;
1791 pthread_setspecific(_dw_fg_color_key, foreground);
1792 pthread_setspecific(_dw_bg_color_key, NULL);
1793 }
1794
1795 /* Try to load the WebKitGtk shared libary */ 1786 /* Try to load the WebKitGtk shared libary */
1796 #ifdef USE_WEBKIT 1787 #ifdef USE_WEBKIT
1797 void init_webkit(void) 1788 void init_webkit(void)
1798 { 1789 {
1799 char libname[100]; 1790 char libname[100];
1877 1868
1878 pthread_key_create(&_dw_fg_color_key, NULL); 1869 pthread_key_create(&_dw_fg_color_key, NULL);
1879 pthread_key_create(&_dw_bg_color_key, NULL); 1870 pthread_key_create(&_dw_bg_color_key, NULL);
1880 pthread_key_create(&_dw_mutex_key, NULL); 1871 pthread_key_create(&_dw_mutex_key, NULL);
1881 1872
1882 _init_thread(); 1873 _dw_init_thread();
1883 1874
1884 /* Create a global object for glib activities */ 1875 /* Create a global object for glib activities */
1885 _DWObject = g_object_new(G_TYPE_OBJECT, NULL); 1876 _DWObject = g_object_new(G_TYPE_OBJECT, NULL);
1886 1877
1887 #ifdef USE_WEBKIT 1878 #ifdef USE_WEBKIT
8321 */ 8312 */
8322 close(GPOINTER_TO_INT(eve)); 8313 close(GPOINTER_TO_INT(eve));
8323 return DW_ERROR_NONE; 8314 return DW_ERROR_NONE;
8324 } 8315 }
8325 8316
8326 /* 8317 /*
8327 * Setup thread independent color sets. 8318 * Generally an internal function called from a newly created
8328 */ 8319 * thread to setup the Dynamic Windows environment for the thread.
8329 void _dwthreadstart(void *data) 8320 * However it is exported so language bindings can call it when
8330 { 8321 * they create threads that require access to Dynamic Windows.
8331 void (*threadfunc)(void *) = NULL; 8322 */
8332 void **tmp = (void **)data; 8323 void API _dw_init_thread(void)
8324 {
8325 GdkRGBA *foreground = malloc(sizeof(GdkRGBA));
8326
8327 foreground->alpha = foreground->red = foreground->green = foreground->blue = 0.0;
8328 pthread_setspecific(_dw_fg_color_key, foreground);
8329 pthread_setspecific(_dw_bg_color_key, NULL);
8330 }
8331
8332 /*
8333 * Generally an internal function called from a terminating
8334 * thread to cleanup the Dynamic Windows environment for the thread.
8335 * However it is exported so language bindings can call it when
8336 * they exit threads that require access to Dynamic Windows.
8337 */
8338 void API _dw_deinit_thread(void)
8339 {
8333 GdkRGBA *foreground, *background; 8340 GdkRGBA *foreground, *background;
8334 8341
8335 threadfunc = (void (*)(void *))tmp[0];
8336
8337 /* Initialize colors */
8338 _init_thread();
8339
8340 threadfunc(tmp[1]);
8341 free(tmp);
8342
8343 /* Free colors */
8344 if((foreground = pthread_getspecific(_dw_fg_color_key))) 8342 if((foreground = pthread_getspecific(_dw_fg_color_key)))
8345 free(foreground); 8343 free(foreground);
8346 if((background = pthread_getspecific(_dw_bg_color_key))) 8344 if((background = pthread_getspecific(_dw_bg_color_key)))
8347 free(background); 8345 free(background);
8346 }
8347
8348 /*
8349 * Setup thread independent color sets.
8350 */
8351 void _dwthreadstart(void *data)
8352 {
8353 void (*threadfunc)(void *) = NULL;
8354 void **tmp = (void **)data;
8355
8356 threadfunc = (void (*)(void *))tmp[0];
8357
8358 /* Initialize colors */
8359 _dw_init_thread();
8360
8361 threadfunc(tmp[1]);
8362 free(tmp);
8363
8364 /* Free colors */
8365 _dw_deinit_thread();
8348 } 8366 }
8349 8367
8350 /* 8368 /*
8351 * Allocates a shared memory region with a name. 8369 * Allocates a shared memory region with a name.
8352 * Parameters: 8370 * Parameters: