blob: c04a3dd2409a0bbedf8a01cbf46b7d1c43cfca60 [file] [log] [blame]
Cody Northrop0d5881e2014-09-17 14:06:55 -06001//
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
Cody Northrop0d5881e2014-09-17 14:06:55 -060039#include "glslang/OSDependent/Linux/osinclude.h"
40#include "glsl_parser_extras.h"
41
42namespace glslang {
43
44bool InitProcess();
45bool InitThread();
46bool DetachThread();
47bool DetachProcess();
48
49//
50// Thread cleanup
51//
52
53//
54// Wrapper for Linux call to DetachThread. This is required as pthread_cleanup_push() expects
55// the cleanup routine to return void.
56//
57void DetachThreadLinux(void *)
58{
59 DetachThread();
60}
61
62
63//
64// Registers cleanup handler, sets cancel type and state, and excecutes the thread specific
65// cleanup handler. This function will be called in the Standalone.cpp for regression
66// testing. When OpenGL applications are run with the driver code, Linux OS does the
67// thread cleanup.
68//
69void OS_CleanupThreadData(void)
70{
71 int old_cancel_state, old_cancel_type;
72 void *cleanupArg = NULL;
73
74 //
75 // Set thread cancel state and push cleanup handler.
76 //
77 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancel_state);
78 pthread_cleanup_push(DetachThreadLinux, (void *) cleanupArg);
79
80 //
81 // Put the thread in deferred cancellation mode.
82 //
83 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_cancel_type);
84
85 //
86 // Pop cleanup handler and execute it prior to unregistering the cleanup handler.
87 //
88 pthread_cleanup_pop(1);
89
90 //
91 // Restore the thread's previous cancellation mode.
92 //
93 pthread_setcanceltype(old_cancel_state, NULL);
94}
95
96
97//
98// Thread Local Storage Operations
99//
100OS_TLSIndex OS_AllocTLSIndex()
101{
102 pthread_key_t pPoolIndex;
103
104 //
105 // Create global pool key.
106 //
107 if ((pthread_key_create(&pPoolIndex, NULL)) != 0) {
108 assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
109 return false;
110 }
111 else
112 return pPoolIndex;
113}
114
115
116bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
117{
118 if (nIndex == OS_INVALID_TLS_INDEX) {
119 assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
120 return false;
121 }
122
123 if (pthread_setspecific(nIndex, lpvValue) == 0)
124 return true;
125 else
126 return false;
127}
128
129
130bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
131{
132 if (nIndex == OS_INVALID_TLS_INDEX) {
133 assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
134 return false;
135 }
136
137 //
138 // Delete the global pool key.
139 //
140 if (pthread_key_delete(nIndex) == 0)
141 return true;
142 else
143 return false;
144}
145
146mtx_t GlslangGlobalLock = _MTX_INITIALIZER_NP;
147
148void InitGlobalLock() {
149}
150
151void GetGlobalLock() {
152 mtx_lock(&GlslangGlobalLock);
153}
154
155void ReleaseGlobalLock() {
156 mtx_unlock(&GlslangGlobalLock);
157}
158
159void* OS_CreateThread(TThreadEntrypoint entry)
160{
161 return 0;
162}
163
164void OS_WaitForAllThreads(void* threads, int numThreads)
165{
166}
167
168void OS_Sleep(int milliseconds)
169{
170}
171
172void OS_DumpMemoryCounters()
173{
174}
175
176} // end namespace glslang