BIND 10 trac2198, updated. 2e2ddb0e28f6a5b8ff263bec7a0fda0eb38730df [2198] Test InterprocessSyncFile implementation using threads
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Sep 11 16:41:33 UTC 2012
The branch, trac2198 has been updated
via 2e2ddb0e28f6a5b8ff263bec7a0fda0eb38730df (commit)
via 30bbc25ab8d87af4c5924671430388ae1df188f5 (commit)
from a7d142baf404d969e1baa45669efab1ebee3163f (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 2e2ddb0e28f6a5b8ff263bec7a0fda0eb38730df
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Sep 11 22:11:17 2012 +0530
[2198] Test InterprocessSyncFile implementation using threads
commit 30bbc25ab8d87af4c5924671430388ae1df188f5
Author: Mukund Sivaraman <muks at isc.org>
Date: Tue Sep 11 22:10:08 2012 +0530
[2198] Remove space
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/interprocess_sync_file.cc | 2 +-
.../util/tests/interprocess_sync_file_unittest.cc | 47 ++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
-----------------------------------------------------------------------
diff --git a/src/lib/util/interprocess_sync_file.cc b/src/lib/util/interprocess_sync_file.cc
index 81502c9..8bed4fe 100644
--- a/src/lib/util/interprocess_sync_file.cc
+++ b/src/lib/util/interprocess_sync_file.cc
@@ -32,7 +32,7 @@ namespace {
// 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;
+typedef std::map<std::string,SyncMapData*> SyncMap;
pthread_mutex_t sync_map_mutex = PTHREAD_MUTEX_INITIALIZER;
SyncMap sync_map;
diff --git a/src/lib/util/tests/interprocess_sync_file_unittest.cc b/src/lib/util/tests/interprocess_sync_file_unittest.cc
index 9a1b025..a244933 100644
--- a/src/lib/util/tests/interprocess_sync_file_unittest.cc
+++ b/src/lib/util/tests/interprocess_sync_file_unittest.cc
@@ -15,6 +15,7 @@
#include "util/interprocess_sync_file.h"
#include <gtest/gtest.h>
#include <unistd.h>
+#include <pthread.h>
using namespace std;
@@ -108,6 +109,52 @@ TEST(InterprocessSyncFileTest, TestLock) {
EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test_lockfile"));
}
+void*
+test_thread_fn(void* data)
+{
+ bool* locked = static_cast<bool*>(data);
+
+ InterprocessSyncFile sync2("test");
+ InterprocessSyncLocker locker2(sync2);
+
+ *locked = !locker2.tryLock();
+
+ return NULL;
+}
+
+TEST(InterprocessSyncFileTest, TestLockThreaded) {
+ InterprocessSyncFile sync("test");
+ InterprocessSyncLocker locker(sync);
+
+ EXPECT_FALSE(locker.isLocked());
+ EXPECT_TRUE(locker.lock());
+ EXPECT_TRUE(locker.isLocked());
+
+ bool locked_in_other_thread = false;
+
+ // Here, we check that a lock has been taken by creating a new thread
+ // and checking from the new thread that a lock exists. The lock
+ // attempt must fail to pass our check.
+
+ pthread_t thread;
+ pthread_create(&thread, NULL, test_thread_fn, &locked_in_other_thread);
+ pthread_join(thread, NULL);
+
+ EXPECT_TRUE(locked_in_other_thread);
+
+ // Release the lock and try again. This time, the attempt must pass.
+
+ EXPECT_TRUE(locker.unlock());
+ EXPECT_FALSE(locker.isLocked());
+
+ pthread_create(&thread, NULL, test_thread_fn, &locked_in_other_thread);
+ pthread_join(thread, NULL);
+
+ EXPECT_FALSE(locked_in_other_thread);
+
+ EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test_lockfile"));
+}
+
TEST(InterprocessSyncFileTest, TestMultipleFilesDirect) {
InterprocessSyncFile sync("test1");
InterprocessSyncLocker locker(sync);
More information about the bind10-changes
mailing list