Home | History | Annotate | Download | only in compiler
      1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //    http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #include "osinclude.h"
     16 //
     17 // This file contains contains the window's specific functions
     18 //
     19 
     20 #if !defined(ANGLE_OS_WIN)
     21 #error Trying to build a windows specific file in a non windows build.
     22 #endif
     23 
     24 
     25 //
     26 // Thread Local Storage Operations
     27 //
     28 OS_TLSIndex OS_AllocTLSIndex()
     29 {
     30 	DWORD dwIndex = TlsAlloc();
     31 	if (dwIndex == TLS_OUT_OF_INDEXES) {
     32 		assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
     33 		return OS_INVALID_TLS_INDEX;
     34 	}
     35 
     36 	return dwIndex;
     37 }
     38 
     39 
     40 bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
     41 {
     42 	if (nIndex == OS_INVALID_TLS_INDEX) {
     43 		assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
     44 		return false;
     45 	}
     46 
     47 	if (TlsSetValue(nIndex, lpvValue))
     48 		return true;
     49 	else
     50 		return false;
     51 }
     52 
     53 
     54 bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
     55 {
     56 	if (nIndex == OS_INVALID_TLS_INDEX) {
     57 		assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
     58 		return false;
     59 	}
     60 
     61 	if (TlsFree(nIndex))
     62 		return true;
     63 	else
     64 		return false;
     65 }
     66