diff options
-rw-r--r-- | src/applist.cpp | 20 | ||||
-rw-r--r-- | src/applist.hpp | 2 |
2 files changed, 18 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) { diff --git a/src/applist.hpp b/src/applist.hpp index 10c2947..c0cc298 100644 --- a/src/applist.hpp +++ b/src/applist.hpp @@ -20,6 +20,7 @@ #include <string> #include <map> #include <memory> +#include <mutex> #include "wm_client.hpp" #include "request.hpp" #include "wm_error.hpp" @@ -71,6 +72,7 @@ class AppList std::vector<WMRequest> req_list; std::unordered_map<std::string, std::shared_ptr<WMClient>> app2client; unsigned current_req; + std::mutex mtx; }; } // namespace wm |