[dali_1.0.31] Merge branch 'tizen'
[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 __thread ThreadLocalStorage* threadLocal = NULL;
34 }
35
36 ThreadLocalStorage::ThreadLocalStorage(Core* core)
37 : mCore(core)
38 {
39   DALI_ASSERT_ALWAYS( threadLocal == NULL && "Cannot create more than one ThreadLocalStorage object" );
40
41   // reset is used to store a new value associated with this thread
42   threadLocal = this;
43 }
44
45 ThreadLocalStorage::~ThreadLocalStorage()
46 {
47 }
48
49 void ThreadLocalStorage::Remove()
50 {
51   threadLocal = NULL;
52 }
53
54 ThreadLocalStorage& ThreadLocalStorage::Get()
55 {
56   DALI_ASSERT_ALWAYS(threadLocal);
57
58   return *threadLocal;
59 }
60
61 bool ThreadLocalStorage::Created()
62 {
63   // see if the TLS has been set yet
64   return (threadLocal != NULL);
65 }
66
67 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
68 {
69   return threadLocal;
70 }
71
72 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
73 {
74   return mCore->GetPlatform();
75 }
76
77 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
78 {
79   return mCore->GetUpdateManager();
80 }
81
82 NotificationManager& ThreadLocalStorage::GetNotificationManager()
83 {
84   return mCore->GetNotificationManager();
85 }
86
87 ResourceManager& ThreadLocalStorage::GetResourceManager()
88 {
89   return mCore->GetResourceManager();
90 }
91
92 ResourceClient& ThreadLocalStorage::GetResourceClient()
93 {
94   return mCore->GetResourceClient();
95 }
96
97 ImageFactory& ThreadLocalStorage::GetImageFactory()
98 {
99   return mCore->GetImageFactory();
100 }
101
102 ModelFactory& ThreadLocalStorage::GetModelFactory()
103 {
104   return mCore->GetModelFactory();
105 }
106
107 FontFactory& ThreadLocalStorage::GetFontFactory()
108 {
109   return mCore->GetFontFactory();
110 }
111
112 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
113 {
114   return mCore->GetShaderFactory();
115 }
116
117 StagePtr ThreadLocalStorage::GetCurrentStage()
118 {
119   return mCore->GetCurrentStage();
120 }
121
122 EventToUpdate& ThreadLocalStorage::GetEventToUpdate()
123 {
124   return GetUpdateManager().GetEventToUpdate();
125 }
126
127 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
128 {
129   return mCore->GetGestureEventProcessor();
130 }
131
132 EmojiFactory& ThreadLocalStorage::GetEmojiFactory()
133 {
134   return mCore->GetEmojiFactory();
135 }
136
137 } // namespace Internal
138
139 } // namespace Dali