Changeset 2296 in kBuild for trunk/src/kash/shthread.c
- Timestamp:
- Mar 1, 2009 1:54:30 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/shthread.c
r2243 r2296 27 27 #include "shthread.h" 28 28 #include "shinstance.h" 29 #include <assert.h> 29 30 30 #if defined(_MSC_VER) || defined(__EMX__) 31 # include <process.h> 31 #if K_OS == K_OS_WINDOWS 32 # include <Windows.h> 33 #elif K_OS == K_OS_OS2 34 # include <InnoTekLIBC/FastInfoBlocks.h> 35 # include <InnoTekLIBC/thread.h> 32 36 #else 33 37 # include <pthread.h> … … 35 39 36 40 41 /******************************************************************************* 42 * Global Variables * 43 *******************************************************************************/ 44 #if K_OS == K_OS_WINDOWS 45 static DWORD sh_tls = TLS_OUT_OF_INDEXES; 46 #elif K_OS == K_OS_OS2 47 static int sh_tls = -1; 48 #else 49 static int sh_tls_inited = 0; 50 static int sh_tls; 51 #endif 52 53 54 /** 55 * Stores the shell instance pointer in a TLS entry. 56 * 57 * This will allocate the TLS entry on the first call. We assume 58 * there will no be races at that time. 59 * 60 * @param psh The shell instance. 61 */ 37 62 void shthread_set_shell(struct shinstance *psh) 38 63 { 64 #if K_OS == K_OS_WINDOWS 65 if (sh_tls == TLS_OUT_OF_INDEXES) 66 { 67 sh_tls = TlsAlloc(); 68 assert(sh_tls != TLS_OUT_OF_INDEXES); 69 } 70 if (!TlsSetValue(sh_tls, psh)) 71 assert(0); 39 72 73 #elif K_OS == K_OS_OS2 74 if (sh_tls == -1) 75 { 76 sh_tls = __libc_TLSAlloc(); 77 assert(sh_tls != -1); 78 } 79 if (__libc_TLSSet(sh_tls, psh) == -1) 80 assert(0); 81 #else 82 if (!sh_tls_inited) 83 { 84 if (pthread_key_create(&sh_tls, NULL) != 0) 85 assert(0); 86 sh_tls_inited = 1; 87 } 88 if (pthread_setspecific(sh_tls, psh) != 0) 89 assert(0); 90 #endif 40 91 } 41 92 93 /** 94 * Get the shell instance pointer from TLS. 95 * 96 * @returns The shell instance. 97 */ 42 98 struct shinstance *shthread_get_shell(void) 43 99 { 44 shinstance *psh = NULL; 100 shinstance *psh; 101 #if K_OS == K_OS_WINDOWS 102 psh = (shinstance *)TlsGetValue(sh_tls); 103 #elif K_OS == K_OS_OS2 104 psh = (shinstance *)__libc_TLSGet(iTls) 105 #else 106 psh = (shinstance *)pthread_getspecific(sh_tls); 107 #endif 45 108 return psh; 46 109 } 47 110 48
Note:
See TracChangeset
for help on using the changeset viewer.