[dali_1.1.15] Merge branch 'devel/master'
[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 // INTERNAL INCLUDES
22 #include <dali/internal/common/core-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace
32 {
33 #if defined(EMSCRIPTEN)
34 ThreadLocalStorage* threadLocal = NULL;
35 #else
36 __thread ThreadLocalStorage* threadLocal = NULL;
37 #endif
38 }
39
40 ThreadLocalStorage::ThreadLocalStorage(Core* core)
41 : mCore( core )
42 {
43   DALI_ASSERT_ALWAYS( threadLocal == NULL && "Cannot create more than one ThreadLocalStorage object" );
44
45   threadLocal = this;
46 }
47
48 ThreadLocalStorage::~ThreadLocalStorage()
49 {
50 }
51
52 void ThreadLocalStorage::Remove()
53 {
54   threadLocal = NULL;
55 }
56
57 ThreadLocalStorage& ThreadLocalStorage::Get()
58 {
59   DALI_ASSERT_ALWAYS(threadLocal);
60
61   return *threadLocal;
62 }
63
64 bool ThreadLocalStorage::Created()
65 {
66   // see if the TLS has been set yet
67   return (threadLocal != NULL);
68 }
69
70 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
71 {
72   return threadLocal;
73 }
74
75 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
76 {
77   return mCore->GetPlatform();
78 }
79
80 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
81 {
82   return mCore->GetUpdateManager();
83 }
84
85 NotificationManager& ThreadLocalStorage::GetNotificationManager()
86 {
87   return mCore->GetNotificationManager();
88 }
89
90 ResourceManager& ThreadLocalStorage::GetResourceManager()
91 {
92   return mCore->GetResourceManager();
93 }
94
95 ResourceClient& ThreadLocalStorage::GetResourceClient()
96 {
97   return mCore->GetResourceClient();
98 }
99
100 ImageFactory& ThreadLocalStorage::GetImageFactory()
101 {
102   return mCore->GetImageFactory();
103 }
104
105 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
106 {
107   return mCore->GetShaderFactory();
108 }
109
110 StagePtr ThreadLocalStorage::GetCurrentStage()
111 {
112   return mCore->GetCurrentStage();
113 }
114
115 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
116 {
117   return mCore->GetGestureEventProcessor();
118 }
119
120 RelayoutController& ThreadLocalStorage::GetRelayoutController()
121 {
122   return mCore->GetRelayoutController();
123 }
124
125 } // namespace Internal
126
127 } // namespace Dali