[Notification] Remove locking from NotificationManager in mobile
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 18 Sep 2013 17:18:06 +0000 (14:18 -0300)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 18 Sep 2013 17:24:23 +0000 (14:24 -0300)
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.

notification/mobile/notification_manager.cc
notification/mobile/notification_manager.h

index e20997a..2fcf480 100644 (file)
@@ -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<void*>(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.
index e37d3e1..8cab3e9 100644 (file)
@@ -6,7 +6,6 @@
 #define NOTIFICATION_MOBILE_NOTIFICATION_MANAGER_H_
 
 #include <notification.h>
-#include <pthread.h>
 #include <map>
 #include <string>
 
@@ -80,7 +79,6 @@ class NotificationManager {
   }
 
   IDMap id_map_;
-  pthread_mutex_t mutex_;
 };
 
 #endif  // NOTIFICATION_MOBILE_NOTIFICATION_MANAGER_H_