Emscripten workarounds and llvm syntax fixes
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/event/common/thread-local-storage.h>
19
20 // EXTERNAL INCLUDES
21 #include <boost/thread/tss.hpp>
22 #include <memory>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/common/core-impl.h>
26 #include <dali/internal/update/manager/update-manager.h>
27 #include <dali/internal/render/common/render-manager.h>
28 #include <dali/integration-api/platform-abstraction.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/math/vector2.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace
39 {
40 #ifdef EMSCRIPTEN
41   std::auto_ptr<ThreadLocalStorage> threadLocal;
42 #else
43   boost::thread_specific_ptr<ThreadLocalStorage> threadLocal;
44 #endif
45 }
46
47 ThreadLocalStorage::ThreadLocalStorage(Core* core)
48 :mCore(core)
49 {
50   DALI_ASSERT_ALWAYS( threadLocal.get() == NULL && "Cannot create more than one ThreadLocalStorage object" );
51
52   // reset is used to store a new value associated with this thread
53   threadLocal.reset(this);
54
55 }
56
57 ThreadLocalStorage::~ThreadLocalStorage()
58 {
59 }
60
61 void ThreadLocalStorage::Remove()
62 {
63   threadLocal.reset();
64 }
65
66 ThreadLocalStorage& ThreadLocalStorage::Get()
67 {
68   ThreadLocalStorage* tls = threadLocal.get();
69
70   DALI_ASSERT_ALWAYS(tls);
71
72   return *tls;
73 }
74
75 bool ThreadLocalStorage::Created()
76 {
77   // see if the TLS has been set yet
78   return (threadLocal.get() != NULL);
79 }
80
81 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
82 {
83   return mCore->GetPlatform();
84 }
85
86 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
87 {
88   return mCore->GetUpdateManager();
89 }
90
91 NotificationManager& ThreadLocalStorage::GetNotificationManager()
92 {
93   return mCore->GetNotificationManager();
94 }
95
96 ResourceManager& ThreadLocalStorage::GetResourceManager()
97 {
98   return mCore->GetResourceManager();
99 }
100
101 ResourceClient& ThreadLocalStorage::GetResourceClient()
102 {
103   return mCore->GetResourceClient();
104 }
105
106 ImageFactory& ThreadLocalStorage::GetImageFactory()
107 {
108   return mCore->GetImageFactory();
109 }
110
111 ModelFactory& ThreadLocalStorage::GetModelFactory()
112 {
113   return mCore->GetModelFactory();
114 }
115
116 FontFactory& ThreadLocalStorage::GetFontFactory()
117 {
118   return mCore->GetFontFactory();
119 }
120
121 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
122 {
123   return mCore->GetShaderFactory();
124 }
125
126 StagePtr ThreadLocalStorage::GetCurrentStage()
127 {
128   return mCore->GetCurrentStage();
129 }
130
131 EventToUpdate& ThreadLocalStorage::GetEventToUpdate()
132 {
133   return GetUpdateManager().GetEventToUpdate();
134 }
135
136 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
137 {
138   return mCore->GetGestureEventProcessor();
139 }
140
141 } // namespace Internal
142
143 } // namespace Dali