Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/anim
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-09-26 20:33:22 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:44:16 +0300
commitff3bc1517475102ccac59dc2364fa2a292a906e6 (patch)
tree027be6e01b69b0e1abe66d76012c98c5ec871f76 /anim
parente02d4165cec23a5dca58866c5ca16397c17835a1 (diff)
anim::Task::Lock/Unlock for synchronization of task state changes in different threads.
Diffstat (limited to 'anim')
-rw-r--r--anim/task.cpp16
-rw-r--r--anim/task.hpp9
2 files changed, 22 insertions, 3 deletions
diff --git a/anim/task.cpp b/anim/task.cpp
index c921fc8789..b012ce2fc7 100644
--- a/anim/task.cpp
+++ b/anim/task.cpp
@@ -14,14 +14,26 @@ namespace anim
return m_State;
}
+ void Task::Lock()
+ {
+ m_mutex.Lock();
+ }
+
+ void Task::Unlock()
+ {
+ m_mutex.Unlock();
+ }
+
void Task::SetState(EState State)
{
+ Lock();
m_State = State;
+ Unlock();
}
void Task::PerformCallback(EState state)
{
- TCallback const & cb = m_callbacks[state];
+ TCallback const & cb = m_Callbacks[state];
if (cb)
cb();
}
@@ -74,6 +86,6 @@ namespace anim
void Task::SetCallback(EState state, TCallback const & cb)
{
- m_callbacks[state] = cb;
+ m_Callbacks[state] = cb;
}
}
diff --git a/anim/task.hpp b/anim/task.hpp
index d898a972ef..d55c61d129 100644
--- a/anim/task.hpp
+++ b/anim/task.hpp
@@ -3,6 +3,8 @@
#include "../std/map.hpp"
#include "../std/function.hpp"
+#include "../base/mutex.hpp"
+
namespace anim
{
// Interface for single animation task
@@ -24,10 +26,12 @@ namespace anim
EState m_State;
- map<EState, TCallback> m_callbacks;
+ map<EState, TCallback> m_Callbacks;
void PerformCallback(EState state);
+ threads::Mutex m_mutex;
+
protected:
void SetState(EState state);
@@ -51,6 +55,9 @@ namespace anim
bool IsEnded() const;
bool IsRunning() const;
+ void Lock();
+ void Unlock();
+
void SetCallback(EState state, TCallback const & cb);
};
}