From: Caio Marcelo de Oliveira Filho Date: Wed, 18 Sep 2013 17:18:06 +0000 (-0300) Subject: [Notification] Remove locking from NotificationManager in mobile X-Git-Tag: accepted/tizen/generic/20140324.124941~134^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=50160ca8ab76bed27eb30d6f7e402a337c7af737;p=platform%2Fframework%2Fweb%2Ftizen-extensions-crosswalk.git [Notification] Remove locking from NotificationManager in mobile Locking was necessary because each instance was running in a separated thread, but now all of them share the same thread, so it's safe to access shared state without locking. --- diff --git a/notification/mobile/notification_manager.cc b/notification/mobile/notification_manager.cc index e20997a..2fcf480 100644 --- a/notification/mobile/notification_manager.cc +++ b/notification/mobile/notification_manager.cc @@ -4,28 +4,14 @@ #include "notification/mobile/notification_manager.h" -// Utility to lock a mutex and unlock it in the end of the scope. -struct AutoLock { - explicit AutoLock(pthread_mutex_t* m) : m_(m) { pthread_mutex_lock(m_); } - ~AutoLock() { pthread_mutex_unlock(m_); } - private: - pthread_mutex_t* m_; -}; - NotificationManager::NotificationManager() { - pthread_mutex_init(&mutex_, NULL); notification_register_detailed_changed_cb( OnDetailedChanged, reinterpret_cast(this)); } -NotificationManager::~NotificationManager() { - // Extension should outlive all its contexts, so when it is shutdown, all the - // contexts were destroyed, so no contention here. - pthread_mutex_destroy(&mutex_); -} +NotificationManager::~NotificationManager() {} notification_h NotificationManager::CreateNotification() { - AutoLock lock(&mutex_); return notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE); @@ -34,7 +20,6 @@ notification_h NotificationManager::CreateNotification() { bool NotificationManager::PostNotification(const std::string& id, notification_h notification, NotificationClient* client) { - AutoLock lock(&mutex_); int priv_id; notification_error_e err = notification_insert(notification, &priv_id); if (err != NOTIFICATION_ERROR_NONE) @@ -50,7 +35,6 @@ bool NotificationManager::PostNotification(const std::string& id, } bool NotificationManager::RemoveNotification(const std::string& id) { - AutoLock lock(&mutex_); IDMap::iterator it = id_map_.find(id); if (it == id_map_.end()) return false; @@ -64,7 +48,6 @@ bool NotificationManager::RemoveNotification(const std::string& id) { } void NotificationManager::DetachClient(NotificationClient* client) { - AutoLock lock(&mutex_); IDMap::iterator it = id_map_.begin(); while (it != id_map_.end()) { IDMap::iterator current = it++; @@ -78,7 +61,6 @@ void NotificationManager::DetachClient(NotificationClient* client) { void NotificationManager::OnDetailedChanged( notification_type_e type, notification_op* op_list, int num_op) { - AutoLock lock(&mutex_); // This function gets warned about every notification event for every // application. This code filters so we just look into removals of priv_ids // handled by this manager. diff --git a/notification/mobile/notification_manager.h b/notification/mobile/notification_manager.h index e37d3e1..8cab3e9 100644 --- a/notification/mobile/notification_manager.h +++ b/notification/mobile/notification_manager.h @@ -6,7 +6,6 @@ #define NOTIFICATION_MOBILE_NOTIFICATION_MANAGER_H_ #include -#include #include #include @@ -80,7 +79,6 @@ class NotificationManager { } IDMap id_map_; - pthread_mutex_t mutex_; }; #endif // NOTIFICATION_MOBILE_NOTIFICATION_MANAGER_H_