Merge remote-tracking branch 'origin/tizen' into new_text
[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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
18 // CLASS HEADER
19 #include <dali/internal/event/common/thread-local-storage.h>
20
21 // EXTERNAL INCLUDES
22 #include <boost/thread/tss.hpp>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/common/core-impl.h>
27 #include <dali/internal/update/manager/update-manager.h>
28 #include <dali/internal/render/common/render-manager.h>
29 #include <dali/integration-api/platform-abstraction.h>
30 #include <dali/public-api/common/dali-common.h>
31 #include <dali/public-api/math/vector2.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace
40 {
41 #ifdef EMSCRIPTEN
42   std::auto_ptr<ThreadLocalStorage> threadLocal;
43 #else
44   boost::thread_specific_ptr<ThreadLocalStorage> threadLocal;
45 #endif
46 }
47
48 ThreadLocalStorage::ThreadLocalStorage(Core* core)
49 : mCore(core)
50 {
51   DALI_ASSERT_ALWAYS( threadLocal.get() == NULL && "Cannot create more than one ThreadLocalStorage object" );
52
53   // reset is used to store a new value associated with this thread
54   threadLocal.reset(this);
55
56 }
57
58 ThreadLocalStorage::~ThreadLocalStorage()
59 {
60 }
61
62 void ThreadLocalStorage::Remove()
63 {
64   threadLocal.reset();
65 }
66
67 ThreadLocalStorage& ThreadLocalStorage::Get()
68 {
69   ThreadLocalStorage* tls = threadLocal.get();
70
71   DALI_ASSERT_ALWAYS(tls);
72
73   return *tls;
74 }
75
76 bool ThreadLocalStorage::Created()
77 {
78   // see if the TLS has been set yet
79   return (threadLocal.get() != NULL);
80 }
81
82 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
83 {
84   return mCore->GetPlatform();
85 }
86
87 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
88 {
89   return mCore->GetUpdateManager();
90 }
91
92 NotificationManager& ThreadLocalStorage::GetNotificationManager()
93 {
94   return mCore->GetNotificationManager();
95 }
96
97 ResourceManager& ThreadLocalStorage::GetResourceManager()
98 {
99   return mCore->GetResourceManager();
100 }
101
102 ResourceClient& ThreadLocalStorage::GetResourceClient()
103 {
104   return mCore->GetResourceClient();
105 }
106
107 ImageFactory& ThreadLocalStorage::GetImageFactory()
108 {
109   return mCore->GetImageFactory();
110 }
111
112 ModelFactory& ThreadLocalStorage::GetModelFactory()
113 {
114   return mCore->GetModelFactory();
115 }
116
117 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
118 {
119   return mCore->GetShaderFactory();
120 }
121
122 StagePtr ThreadLocalStorage::GetCurrentStage()
123 {
124   return mCore->GetCurrentStage();
125 }
126
127 EventToUpdate& ThreadLocalStorage::GetEventToUpdate()
128 {
129   return GetUpdateManager().GetEventToUpdate();
130 }
131
132 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
133 {
134   return mCore->GetGestureEventProcessor();
135 }
136
137 } // namespace Internal
138
139 } // namespace Dali