1 /*************************************************************************
3 * Thread local storage access stub for Open Dynamics Engine, *
4 * Copyright (C) 2008-2024 Oleh Derevenko. All rights reserved. *
5 * Email: odar@eleks.com (change all "a" to "e") *
7 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
8 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of EITHER: *
13 * (1) The GNU Lesser General Public License as published by the Free *
14 * Software Foundation; either version 2.1 of the License, or (at *
15 * your option) any later version. The text of the GNU Lesser *
16 * General Public License is included with this library in the *
18 * (2) The BSD-style license that is included with this library in *
19 * the file LICENSE-BSD.TXT. *
21 * This library is distributed in the hope that it will be useful, *
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
24 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
26 *************************************************************************/
30 ODE Thread Local Storage access stub interface.
35 #ifndef _ODE_ODETLS_H_
36 #define _ODE_ODETLS_H_
45 using _OU_NAMESPACE::tlsvaluetype
;
46 using _OU_NAMESPACE::HTLSKEY
;
47 using _OU_NAMESPACE::CThreadLocalStorage
;
50 struct TrimeshCollidersCache
;
57 OTK_AUTOCLEANUP
= OTK__MIN
,
62 OTK__DEFAULT
= OTK_AUTOCLEANUP
,
67 OTI_DATA_ALLOCATION_FLAGS
,
68 OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
,
77 static bool Initialize(EODETLSKIND tkTLSKind
);
78 static void Finalize(EODETLSKIND tkTLSKind
);
80 static void CleanupForThread();
83 static unsigned GetDataAllocationFlags(EODETLSKIND tkTLSKind
)
85 // Must be a safe call as it is used to test if TLS slot is allocated at all
86 return (unsigned)(sizeint
)CThreadLocalStorage::GetStorageValue(m_ahtkStorageKeys
[tkTLSKind
], OTI_DATA_ALLOCATION_FLAGS
);
89 static void SignalDataAllocationFlags(EODETLSKIND tkTLSKind
, unsigned uFlagsMask
)
91 unsigned uCurrentFlags
= (unsigned)(sizeint
)CThreadLocalStorage::UnsafeGetStorageValue(m_ahtkStorageKeys
[tkTLSKind
], OTI_DATA_ALLOCATION_FLAGS
);
92 CThreadLocalStorage::UnsafeSetStorageValue(m_ahtkStorageKeys
[tkTLSKind
], OTI_DATA_ALLOCATION_FLAGS
, (tlsvaluetype
)(sizeint
)(uCurrentFlags
| uFlagsMask
));
95 static void DropDataAllocationFlags(EODETLSKIND tkTLSKind
, unsigned uFlagsMask
)
97 unsigned uCurrentFlags
= (unsigned)(sizeint
)CThreadLocalStorage::UnsafeGetStorageValue(m_ahtkStorageKeys
[tkTLSKind
], OTI_DATA_ALLOCATION_FLAGS
);
98 CThreadLocalStorage::UnsafeSetStorageValue(m_ahtkStorageKeys
[tkTLSKind
], OTI_DATA_ALLOCATION_FLAGS
, (tlsvaluetype
)(sizeint
)(uCurrentFlags
& ~uFlagsMask
));
101 static TrimeshCollidersCache
*GetTrimeshCollidersCache(EODETLSKIND tkTLSKind
)
103 return (TrimeshCollidersCache
*)CThreadLocalStorage::UnsafeGetStorageValue(m_ahtkStorageKeys
[tkTLSKind
], OTI_TRIMESH_TRIMESH_COLLIDER_CACHE
);
107 static bool AssignDataAllocationFlags(EODETLSKIND tkTLSKind
, unsigned uInitializationFlags
);
109 static bool AssignTrimeshCollidersCache(EODETLSKIND tkTLSKind
, TrimeshCollidersCache
*pccInstance
);
110 static void DestroyTrimeshCollidersCache(EODETLSKIND tkTLSKind
);
113 static void FreeTrimeshCollidersCache(TrimeshCollidersCache
*pccCacheInstance
);
116 static void _OU_CONVENTION_CALLBACK
FreeTrimeshCollidersCache_Callback(tlsvaluetype vValueData
);
119 static HTLSKEY m_ahtkStorageKeys
[OTK__MAX
];
123 #endif // dTLS_ENABLED
126 #endif // _ODE_ODETLS_H_