[gnote] add the lock to the tagmanager.
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnote] add the lock to the tagmanager.
- Date: Wed, 27 May 2009 17:33:42 -0400 (EDT)
commit 82d28f29bb7b8553898c9d8ab21e20bf7e3b2b69
Author: Hubert Figuiere <hub figuiere net>
Date: Sat Apr 11 03:09:43 2009 -0400
add the lock to the tagmanager.
---
src/tagmanager.cpp | 64 ++++++++++++++++++++++++++--------------------------
src/tagmanager.hpp | 8 +++---
2 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/src/tagmanager.cpp b/src/tagmanager.cpp
index ff973d0..0c513a6 100644
--- a/src/tagmanager.cpp
+++ b/src/tagmanager.cpp
@@ -74,13 +74,12 @@ namespace gnote {
std::vector<std::string> splits;
sharp::string_split(splits, normalized_tag_name, ":");
if ((splits.size() > 2) || sharp::string_starts_with(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)) {
-// lock (locker) {
+ Glib::Mutex::Lock lock(m_locker);
std::map<std::string, Tag::Ptr>::const_iterator iter = m_internal_tags.find(normalized_tag_name);
if(iter != m_internal_tags.end()) {
return iter->second;
}
return Tag::Ptr();
-// }
}
std::map<std::string, Gtk::TreeIter>::const_iterator iter = m_tag_map.find(normalized_tag_name);
if (iter != m_tag_map.end()) {
@@ -106,7 +105,7 @@ namespace gnote {
std::vector<std::string> splits;
sharp::string_split(splits, normalized_tag_name, ":");
if ((splits.size() > 2) || sharp::string_starts_with(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)){
-// lock (locker) {
+ Glib::Mutex::Lock lock(m_locker);
std::map<std::string, Tag::Ptr>::iterator iter;
iter = m_internal_tags.find(normalized_tag_name);
if(iter != m_internal_tags.end()) {
@@ -117,14 +116,14 @@ namespace gnote {
m_internal_tags [ t->normalized_name() ] = t;
return t;
}
-// }
}
Gtk::TreeIter iter;
bool tag_added = false;
Tag::Ptr tag = get_tag (normalized_tag_name);
if (!tag) {
-// -- Hub - WTF do we lookup twice?
-// lock (locker) {
+
+ Glib::Mutex::Lock lock(m_locker);
+
tag = get_tag (normalized_tag_name);
if (!tag) {
tag.reset(new Tag (sharp::string_trim(tag_name)));
@@ -134,7 +133,6 @@ namespace gnote {
tag_added = true;
}
-// }
}
if (tag_added) {
@@ -185,38 +183,40 @@ namespace gnote {
throw sharp::Exception ("TagManager.RemoveTag () called with a null tag");
if(tag->is_property() || tag->is_system()){
-// lock (locker) {
+
+ Glib::Mutex::Lock lock(m_locker);
+
m_internal_tags.erase(tag->normalized_name());
-// }
}
bool tag_removed = false;
std::map<std::string, Gtk::TreeIter>::iterator map_iter;
map_iter = m_tag_map.find(tag->normalized_name());
if (map_iter != m_tag_map.end()) {
-// lock (locker) {
- map_iter = m_tag_map.find(tag->normalized_name());
- if (map_iter != m_tag_map.end()) {
- Gtk::TreeIter iter = map_iter->second;
- if (!m_tags->erase(iter)) {
- DBG_OUT("TagManager: Removed tag: %s", tag->normalized_name().c_str());
- }
- else {
- // FIXME: For some really weird reason, this block actually gets called sometimes!
- DBG_OUT("TagManager: Call to remove tag from ListStore failed: %s", tag->normalized_name().c_str());
- }
-
- m_tag_map.erase(map_iter);
- DBG_OUT("Removed TreeIter from tag_map: %s", tag->normalized_name().c_str());
- tag_removed = true;
-
- std::list<Note*> notes;
- tag->get_notes(notes);
- for(std::list<Note*>::const_iterator note_iter = notes.begin();
- note_iter != notes.end(); ++note_iter) {
- (*note_iter)->remove_tag(tag);
- }
+
+ Glib::Mutex::Lock lock(m_locker);
+
+ map_iter = m_tag_map.find(tag->normalized_name());
+ if (map_iter != m_tag_map.end()) {
+ Gtk::TreeIter iter = map_iter->second;
+ if (!m_tags->erase(iter)) {
+ DBG_OUT("TagManager: Removed tag: %s", tag->normalized_name().c_str());
+ }
+ else {
+ // FIXME: For some really weird reason, this block actually gets called sometimes!
+ DBG_OUT("TagManager: Call to remove tag from ListStore failed: %s", tag->normalized_name().c_str());
}
-// }
+
+ m_tag_map.erase(map_iter);
+ DBG_OUT("Removed TreeIter from tag_map: %s", tag->normalized_name().c_str());
+ tag_removed = true;
+
+ std::list<Note*> notes;
+ tag->get_notes(notes);
+ for(std::list<Note*>::const_iterator note_iter = notes.begin();
+ note_iter != notes.end(); ++note_iter) {
+ (*note_iter)->remove_tag(tag);
+ }
+ }
}
if (tag_removed) {
diff --git a/src/tagmanager.hpp b/src/tagmanager.hpp
index 15789c0..be9e062 100644
--- a/src/tagmanager.hpp
+++ b/src/tagmanager.hpp
@@ -26,6 +26,7 @@
#include <sigc++/signal.h>
+#include <glibmm/thread.h>
#include <gtkmm/liststore.h>
#include <gtkmm/treemodelsort.h>
@@ -67,13 +68,12 @@ private:
ColumnRecord m_columns;
Glib::RefPtr<Gtk::ListStore> m_tags;
Glib::RefPtr<Gtk::TreeModelSort> m_sorted_tags;
- // <summary>
// The key for this dictionary is Tag.Name.ToLower ().
- // </summary>
typedef std::map<std::string, Gtk::TreeIter> TagMap;
- TagMap m_tag_map;
+ TagMap m_tag_map;
typedef std::map<std::string, Tag::Ptr> InternalMap;
- InternalMap m_internal_tags;
+ InternalMap m_internal_tags;
+ mutable Glib::Mutex m_locker;
sigc::signal<void, Tag::Ptr, const Gtk::TreeIter &> m_signal_tag_added;
sigc::signal<void, const std::string &> m_signal_tag_removed;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]