Mercurial > dwindows
comparison mac/dw.m @ 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 | fafe1a68f0fd |
comparison
equal
deleted
inserted
replaced
1886:f7d408a47752 | 1887:09860ba329a4 |
---|---|
10909 pool = [[NSAutoreleasePool alloc] init]; | 10909 pool = [[NSAutoreleasePool alloc] init]; |
10910 pthread_setspecific(_dw_pool_key, pool); | 10910 pthread_setspecific(_dw_pool_key, pool); |
10911 #endif | 10911 #endif |
10912 } | 10912 } |
10913 | 10913 |
10914 /* | 10914 /* |
10915 * Setup thread independent pools. | 10915 * Generally an internal function called from a newly created |
10916 */ | 10916 * thread to setup the Dynamic Windows environment for the thread. |
10917 void _dwthreadstart(void *data) | 10917 * However it is exported so language bindings can call it when |
10918 { | 10918 * they create threads that require access to Dynamic Windows. |
10919 void (*threadfunc)(void *) = NULL; | 10919 */ |
10920 void **tmp = (void **)data; | 10920 void API _dw_init_thread(void) |
10921 NSColor *color; | 10921 { |
10922 | |
10923 /* If we aren't using garbage collection we need autorelease pools */ | 10922 /* If we aren't using garbage collection we need autorelease pools */ |
10924 #if !defined(GARBAGE_COLLECT) | 10923 #if !defined(GARBAGE_COLLECT) |
10925 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | 10924 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
10926 pthread_setspecific(_dw_pool_key, pool); | 10925 pthread_setspecific(_dw_pool_key, pool); |
10927 #endif | 10926 #endif |
10928 _init_colors(); | 10927 _init_colors(); |
10929 | 10928 } |
10930 threadfunc = (void (*)(void *))tmp[0]; | 10929 |
10931 | 10930 /* |
10932 /* Start our thread function */ | 10931 * Generally an internal function called from a terminating |
10933 threadfunc(tmp[1]); | 10932 * thread to cleanup the Dynamic Windows environment for the thread. |
10934 | 10933 * However it is exported so language bindings can call it when |
10934 * they exit threads that require access to Dynamic Windows. | |
10935 */ | |
10936 void API _dw_deinit_thread(void) | |
10937 { | |
10938 NSColor *color; | |
10939 | |
10935 /* Release the pool when we are done so we don't leak */ | 10940 /* Release the pool when we are done so we don't leak */ |
10936 color = pthread_getspecific(_dw_fg_color_key); | 10941 color = pthread_getspecific(_dw_fg_color_key); |
10937 [color release]; | 10942 [color release]; |
10938 color = pthread_getspecific(_dw_bg_color_key); | 10943 color = pthread_getspecific(_dw_bg_color_key); |
10939 [color release]; | 10944 [color release]; |
10940 #if !defined(GARBAGE_COLLECT) | 10945 #if !defined(GARBAGE_COLLECT) |
10941 pool = pthread_getspecific(_dw_pool_key); | 10946 pool = pthread_getspecific(_dw_pool_key); |
10942 [pool drain]; | 10947 [pool drain]; |
10943 #endif | 10948 #endif |
10949 } | |
10950 | |
10951 /* | |
10952 * Setup thread independent pools. | |
10953 */ | |
10954 void _dwthreadstart(void *data) | |
10955 { | |
10956 void (*threadfunc)(void *) = NULL; | |
10957 void **tmp = (void **)data; | |
10958 | |
10959 _dw_init_thread(); | |
10960 | |
10961 threadfunc = (void (*)(void *))tmp[0]; | |
10962 | |
10963 /* Start our thread function */ | |
10964 threadfunc(tmp[1]); | |
10965 | |
10944 free(tmp); | 10966 free(tmp); |
10967 | |
10968 _dw_deinit_thread(); | |
10945 } | 10969 } |
10946 | 10970 |
10947 /* | 10971 /* |
10948 * Sets the default font used on text based widgets. | 10972 * Sets the default font used on text based widgets. |
10949 * Parameters: | 10973 * Parameters: |