1 #ifndef __DALI_CONDITIONAL_WAIT_H__
2 #define __DALI_CONDITIONAL_WAIT_H__
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-common.h>
28 * Helper class to allow conditional waiting and notifications between multiple threads.
30 class DALI_CORE_API ConditionalWait
35 * @brief Allows client code to synchronize updates to its own state with the
36 * internal state of a ConditionalWait object.
38 class DALI_CORE_API ScopedLock
43 * @brief Will acquire the internal mutex of the ConditionalWait object passed in.
44 * @param[in] wait The ConditionalWait object to lock.
46 ScopedLock( ConditionalWait& wait );
50 * @brief Will release the internal mutex of the ConditionalWait object passed in.
55 * Getter for the ConditionalWait locked for this instance's lifetime.
56 * @return the ConditionalWait object currently locked.
58 ConditionalWait& GetLockedWait() const;
60 public: // Data, public to allow nesting class to access
62 struct ScopedLockImpl;
63 ScopedLockImpl* mImpl;
67 // Not implemented as ScopedLock cannot be copied:
68 ScopedLock( const ScopedLock& );
69 const ScopedLock& operator=( const ScopedLock& );
73 * @brief Constructor, creates the internal synchronization objects
78 * @brief Destructor, non-virtual as this is not a base class
83 * @brief Notifies another thread to continue if it is blocked on a wait.
85 * Can be called from any thread.
86 * Does not block the current thread but may cause a rescheduling of threads.
91 * @brief Notifies another thread to continue if it is blocked on a wait.
93 * Assumes that the ScopedLock object passed in has already locked the internal state of
95 * Can be called from any thread.
96 * Does not block the current thread but may cause a rescheduling of threads.
98 * @param[in] scope A pre-existing lock on the internal state of this object.
100 void Notify( const ScopedLock& scope );
103 * @brief Wait for another thread to notify us when the condition is true and we can continue
105 * Will always block current thread until Notify is called
110 * @brief Wait for another thread to notify us when the condition is true and we can continue
112 * Will always block current thread until Notify is called.
113 * Assumes that the ScopedLock object passed in has already locked the internal state of
114 * this object. Releases the lock while waiting and re-acquires it when returning
116 * @param[in] scope A pre-existing lock on the internal state of this object.
117 * @pre scope must have been passed this ConditionalWait during its construction.
119 void Wait( const ScopedLock& scope );
122 * @brief Return the count of threads waiting for this conditional
123 * @return count of waits
125 unsigned int GetWaitCount() const;
129 // Not implemented as ConditionalWait is not copyable
130 ConditionalWait( const ConditionalWait& );
131 const ConditionalWait& operator=( const ConditionalWait& );
133 struct ConditionalWaitImpl;
134 ConditionalWaitImpl* mImpl;
140 #endif // __DALI_CONDITIONAL_WAIT_H__