1 /*-------------------------------------------------------------------------
2 * dEQP glslang integration
3 * ------------------------
4 *
5 * Copyright 2015 The Android Open Source Project
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief glslang OS interface.
22 *//*--------------------------------------------------------------------*/
23
24 #include "osinclude.h"
25
26 #include "deThread.h"
27 #include "deThreadLocal.h"
28 #include "deMutex.h"
29
30 namespace glslang
31 {
32
33 DE_STATIC_ASSERT(sizeof(deThreadLocal) == sizeof(OS_TLSIndex));
34 DE_STATIC_ASSERT(sizeof(deThread) == sizeof(void*));
35
36 // Thread-local
37
OS_AllocTLSIndex(void)38 OS_TLSIndex OS_AllocTLSIndex (void)
39 {
40 return (OS_TLSIndex)deThreadLocal_create();
41 }
42
OS_SetTLSValue(OS_TLSIndex nIndex,void * lpvValue)43 bool OS_SetTLSValue (OS_TLSIndex nIndex, void* lpvValue)
44 {
45 deThreadLocal_set((deThreadLocal)nIndex, lpvValue);
46 return true;
47 }
48
OS_FreeTLSIndex(OS_TLSIndex nIndex)49 bool OS_FreeTLSIndex (OS_TLSIndex nIndex)
50 {
51 deThreadLocal_destroy((deThreadLocal)nIndex);
52 return true;
53 }
54
OS_GetTLSValue(OS_TLSIndex nIndex)55 void* OS_GetTLSValue (OS_TLSIndex nIndex)
56 {
57 return deThreadLocal_get((deThreadLocal)nIndex);
58 }
59
60 // Global lock
61
62 static deMutex s_globalLock = 0;
63
InitGlobalLock(void)64 void InitGlobalLock (void)
65 {
66 DE_ASSERT(s_globalLock == 0);
67 s_globalLock = deMutex_create(DE_NULL);
68 }
69
GetGlobalLock(void)70 void GetGlobalLock (void)
71 {
72 deMutex_lock(s_globalLock);
73 }
74
ReleaseGlobalLock(void)75 void ReleaseGlobalLock (void)
76 {
77 deMutex_unlock(s_globalLock);
78 }
79
80 // Threading
81
82 DE_STATIC_ASSERT(sizeof(void*) >= sizeof(deThread));
83
EnterGenericThread(void * entry)84 static void EnterGenericThread (void* entry)
85 {
86 ((TThreadEntrypoint)entry)(DE_NULL);
87 }
88
OS_CreateThread(TThreadEntrypoint entry)89 void* OS_CreateThread (TThreadEntrypoint entry)
90 {
91 return (void*)(deUintptr)deThread_create(EnterGenericThread, (void*)entry, DE_NULL);
92 }
93
OS_WaitForAllThreads(void * threads,int numThreads)94 void OS_WaitForAllThreads (void* threads, int numThreads)
95 {
96 for (int ndx = 0; ndx < numThreads; ndx++)
97 {
98 const deThread thread = (deThread)(deUintptr)((void**)threads)[ndx];
99 deThread_join(thread);
100 deThread_destroy(thread);
101 }
102 }
103
OS_Sleep(int milliseconds)104 void OS_Sleep (int milliseconds)
105 {
106 deSleep(milliseconds);
107 }
108
OS_DumpMemoryCounters(void)109 void OS_DumpMemoryCounters (void)
110 {
111 // Not used
112 }
113
114 } // glslang
115