winTLS.cpp

Engine/source/platformWin32/winTLS.cpp

More...

Classes:

Public Defines

define
TORQUE_ALLOC_STORAGE(member, cls, data)    (sizeof(cls) <= sizeof(data), ("Error, storage  %s must be %d bytes.", #cls, sizeof(cls))); \
   member = (cls *) data; \
   (member)

Detailed Description

Public Defines

TORQUE_ALLOC_STORAGE(member, cls, data)    (sizeof(cls) <= sizeof(data), ("Error, storage  %s must be %d bytes.", #cls, sizeof(cls))); \
   member = (cls *) data; \
   (member)
 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#include "platform/platformTLS.h"
25#include "platformWin32/platformWin32.h"
26#include "core/util/safeDelete.h"
27
28#define TORQUE_ALLOC_STORAGE(member, cls, data) \
29   AssertFatal(sizeof(cls) <= sizeof(data), avar("Error, storage for %s must be %d bytes.", #cls, sizeof(cls))); \
30   member = (cls *) data; \
31   constructInPlace(member)
32
33//-----------------------------------------------------------------------------
34
35struct PlatformThreadStorage
36{
37   DWORD mTlsIndex;
38};
39
40//-----------------------------------------------------------------------------
41
42ThreadStorage::ThreadStorage()
43{
44   TORQUE_ALLOC_STORAGE(mThreadStorage, PlatformThreadStorage, mStorage);
45   mThreadStorage->mTlsIndex = TlsAlloc();
46}
47
48ThreadStorage::~ThreadStorage()
49{
50   TlsFree(mThreadStorage->mTlsIndex);
51   destructInPlace(mThreadStorage);
52}
53
54void *ThreadStorage::get()
55{
56   return TlsGetValue(mThreadStorage->mTlsIndex);
57}
58
59void ThreadStorage::set(void *value)
60{
61   TlsSetValue(mThreadStorage->mTlsIndex, value);
62}
63
64/* POSIX IMPLEMENTATION LOOKS LIKE THIS:
65
66class PlatformThreadStorage
67{
68pthread_key_t mThreadKey;
69};
70
71ThreadStorage::ThreadStorage()
72{
73TORQUE_ALLOC_STORAGE(mThreadStorage, PlatformThreadStorage, mStorage);
74pthread_key_create(&mThreadStorage->mThreadKey, NULL);
75}
76
77ThreadStorage::~ThreadStorage()
78{
79pthread_key_delete(mThreadStorage->mThreadKey);
80}
81
82void *ThreadStorage::get()
83{
84return pthread_getspecific(mThreadStorage->mThreadKey);
85}
86
87void ThreadStorage::set(void *value)
88{
89pthread_setspecific(mThreadStorage->mThreadKey, value);
90}
91*/
92