[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-core.git] / dali / devel-api / threading / mutex.h
1 #ifndef __DALI_MUTEX_H__
2 #define __DALI_MUTEX_H__
3
4 /*
5  * Copyright (c) 2018 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23
24 /**
25  * The top level DALi namespace
26  */
27 namespace Dali
28 {
29
30 /**
31  * Class to synchronize access to critical resources from multiple threads
32  */
33 class DALI_CORE_API Mutex
34 {
35 public:
36
37   /**
38    * @brief Constructor, acquires the mutex from the underlying OS
39    */
40   Mutex();
41
42   /**
43    * @brief Destructor, non virtual as this is not meant as a base class
44    */
45   ~Mutex();
46
47   /**
48    * @brief Check if the mutex is locked
49    * @return true if the mutex is locked
50    */
51   bool IsLocked();
52
53 public:
54
55   /**
56    * Helper class to do a scoped lock on a mutex implementing the RAII idiom.
57    * Note! this class *does not* prevent a deadlock in the case when same thread is
58    * locking the same mutex twice.
59    */
60   class DALI_CORE_API ScopedLock
61   {
62   public:
63
64     /**
65      * Constructor
66      * @param mutex to lock
67      */
68     ScopedLock( Mutex& mutex );
69
70     /**
71      * Destructor, releases the lock
72      */
73     ~ScopedLock();
74
75   private:
76     Mutex& mMutex;
77   };
78
79 private:
80
81   /// Not implemented as Mutex is not copyable
82   Mutex( const Mutex& );
83   const Mutex& operator= ( const Mutex& );
84
85   struct MutexImpl;
86   MutexImpl* mImpl;
87
88 };
89
90 } // namespace Dali
91
92 #endif // __DALI_MUTEX_H__