xref: /reactos/dll/ime/msctfime/tls.h (revision 14d3b53c)
1 /*
2  * PROJECT:     ReactOS msctfime.ime
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     Thread-local storage
5  * COPYRIGHT:   Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #pragma once
9 
10 class TLS;
11 
12 class CicBridge;
13 class CicProfile;
14 
15 class TLS
16 {
17 public:
18     static DWORD s_dwTlsIndex;
19 
20     DWORD m_dwSystemInfoFlags;
21     CicBridge *m_pBridge;
22     CicProfile *m_pProfile;
23     ITfThreadMgr_P *m_pThreadMgr;
24     DWORD m_dwFlags1;
25     DWORD m_dwFlags2;
26     DWORD m_dwUnknown2;
27     BOOL m_bDestroyed;
28     BOOL m_bNowOpening;
29     DWORD m_NonEAComposition;
30     DWORD m_cWnds;
31 
32     /**
33      * @implemented
34      */
35     static BOOL Initialize()
36     {
37         s_dwTlsIndex = ::TlsAlloc();
38         return s_dwTlsIndex != (DWORD)-1;
39     }
40 
41     /**
42      * @implemented
43      */
44     static VOID Uninitialize()
45     {
46         if (s_dwTlsIndex != (DWORD)-1)
47         {
48             ::TlsFree(s_dwTlsIndex);
49             s_dwTlsIndex = (DWORD)-1;
50         }
51     }
52 
53     /**
54      * @implemented
55      */
56     static TLS* GetTLS()
57     {
58         if (s_dwTlsIndex == (DWORD)-1)
59             return NULL;
60 
61         return InternalAllocateTLS();
62     }
63 
64     /**
65      * @implemented
66      */
67     static TLS* PeekTLS()
68     {
69         return (TLS*)::TlsGetValue(TLS::s_dwTlsIndex);
70     }
71 
72     static TLS* InternalAllocateTLS();
73     static BOOL InternalDestroyTLS();
74 };
75