Cody Northrop | 0d5881e | 2014-09-17 14:06:55 -0600 | [diff] [blame^] | 1 | // |
| 2 | //Copyright (C) 2002-2005 3Dlabs Inc. Ltd. |
| 3 | //All rights reserved. |
| 4 | // |
| 5 | //Redistribution and use in source and binary forms, with or without |
| 6 | //modification, are permitted provided that the following conditions |
| 7 | //are met: |
| 8 | // |
| 9 | // Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // |
| 12 | // Redistributions in binary form must reproduce the above |
| 13 | // copyright notice, this list of conditions and the following |
| 14 | // disclaimer in the documentation and/or other materials provided |
| 15 | // with the distribution. |
| 16 | // |
| 17 | // Neither the name of 3Dlabs Inc. Ltd. nor the names of its |
| 18 | // contributors may be used to endorse or promote products derived |
| 19 | // from this software without specific prior written permission. |
| 20 | // |
| 21 | //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 | //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 24 | //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 25 | //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 27 | //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 28 | //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 29 | //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 30 | //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 31 | //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 32 | //POSSIBILITY OF SUCH DAMAGE. |
| 33 | // |
| 34 | |
| 35 | // |
| 36 | // This file contains the Linux-specific functions |
| 37 | // |
| 38 | |
| 39 | #ifdef USE_LUNARGLASS |
| 40 | |
| 41 | #include "glslang/OSDependent/Linux/osinclude.h" |
| 42 | #include "glsl_parser_extras.h" |
| 43 | |
| 44 | namespace glslang { |
| 45 | |
| 46 | bool InitProcess(); |
| 47 | bool InitThread(); |
| 48 | bool DetachThread(); |
| 49 | bool DetachProcess(); |
| 50 | |
| 51 | // |
| 52 | // Thread cleanup |
| 53 | // |
| 54 | |
| 55 | // |
| 56 | // Wrapper for Linux call to DetachThread. This is required as pthread_cleanup_push() expects |
| 57 | // the cleanup routine to return void. |
| 58 | // |
| 59 | void DetachThreadLinux(void *) |
| 60 | { |
| 61 | DetachThread(); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | // |
| 66 | // Registers cleanup handler, sets cancel type and state, and excecutes the thread specific |
| 67 | // cleanup handler. This function will be called in the Standalone.cpp for regression |
| 68 | // testing. When OpenGL applications are run with the driver code, Linux OS does the |
| 69 | // thread cleanup. |
| 70 | // |
| 71 | void OS_CleanupThreadData(void) |
| 72 | { |
| 73 | int old_cancel_state, old_cancel_type; |
| 74 | void *cleanupArg = NULL; |
| 75 | |
| 76 | // |
| 77 | // Set thread cancel state and push cleanup handler. |
| 78 | // |
| 79 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancel_state); |
| 80 | pthread_cleanup_push(DetachThreadLinux, (void *) cleanupArg); |
| 81 | |
| 82 | // |
| 83 | // Put the thread in deferred cancellation mode. |
| 84 | // |
| 85 | pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_cancel_type); |
| 86 | |
| 87 | // |
| 88 | // Pop cleanup handler and execute it prior to unregistering the cleanup handler. |
| 89 | // |
| 90 | pthread_cleanup_pop(1); |
| 91 | |
| 92 | // |
| 93 | // Restore the thread's previous cancellation mode. |
| 94 | // |
| 95 | pthread_setcanceltype(old_cancel_state, NULL); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | // |
| 100 | // Thread Local Storage Operations |
| 101 | // |
| 102 | OS_TLSIndex OS_AllocTLSIndex() |
| 103 | { |
| 104 | pthread_key_t pPoolIndex; |
| 105 | |
| 106 | // |
| 107 | // Create global pool key. |
| 108 | // |
| 109 | if ((pthread_key_create(&pPoolIndex, NULL)) != 0) { |
| 110 | assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage"); |
| 111 | return false; |
| 112 | } |
| 113 | else |
| 114 | return pPoolIndex; |
| 115 | } |
| 116 | |
| 117 | |
| 118 | bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue) |
| 119 | { |
| 120 | if (nIndex == OS_INVALID_TLS_INDEX) { |
| 121 | assert(0 && "OS_SetTLSValue(): Invalid TLS Index"); |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | if (pthread_setspecific(nIndex, lpvValue) == 0) |
| 126 | return true; |
| 127 | else |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | bool OS_FreeTLSIndex(OS_TLSIndex nIndex) |
| 133 | { |
| 134 | if (nIndex == OS_INVALID_TLS_INDEX) { |
| 135 | assert(0 && "OS_SetTLSValue(): Invalid TLS Index"); |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | // |
| 140 | // Delete the global pool key. |
| 141 | // |
| 142 | if (pthread_key_delete(nIndex) == 0) |
| 143 | return true; |
| 144 | else |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | mtx_t GlslangGlobalLock = _MTX_INITIALIZER_NP; |
| 149 | |
| 150 | void InitGlobalLock() { |
| 151 | } |
| 152 | |
| 153 | void GetGlobalLock() { |
| 154 | mtx_lock(&GlslangGlobalLock); |
| 155 | } |
| 156 | |
| 157 | void ReleaseGlobalLock() { |
| 158 | mtx_unlock(&GlslangGlobalLock); |
| 159 | } |
| 160 | |
| 161 | void* OS_CreateThread(TThreadEntrypoint entry) |
| 162 | { |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | void OS_WaitForAllThreads(void* threads, int numThreads) |
| 167 | { |
| 168 | } |
| 169 | |
| 170 | void OS_Sleep(int milliseconds) |
| 171 | { |
| 172 | } |
| 173 | |
| 174 | void OS_DumpMemoryCounters() |
| 175 | { |
| 176 | } |
| 177 | |
| 178 | } // end namespace glslang |
| 179 | |
| 180 | #endif |