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
29namespace glslang
30{
31
32DE_STATIC_ASSERT(sizeof(deThreadLocal)	== sizeof(OS_TLSIndex));
33DE_STATIC_ASSERT(sizeof(deThread)		== sizeof(void*));
34
35// Thread-local
36
37OS_TLSIndex OS_AllocTLSIndex (void)
38{
39	return (OS_TLSIndex)deThreadLocal_create();
40}
41
42bool OS_SetTLSValue (OS_TLSIndex nIndex, void* lpvValue)
43{
44	deThreadLocal_set((deThreadLocal)nIndex, lpvValue);
45	return true;
46}
47
48bool OS_FreeTLSIndex (OS_TLSIndex nIndex)
49{
50	deThreadLocal_destroy((deThreadLocal)nIndex);
51	return true;
52}
53
54void* OS_GetTLSValue (OS_TLSIndex nIndex)
55{
56	return deThreadLocal_get((deThreadLocal)nIndex);
57}
58
59// Global lock - not used
60
61void InitGlobalLock (void)
62{
63}
64
65void GetGlobalLock (void)
66{
67}
68
69void ReleaseGlobalLock (void)
70{
71}
72
73// Threading
74
75DE_STATIC_ASSERT(sizeof(void*) >= sizeof(deThread));
76
77static void EnterGenericThread (void* entry)
78{
79	((TThreadEntrypoint)entry)(DE_NULL);
80}
81
82void* OS_CreateThread (TThreadEntrypoint entry)
83{
84	return (void*)(deUintptr)deThread_create(EnterGenericThread, (void*)entry, DE_NULL);
85}
86
87void OS_WaitForAllThreads (void* threads, int numThreads)
88{
89	for (int ndx = 0; ndx < numThreads; ndx++)
90	{
91		const deThread thread = (deThread)(deUintptr)((void**)threads)[ndx];
92		deThread_join(thread);
93		deThread_destroy(thread);
94	}
95}
96
97void OS_Sleep (int milliseconds)
98{
99	deSleep(milliseconds);
100}
101
102void OS_DumpMemoryCounters (void)
103{
104	// Not used
105}
106
107} // glslang
108