1/*-------------------------------------------------------------------------
2 * drawElements Thread Library
3 * ---------------------------
4 *
5 * Copyright 2014 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 Win32 implementation of thread-local storage.
22 *//*--------------------------------------------------------------------*/
23
24#include "deThreadLocal.h"
25
26#if (DE_OS == DE_OS_WIN32 || DE_OS == DE_OS_WINCE)
27
28#define VC_EXTRALEAN
29#define WIN32_LEAN_AND_MEAN
30#include <windows.h>
31
32DE_STATIC_ASSERT(sizeof(deThreadLocal) >= sizeof(DWORD));
33
34deThreadLocal deThreadLocal_create (void)
35{
36	DWORD handle = TlsAlloc();
37	if (handle == TLS_OUT_OF_INDEXES)
38		return 0;
39	return (deThreadLocal)handle;
40}
41
42void deThreadLocal_destroy (deThreadLocal threadLocal)
43{
44	DE_ASSERT(threadLocal != 0);
45	TlsFree((DWORD)threadLocal);
46}
47
48void* deThreadLocal_get (deThreadLocal threadLocal)
49{
50	DE_ASSERT(threadLocal != 0);
51	return TlsGetValue((DWORD)threadLocal);
52}
53
54void deThreadLocal_set (deThreadLocal threadLocal, void* value)
55{
56	DE_ASSERT(threadLocal != 0);
57	TlsSetValue((DWORD)threadLocal, value);
58}
59
60#endif /* DE_OS */
61