BIND 10 trac2198, updated. a7d142baf404d969e1baa45669efab1ebee3163f [2198] Add some code comments
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Sep 11 15:31:00 UTC 2012
The branch, trac2198 has been updated
via a7d142baf404d969e1baa45669efab1ebee3163f (commit)
from 3e227e24d70b739e365383446366086fedb8b7d0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a7d142baf404d969e1baa45669efab1ebee3163f
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Sep 11 21:00:40 2012 +0530
[2198] Add some code comments
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/interprocess_sync_file.cc | 11 +++++++++++
1 file changed, 11 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/util/interprocess_sync_file.cc b/src/lib/util/interprocess_sync_file.cc
index b797dea..81502c9 100644
--- a/src/lib/util/interprocess_sync_file.cc
+++ b/src/lib/util/interprocess_sync_file.cc
@@ -28,6 +28,9 @@
#include <assert.h>
namespace {
+// The size_t counts the number of current InterprocessSyncFile
+// objects with the same task name. The pthread_mutex_t is the lock that
+// should be first acquired by every thread when locking.
typedef std::pair<size_t,pthread_mutex_t> SyncMapData;
typedef std::map <std::string,SyncMapData*> SyncMap;
@@ -48,12 +51,14 @@ InterprocessSyncFile::InterprocessSyncFile(const std::string& task_name) :
if (it != sync_map.end()) {
data = it->second;
} else {
+ // No data was found in the map, so create and insert one.
data = new SyncMapData;
data->first = 0;
pthread_mutex_init(&data->second, NULL);
sync_map[task_name] = data;
}
+ // Increment number of users for this task_name.
data->first++;
pthread_mutex_unlock(&sync_map_mutex);
@@ -140,6 +145,7 @@ InterprocessSyncFile::lock() {
return (true);
}
+ // First grab the thread lock...
SyncMap::iterator it = sync_map.find(task_name_);
assert(it != sync_map.end());
@@ -148,6 +154,7 @@ InterprocessSyncFile::lock() {
return (false);
}
+ // ... then the file lock.
if (do_lock(F_SETLKW, F_WRLCK)) {
is_locked_ = true;
return (true);
@@ -163,6 +170,7 @@ InterprocessSyncFile::tryLock() {
return (true);
}
+ // First grab the thread lock...
SyncMap::iterator it = sync_map.find(task_name_);
assert(it != sync_map.end());
@@ -171,6 +179,7 @@ InterprocessSyncFile::tryLock() {
return (false);
}
+ // ... then the file lock.
if (do_lock(F_SETLK, F_WRLCK)) {
is_locked_ = true;
return (true);
@@ -186,10 +195,12 @@ InterprocessSyncFile::unlock() {
return (true);
}
+ // First release the file lock...
if (do_lock(F_SETLKW, F_UNLCK) == 0) {
return (false);
}
+ // ... then the thread lock.
SyncMap::iterator it = sync_map.find(task_name_);
assert(it != sync_map.end());
More information about the bind10-changes
mailing list