Mercurial > dwindows
diff os2/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 | 0df3fc47002e |
line wrap: on
line diff
--- a/os2/dw.c Thu Sep 05 17:58:40 2013 +0000 +++ b/os2/dw.c Mon Sep 09 19:18:36 2013 +0000 @@ -11912,28 +11912,66 @@ return 0; } +/* + * 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) +{ + HAB thishab = WinInitialize(0); + HMQ thishmq = WinCreateMsgQueue(thishab, 0); + void **threadinfo = (void **)malloc(sizeof(void *) * 2); + + threadinfo[0] = (void *)thishab; + threadinfo[1] = (void *)thishmq; + + _threadstore() = (void *)threadinfo; + +#ifdef UNICODE + /* Set the codepage to 1208 (UTF-8) */ + WinSetCp(thishmq, 1208); +#endif +} + +/* + * 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) +{ + void **threadinfo = (void **)_threadstore(); + + if(threadinfo) + { + HAB thishab = (HAB)threadinfo[0]; + HMQ thishmq = (HMQ)threadinfo[1]; + + WinDestroyMsgQueue(thishmq); + WinTerminate(thishab); + free(threadinfo); + } +} + /* * Encapsulate the message queues on OS/2. */ void _dwthreadstart(void *data) { - HAB thishab = WinInitialize(0); - HMQ thishmq = WinCreateMsgQueue(thishab, 0); void (API_FUNC threadfunc)(void *) = NULL; void **tmp = (void **)data; -#ifdef UNICODE - /* Set the codepage to 1208 (UTF-8) */ - WinSetCp(thishmq, 1208); -#endif + _dw_init_thread(); threadfunc = (void (API_FUNC)(void *))tmp[0]; threadfunc(tmp[1]); free(tmp); - WinDestroyMsgQueue(thishmq); - WinTerminate(thishab); + _dw_deinit_thread(); } /*