1 /* 2 Language Independent Library 3 4 Copyright 1983-2007 Green Hills Software,Inc. 5 6 This program is the property of Green Hills Software, Inc, 7 its contents are proprietary information and no part of it 8 is to be disclosed to anyone except employees of Green Hills 9 Software, Inc., or as agreed in writing signed by the President 10 of Green Hills Software, Inc. 11 */ 12 #include "inddef.h" 13 #include "inderrno.h" 14 #include "ind_thrd.h" 15 16 /* 17 Thread-Local errno Values 18 ========================= 19 20 To make library functions that set errno thread-safe, references 21 to errno are made using __gh_get_errno and __gh_set_errno when 22 EMBEDDED is defined. 23 24 By default this file causes the libraries to use a single, 25 global errno value. 26 27 If __ghs_GetThreadLocalStorageItem is customized to 28 return a per-thread errno value, define the preprocessor 29 symbol USE_THREAD_LOCAL_ERRNO. 30 31 Programs not compiled with the proper definition of errno will 32 reference the global errno value. If a per-thread errno value 33 is implemented, programs must #include <errno.h> to 34 properly reference errno. 35 36 These errno functions are provided in this file instead of in 37 ind_thrd.c to avoid pulling in the contents of ind_thrd.c for 38 stand-alone programs that reference errno without otherwise 39 referencing the contents of ind_thrd.c (unless USE_THREAD_LOCAL_ERRNO 40 is defined). 41 42 */ 43 44 #if 1 // CAFE MOD 45 #define USE_THREAD_LOCAL_ERRNO 46 /* Remove if __ghs_GetThreadLocalStorageItem returns per-thread errno. */ 47 //#undef USE_THREAD_LOCAL_ERRNO 48 #endif // CAFE MOD 49 50 #if 0 // CAFE GHS ORIG 51 /* Remove if __ghs_GetThreadLocalStorageItem returns per-thread errno. */ 52 #undef USE_THREAD_LOCAL_ERRNO 53 #endif // CAFE GHS ORIG 54 55 /* 56 If compiling with the MINIMAL_STARTUP option, 57 __ghs_GetThreadLocalStorageItem does not exist, so use the 58 global errno. 59 */ 60 #if defined(MINIMAL_STARTUP) 61 #undef USE_THREAD_LOCAL_ERRNO 62 #endif 63 64 #if 0 /* move to coreinit */ 65 /* Define the global errno value. */ 66 #undef errno 67 int errno; 68 69 int *__gh_errno_ptr(void) 70 { 71 #if defined(USE_THREAD_LOCAL_ERRNO) 72 int *errnoptr = __ghs_GetThreadLocalStorageItem(__ghs_TLS_Errno); 73 if(!errnoptr) 74 errnoptr = &errno; 75 return errnoptr; 76 #else 77 return &errno; 78 #endif 79 } 80 81 void __gh_set_errno(int err) 82 { 83 #if defined(USE_THREAD_LOCAL_ERRNO) 84 int *p = __gh_errno_ptr(); 85 *p = err; 86 #else 87 errno = err; 88 #endif 89 } 90 91 int __gh_get_errno(void) 92 { 93 #if defined(USE_THREAD_LOCAL_ERRNO) 94 int *p = __gh_errno_ptr(); 95 return *p; 96 #else 97 return errno; 98 #endif 99 } 100 #endif 101