Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / misc / tds.cpp
blob928f2b66edee501c5d0eff6603b999e972dd07ee
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdmisc.h"
22 #include "nel/misc/tds.h"
23 #include "nel/misc/debug.h"
25 #ifdef NL_OS_WINDOWS
26 # ifndef NL_COMP_MINGW
27 # define NOMINMAX
28 # endif
29 # include <windows.h>
30 #endif // NL_OS_WINDOWS
32 #ifdef DEBUG_NEW
33 #define new DEBUG_NEW
34 #endif
36 namespace NLMISC
39 // *********************************************************
41 CTDS::CTDS ()
43 /* Please no assert in the constructor because it is called by the NeL memory allocator constructor */
44 #ifdef NL_OS_WINDOWS
45 _Handle = TlsAlloc ();
46 TlsSetValue (_Handle, NULL);
47 #else // NL_OS_WINDOWS
48 // nldebug("CTDS::CTDS...");
49 nlverify(pthread_key_create (&_Key, NULL) == 0);
50 // nldebug("CTDS::CTDS : create a new key %u", _Key);
51 pthread_setspecific(_Key, NULL);
52 #endif // NL_OS_WINDOWS
55 // *********************************************************
57 CTDS::~CTDS ()
59 #ifdef NL_OS_WINDOWS
60 nlverify (TlsFree (_Handle) != 0);
61 #else // NL_OS_WINDOWS
62 // nldebug("CTDS::~CTDS : deleting key %u", _Key);
63 nlverify (pthread_key_delete (_Key) == 0);
64 #endif // NL_OS_WINDOWS
67 // *********************************************************
69 void *CTDS::getPointer () const
71 #ifdef NL_OS_WINDOWS
72 return TlsGetValue (_Handle);
73 #else // NL_OS_WINDOWS
74 // nldebug("CTDS::getPointer for key %u...", _Key);
75 void *ret = pthread_getspecific (_Key);
76 // nldebug("CTDS::getPointer returing value %p", ret);
77 return ret;
78 #endif // NL_OS_WINDOWS
81 // *********************************************************
83 void CTDS::setPointer (void* pointer)
85 #ifdef NL_OS_WINDOWS
86 nlverify (TlsSetValue (_Handle, pointer) != 0);
87 #else // NL_OS_WINDOWS
88 // nldebug("CTDS::setPointer for key %u to value %p", _Key, pointer);
89 nlverify (pthread_setspecific (_Key, pointer) == 0);
90 #endif // NL_OS_WINDOWS
93 // *********************************************************
95 } // NLMISC