1 /*-------------------------------------------------------------------------
2 * dEQP glslang integration
3 * ------------------------
5 * Copyright 2015 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief glslang OS interface.
22 *//*--------------------------------------------------------------------*/
24 #include "osinclude.h"
27 #include "deThreadLocal.h"
33 DE_STATIC_ASSERT(sizeof(deThreadLocal) == sizeof(OS_TLSIndex));
34 DE_STATIC_ASSERT(sizeof(deThread) == sizeof(void*));
38 OS_TLSIndex OS_AllocTLSIndex (void)
40 return (OS_TLSIndex)deThreadLocal_create();
43 bool OS_SetTLSValue (OS_TLSIndex nIndex, void* lpvValue)
45 deThreadLocal_set((deThreadLocal)nIndex, lpvValue);
49 bool OS_FreeTLSIndex (OS_TLSIndex nIndex)
51 deThreadLocal_destroy((deThreadLocal)nIndex);
55 void* OS_GetTLSValue (OS_TLSIndex nIndex)
57 return deThreadLocal_get((deThreadLocal)nIndex);
62 static deMutex s_globalLock = 0;
64 void InitGlobalLock (void)
66 DE_ASSERT(s_globalLock == 0);
67 s_globalLock = deMutex_create(DE_NULL);
70 void GetGlobalLock (void)
72 deMutex_lock(s_globalLock);
75 void ReleaseGlobalLock (void)
77 deMutex_unlock(s_globalLock);
82 DE_STATIC_ASSERT(sizeof(void*) >= sizeof(deThread));
84 static void EnterGenericThread (void* entry)
86 ((TThreadEntrypoint)entry)(DE_NULL);
89 void* OS_CreateThread (TThreadEntrypoint entry)
91 return (void*)(deUintptr)deThread_create(EnterGenericThread, (void*)entry, DE_NULL);
94 void OS_WaitForAllThreads (void* threads, int numThreads)
96 for (int ndx = 0; ndx < numThreads; ndx++)
98 const deThread thread = (deThread)(deUintptr)((void**)threads)[ndx];
99 deThread_join(thread);
100 deThread_destroy(thread);
104 void OS_Sleep (int milliseconds)
106 deSleep(milliseconds);
109 void OS_DumpMemoryCounters (void)