aboutsummaryrefslogtreecommitdiffstats
path: root/src/applist.cpp
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-06-13 09:26:17 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-06-13 09:26:17 +0900
commit314ed7419472933fd3aa7a71e6df9d4ea294e9c3 (patch)
treeb72ea418c3fff8f1e7b13bab6542bf149bbb5c5f /src/applist.cpp
parentbdf5562f360402f810278ccbb3fdbab6b464d1c3 (diff)
Add mutex lock
Change-Id: Id7449b8ccbad67a958efd3dccf7c5d4a0dd41d97 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src/applist.cpp')
-rw-r--r--src/applist.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/applist.cpp b/src/applist.cpp
index d0082dd..77f1b2b 100644
--- a/src/applist.cpp
+++ b/src/applist.cpp
@@ -36,6 +36,7 @@ AppList::~AppList() {}
void AppList::addClient(const string &appid, const string &role)
{
+ std::lock_guard<std::mutex> lock(mtx);
shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, role);
this->app2client[appid] = client;
this->clientDump();
@@ -43,6 +44,7 @@ void AppList::addClient(const string &appid, const string &role)
void AppList::addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role)
{
+ std::lock_guard<std::mutex> lock(mtx);
shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, layer, surface, role);
this->app2client[appid] = client;
this->clientDump();
@@ -50,7 +52,9 @@ void AppList::addClient(const std::string &appid, unsigned layer, unsigned surfa
void AppList::removeClient(const string &appid)
{
+ std::lock_guard<std::mutex> lock(mtx);
this->app2client.erase(appid);
+ HMI_INFO("wm", "Remove client %s", appid.c_str());
}
bool AppList::contains(const string &appid) const
@@ -61,6 +65,7 @@ bool AppList::contains(const string &appid) const
void AppList::removeSurface(unsigned surface_id){
// This function may be very slow
+ std::lock_guard<std::mutex> lock(mtx);
bool ret = false;
for (auto &x : this->app2client)
{
@@ -70,6 +75,7 @@ void AppList::removeSurface(unsigned surface_id){
break;
}
}
+
}
/**
@@ -93,7 +99,6 @@ unsigned AppList::currentRequestNumber() const
return this->current_req;
}
-// Is this function necessary ?
unsigned AppList::getRequestNumber(const string &appid) const
{
for (const auto &x : this->req_list)
@@ -109,17 +114,18 @@ unsigned AppList::getRequestNumber(const string &appid) const
unsigned AppList::addAllocateRequest(WMRequest req)
{
+ std::lock_guard<std::mutex> lock(mtx);
if (this->req_list.size() == 0)
{
req.req_num = current_req;
}
else
{
- HMI_SEQ_DEBUG(this->current_req, "add: %d", this->req_list.back().req_num + 1);
+ HMI_SEQ_INFO(this->current_req, "add: %d", this->req_list.back().req_num + 1);
req.req_num = this->req_list.back().req_num + 1;
}
this->req_list.push_back(req);
- return req.req_num; // return 1; if you test time_expire
+ return req.req_num;
}
struct WMTrigger AppList::getRequest(unsigned req_num, bool *found)
@@ -133,6 +139,7 @@ struct WMTrigger AppList::getRequest(unsigned req_num, bool *found)
return x.trigger;
}
}
+ HMI_SEQ_ERROR(req_num, "Couldn't get request : %d", req_num);
return WMTrigger{"", "", "", Task::TASK_INVALID};
}
@@ -147,10 +154,12 @@ const vector<struct WMAction> &AppList::getActions(unsigned req_num, bool* found
return x.sync_draw_req;
}
}
+ HMI_SEQ_ERROR(req_num, "Couldn't get action with the request : %d", req_num);
}
WMError AppList::setAction(unsigned req_num, const struct WMAction &action)
{
+ std::lock_guard<std::mutex> lock(mtx);
WMError result = WMError::FAIL;
for (auto &x : this->req_list)
{
@@ -162,7 +171,6 @@ WMError AppList::setAction(unsigned req_num, const struct WMAction &action)
result = WMError::SUCCESS;
break;
}
-
return result;
}
@@ -175,6 +183,7 @@ WMError AppList::setAction(unsigned req_num, const struct WMAction &action)
*/
WMError AppList::setAction(unsigned req_num, const string &appid, const string &role, const string &area, bool visible)
{
+ std::lock_guard<std::mutex> lock(mtx);
WMError result = WMError::NOT_REGISTERED;
for (auto &x : req_list)
{
@@ -199,6 +208,7 @@ WMError AppList::setAction(unsigned req_num, const string &appid, const string &
*/
bool AppList::setEndDrawFinished(unsigned req_num, const string &appid, const string &role)
{
+ std::lock_guard<std::mutex> lock(mtx);
bool result = false;
for (auto &x : req_list)
{
@@ -254,6 +264,7 @@ bool AppList::endDrawFullfilled(unsigned req_num)
void AppList::removeRequest(unsigned req_num)
{
+ std::lock_guard<std::mutex> lock(mtx);
this->req_list.erase(remove_if(this->req_list.begin(), this->req_list.end(),
[req_num](WMRequest x) {
return x.req_num == req_num;
@@ -262,6 +273,7 @@ void AppList::removeRequest(unsigned req_num)
void AppList::next()
{
+ std::lock_guard<std::mutex> lock(mtx);
++this->current_req;
if (0 == this->current_req)
{