comparison 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
comparison
equal deleted inserted replaced
1886:f7d408a47752 1887:09860ba329a4
11910 if(DosFreeMem(ptr) != NO_ERROR) 11910 if(DosFreeMem(ptr) != NO_ERROR)
11911 return -1; 11911 return -1;
11912 return 0; 11912 return 0;
11913 } 11913 }
11914 11914
11915 /* 11915 /*
11916 * Encapsulate the message queues on OS/2. 11916 * Generally an internal function called from a newly created
11917 */ 11917 * thread to setup the Dynamic Windows environment for the thread.
11918 void _dwthreadstart(void *data) 11918 * However it is exported so language bindings can call it when
11919 * they create threads that require access to Dynamic Windows.
11920 */
11921 void API _dw_init_thread(void)
11919 { 11922 {
11920 HAB thishab = WinInitialize(0); 11923 HAB thishab = WinInitialize(0);
11921 HMQ thishmq = WinCreateMsgQueue(thishab, 0); 11924 HMQ thishmq = WinCreateMsgQueue(thishab, 0);
11922 void (API_FUNC threadfunc)(void *) = NULL; 11925 void **threadinfo = (void **)malloc(sizeof(void *) * 2);
11923 void **tmp = (void **)data; 11926
11924 11927 threadinfo[0] = (void *)thishab;
11928 threadinfo[1] = (void *)thishmq;
11929
11930 _threadstore() = (void *)threadinfo;
11931
11925 #ifdef UNICODE 11932 #ifdef UNICODE
11926 /* Set the codepage to 1208 (UTF-8) */ 11933 /* Set the codepage to 1208 (UTF-8) */
11927 WinSetCp(thishmq, 1208); 11934 WinSetCp(thishmq, 1208);
11928 #endif 11935 #endif
11936 }
11937
11938 /*
11939 * Generally an internal function called from a terminating
11940 * thread to cleanup the Dynamic Windows environment for the thread.
11941 * However it is exported so language bindings can call it when
11942 * they exit threads that require access to Dynamic Windows.
11943 */
11944 void API _dw_deinit_thread(void)
11945 {
11946 void **threadinfo = (void **)_threadstore();
11947
11948 if(threadinfo)
11949 {
11950 HAB thishab = (HAB)threadinfo[0];
11951 HMQ thishmq = (HMQ)threadinfo[1];
11952
11953 WinDestroyMsgQueue(thishmq);
11954 WinTerminate(thishab);
11955 free(threadinfo);
11956 }
11957 }
11958
11959 /*
11960 * Encapsulate the message queues on OS/2.
11961 */
11962 void _dwthreadstart(void *data)
11963 {
11964 void (API_FUNC threadfunc)(void *) = NULL;
11965 void **tmp = (void **)data;
11966
11967 _dw_init_thread();
11929 11968
11930 threadfunc = (void (API_FUNC)(void *))tmp[0]; 11969 threadfunc = (void (API_FUNC)(void *))tmp[0];
11931 threadfunc(tmp[1]); 11970 threadfunc(tmp[1]);
11932 11971
11933 free(tmp); 11972 free(tmp);
11934 11973
11935 WinDestroyMsgQueue(thishmq); 11974 _dw_deinit_thread();
11936 WinTerminate(thishab);
11937 } 11975 }
11938 11976
11939 /* 11977 /*
11940 * Creates a new thread with a starting point of func. 11978 * Creates a new thread with a starting point of func.
11941 * Parameters: 11979 * Parameters: