Dali 3D User Interface Engine
thread-synchronization.h
Go to the documentation of this file.
1 #ifndef __DALI_INTERNAL_THREAD_SYNCHRONIZATION_H__
2 #define __DALI_INTERNAL_THREAD_SYNCHRONIZATION_H__
3 
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20 
21 // EXTERNAL INCLUDES
23 
24 // INTERNAL INCLUDES
25 #include <integration-api/thread-synchronization-interface.h>
27 #include <trigger-event-interface.h>
30 
31 namespace Dali
32 {
33 
34 class RenderSurface;
35 
36 namespace Internal
37 {
38 
39 namespace Adaptor
40 {
41 
42 class AdaptorInternalServices;
43 
51 class ThreadSynchronization : public Dali::ThreadSynchronizationInterface
52 {
53 public:
54 
60  ThreadSynchronization( AdaptorInternalServices& adaptorInterfaces, unsigned int numberOfVSyncsPerRender );
61 
66 
68  // Called by the Event Thread
70 
79  void Initialise();
80 
88  void Start();
89 
95  void Stop();
96 
102  void Pause();
103 
109  void Resume();
110 
119  void UpdateRequest();
120 
126  void UpdateOnce();
127 
136  void ReplaceSurface( RenderSurface* newSurface );
137 
145  void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
146 
148  // Called by the Update Thread
150 
163  bool UpdateReady( bool notifyEvent, bool runUpdate, float& lastFrameDeltaSeconds, unsigned int& lastSyncTimeMilliseconds, unsigned int& nextSyncTimeMilliseconds );
164 
166  // Called by the Render Thread
168 
177  bool RenderReady( RenderRequest*& request );
178 
184  void RenderFinished();
185 
192 
194  // Called by the V-Sync Thread
196 
210  bool VSyncReady( bool validSync, unsigned int frameNumber, unsigned int seconds, unsigned int microseconds, unsigned int& numberOfVSyncsPerRender );
211 
213  // POST RENDERING
215 
219 
223  void PostRenderComplete();
224 
228 
232  void PostRenderStarted();
233 
238 
240  // Called by ALL Threads
242 
248 
249 private:
250 
251  // Undefined copy constructor.
253 
254  // Undefined assignment operator.
256 
258  // Called by ALL Threads
260 
265  inline void NotifyThreadInitialised();
266 
268  // Called by Update Thread
270 
275  void UpdateInitialising();
276 
281  void UpdateTryToSleep( bool runUpdate );
282 
288 
293  inline bool IsUpdateThreadResuming();
294 
301  inline bool IsUpdateThreadStopping();
302 
309  inline bool MaximumUpdateAheadOfRenderReached();
310 
315  inline void StopAllThreads();
316 
321  inline void RunVSyncThread();
322 
327  inline void PauseVSyncThread();
328 
333  inline void StopVSyncThread();
334 
339  inline void StopRenderThread();
340 
342  // Called by V-Sync Thread
344 
351  inline bool IsVSyncThreadRunning();
352 
354  // Called by Render Thread
356 
363  inline bool IsRenderThreadRunning();
364 
371  inline bool IsRenderThreadReplacingSurface();
372 
373 private:
374 
375  struct State
376  {
377  enum Type
378  {
385  };
386  };
387 
389  TriggerEventInterface& mNotificationTrigger;
392 
397 
400 
401  unsigned int mTryToSleepCount;
402 
403  volatile State::Type mState;
404 
405  volatile int mVSyncAheadOfUpdate;
406  volatile int mUpdateAheadOfRender;
407  volatile int mNumberOfThreadsStarted;
408 
409  //
410  // NOTE: cannot use booleans as these are used from multiple threads, must use variable with machine word size for atomic read/write
411  //
412 
413  volatile unsigned int mUpdateThreadResuming;
414 
415  volatile unsigned int mVSyncThreadRunning;
416  volatile unsigned int mVSyncThreadStop;
417 
418  volatile unsigned int mRenderThreadStop;
419  volatile unsigned int mRenderThreadReplacingSurface;
420 
421  volatile unsigned int mRenderThreadPostRendering;
422 
423  volatile unsigned int mEventThreadSurfaceReplaced;
424 
425  unsigned int mVSyncThreadInitialised;
428 }; // class ThreadSynchronization
429 
430 } // namespace Adaptor
431 
432 } // namespace Internal
433 
434 } // namespace Dali
435 
436 #endif // __DALI_INTERNAL_THREAD_SYNCHRONIZATION_H__
Dali Docs Home
Read more about Dali