BIND 10 trac2298, updated. 753b377a669fd5bc8663838288b65e9a73c54ec7 [2298] skip test_do_GET() if XMLParser() is unavailable

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Oct 17 10:19:26 UTC 2012


The branch, trac2298 has been updated
  discards  bac00930bab6b7b78e621382aa8a0c869f00c4a2 (commit)
  discards  ffd348cbe28428db42e663c0a43cbe5ba356abb5 (commit)
  discards  6805110218305a94849f9c31ca64f51298ba369b (commit)
  discards  b318eeb0e7ad6b7afd21cf8860f294474ceb38ec (commit)
  discards  7ce6eca8b21f43ef53ce8a52340cb578c294d201 (commit)
  discards  74fcd65d1ff620ff958c411bad697ce13e6d9e1e (commit)
  discards  31438436daa45f7acac83707ed23348a6cf146e5 (commit)
  discards  8c344e514ed5262cc50467ad88355a9bbd93a400 (commit)
  discards  c782571ec9bf5d66a6e212060d5fca1c99068f41 (commit)
  discards  722e021fd822b4d01493b611b071c4f841b15935 (commit)
  discards  d707753dc73e1a9fc784b5e28419fb84742d355d (commit)
  discards  e33c7316e5e60b1b3151b33b7eabc7e1f6b45ef4 (commit)
  discards  aa483cd5bef61b40a74bfe4b65ac8bedde30f02c (commit)
  discards  65cd70c8983777b3c183d43064b2d5217e2e3a6c (commit)
  discards  86bbf73d3999e1fdc6f19bbd220c8a7a781f42e4 (commit)
  discards  2234fad395f1fb78fda6a3733ce0aed4ad309144 (commit)
  discards  99e40acc0ae66cbb82c03a7265a88fea5d349c7a (commit)
  discards  4e92833ca73b9b19d32442fd3befb51ce13756f6 (commit)
  discards  bbe84c8af27d38d36c4e05f99589e988096d4471 (commit)
  discards  76140c55d28e9ffecfc67827a4eec0c172813671 (commit)
  discards  69de152bd05f41dc0cf2c51a1598ad49bb688931 (commit)
  discards  309d6933e2c756861ae1c180a9582928f78c5bed (commit)
  discards  64c2f156adfadb5ef56bbd5b907c87068fb4556c (commit)
  discards  6dca85aa4a7892d89e3375b7ff8b205248c3a3f1 (commit)
  discards  a312d3cca07570976f674ac3cf290bdd4d0fd03e (commit)
  discards  753ad7b5833e2deadb02de991be382317d43963d (commit)
  discards  ebf84ed39844d7e34ab20091c33454a180eae212 (commit)
  discards  bdbfc777cb1a293d8ee7f62e36423388d171fe84 (commit)
       via  753b377a669fd5bc8663838288b65e9a73c54ec7 (commit)
       via  d7b7c2a1cef0b4bfa11b6cec3e5070fe0c78f4d1 (commit)
       via  3c04bb23dce397aefef8bf9f626c99f01bec63a4 (commit)
       via  bc4bddbda26bdb8e4e4ce2eb3a0eefd5ebfa2650 (commit)
       via  57e21d31b2695fa8c3f7c7d80979ce8103c66c91 (commit)
       via  f44c42b1f11c1574f76a6e9b8935e8fec39907c8 (commit)
       via  a86eebb1982ce6b21fd57175114884b64e794f5c (commit)
       via  69f3f54f6f6d3ab775e89ecd1ee57129977ef3cf (commit)
       via  5286dd79066458a3c2ad461ddf2a22df313e91a2 (commit)
       via  d663e87b685b13dcebeb1f31120033443656dbc1 (commit)
       via  b1282dc00a166f47c1d868ba684a0ae06ab3f2cb (commit)
       via  68df7dd6a6bb36a127658a1ce163158add00abf9 (commit)
       via  30cf851eb157e5f4882b3c600dcdf914151f0a9b (commit)
       via  2f26b133bace7fd8838b0e0d32212ff56d3e518b (commit)
       via  d4a9ae9ce131496983e4a0636f6fabd150e1a41d (commit)
       via  7e6faa1a1662b88ff02de63208e3bebd7af2adae (commit)
       via  0e07142495d8feee1b02723bd7e827b8c3f0e3c6 (commit)
       via  351a2c052d157bf926a24a2203acb7a93766faa8 (commit)
       via  0a41ff79d9205e6e50d83a6aa0e4034b93af0ba8 (commit)
       via  456e69b264b79938dff4756c98f437c457a3171d (commit)
       via  65a0f45cb7c8c0da51d4e3175f69595462f6c45f (commit)
       via  0d35b9fbd99940133458b766384910da111b8056 (commit)
       via  e44e9c863ee47550e486601317a79d6a7d8512d5 (commit)
       via  3d17e60b4359adb424ebfe8ff8ddeb9c0a3bc593 (commit)
       via  bba78213d16af807c9ebbc98634c769633a721f9 (commit)
       via  7a2a76e6fee7709698ee1fa5ff8217d7053113f7 (commit)
       via  d23d5485fa10b66d227b7e7f39cc99e93db6f294 (commit)
       via  2252c5776f5447f47e567262f8a5a05753fc6ce9 (commit)
       via  f559b99dcccd35703989fce985ff200cd664ccc0 (commit)
       via  c91151db16e215692830bf9b6211c22aae8619dc (commit)
       via  7ffd1e0cad3bd125b490953dbea9f22c67e40fae (commit)
       via  34701adba7f7390640c70ba769cdb0b20f01f82c (commit)
       via  42c638e07a45b69d902a51b35838ae21ac19d116 (commit)
       via  8d321e3ea9f85227296cfac94a9ce79c7db70fdf (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (bac00930bab6b7b78e621382aa8a0c869f00c4a2)
            \
             N -- N -- N (753b377a669fd5bc8663838288b65e9a73c54ec7)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

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 753b377a669fd5bc8663838288b65e9a73c54ec7
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 18:43:52 2012 +0900

    [2298] skip test_do_GET() if XMLParser() is unavailable
    
    skip test_do_GET() if XMLParser() is unavailable on the system. This
    is for Ticket #2048 (configure check for pyexpat).

commit d7b7c2a1cef0b4bfa11b6cec3e5070fe0c78f4d1
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 18:47:20 2012 +0900

    [2298] add a unittest using XML validation with XSD
    
    XML validation with XSD by using the lxml module. the lxml module is a
    third-party module. so if it is not installed on the system, the unittest using
    the validation would be skipped.

commit 3c04bb23dce397aefef8bf9f626c99f01bec63a4
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:30:48 2012 +0900

    [2298] modify test_xsl_handler()
    
    Remove the obsoleted content and add checks for items in the xsl
    document which can be also in the xml document.

commit bc4bddbda26bdb8e4e4ce2eb3a0eefd5ebfa2650
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 15:37:28 2012 +0900

    [2298] modify test_xsd_handler()
    
    Remove the obsoleted content and add checks for elements in the xsd document.

commit 57e21d31b2695fa8c3f7c7d80979ce8103c66c91
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:22:32 2012 +0900

    [2298] update test_xml_handler()
    
    Remove the obsoleted content and add checks for items in the xml document.

commit f44c42b1f11c1574f76a6e9b8935e8fec39907c8
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:22:02 2012 +0900

    [2298] use assertGreater() rather than assertTrue()

commit a86eebb1982ce6b21fd57175114884b64e794f5c
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:20:39 2012 +0900

    [2298] update HTTP status codes
    
    This change is due to the change of the status codes returned by
    b10-stats-httpd.

commit 69f3f54f6f6d3ab775e89ecd1ee57129977ef3cf
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:18:50 2012 +0900

    [2298] append a slash at the end of the URI

commit 5286dd79066458a3c2ad461ddf2a22df313e91a2
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 22:01:36 2012 +0900

    [2298] modify test_do_GET() and check_XSL_URL_PATH()
    
    This change is due to the change of the xsl format displayed by
    b10-stats-httpd.

commit d663e87b685b13dcebeb1f31120033443656dbc1
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:59:53 2012 +0900

    [2298] modify test_do_GET() and check_XSD_URL_PATH()
    
    This change is due to the change of the xsd format displayed by
    b10-stats-httpd.

commit b1282dc00a166f47c1d868ba684a0ae06ab3f2cb
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 10:49:53 2012 +0900

    [2298] modify test_do_GET() and check_XML_URL_PATH()
    
    This change is due to the change of the xml format displayed by
    b10-stats-httpd.

commit 68df7dd6a6bb36a127658a1ce163158add00abf9
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:16:06 2012 +0900

    [2298] add tests for item_name_list()

commit 30cf851eb157e5f4882b3c600dcdf914151f0a9b
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 10:24:57 2012 +0900

    [2298] add constants of XML namespaces for using in tests

commit 2f26b133bace7fd8838b0e0d32212ff56d3e518b
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 10:41:49 2012 +0900

    [2298] modify DUMMY_DATA
    
    For consistency with consts in test_utils.py. Modifying for consisting
    of time values based on CONST_BASETIME in test_utils.py. Modifying to
    counters returned from MockAuth in test_utils.py.

commit d4a9ae9ce131496983e4a0636f6fabd150e1a41d
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 11:15:01 2012 +0900

    [2298] add CONST_BASETIME and use it in MockBoss and MyStats classes
    
    Add fixed BASETIME not depending on the time module. And modify
    MockBoss and MockStats classes in order that they return time values
    of that. This is for testing b10-stats and b10-stats-httpd.

commit 7e6faa1a1662b88ff02de63208e3bebd7af2adae
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:14:46 2012 +0900

    [2298] modify the open_template() method
    
    open_template() throws StatsHttpdDataError instead of IOError when the
    specified file is not found. The parent class catches it and returns a
    404 status code.

commit 0e07142495d8feee1b02723bd7e827b8c3f0e3c6
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 13:16:54 2012 +0900

    [2298] modify test_xsl_handler()
    
    Remove the obsoleted content and add checks for items in the xsl document which
    can be also in the xml document.

commit 351a2c052d157bf926a24a2203acb7a93766faa8
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 13:15:49 2012 +0900

    [2298] modify the xsd_handler() method
    
    xsd_handler() doesn't accept any arguments such as a module name and a item
    name. It replaces variable strings in the template and displays it.

commit 0a41ff79d9205e6e50d83a6aa0e4034b93af0ba8
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 13:12:16 2012 +0900

    [2298] modify the xml_handler() method
    
    The requested URI is divided at the delimiter '/' and the module name and the
    top-level item name are extracted if there are. It requests statistics data and
    statistics schema of them the the stats daemon. It builds an xml document by
    the values returned from the stats daemon.

commit 456e69b264b79938dff4756c98f437c457a3171d
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:08:51 2012 +0900

    [2298] append a Last-Modified header
    
    This is because the server tells browsers that the contents are always
    being modified.

commit 65a0f45cb7c8c0da51d4e3175f69595462f6c45f
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:08:09 2012 +0900

    [2298] return a 500 status code when catching any exception

commit 0d35b9fbd99940133458b766384910da111b8056
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:07:10 2012 +0900

    [2298] modify handling the accepted URI
    
    - Do not return a dynamic page when being requested XSD or XSL. So
      pass nothing to xsd_handler() or xsl_handler(). Pass path in URI to
      xml_handler().
    
    - XML_URL_PATH is handled as a directory.  When XML_URL_PATH which
      doesn't ends with '/' is requested, the request is redirected to
      XML_URL_PATH + '/'.

commit e44e9c863ee47550e486601317a79d6a7d8512d5
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 13:07:27 2012 +0900

    [2298] add a method item_name_list()

commit 3d17e60b4359adb424ebfe8ff8ddeb9c0a3bc593
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 22:07:30 2012 +0900

    [2298] modify consts related to XML, XSD, and XSL
    
    change URIs of XSD and XSL to fixed ones

commit bba78213d16af807c9ebbc98634c769633a721f9
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:04:49 2012 +0900

    [2298] modify the xsl template file
    
    The XSL contents are fixed.

commit 7a2a76e6fee7709698ee1fa5ff8217d7053113f7
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 15 21:04:44 2012 +0900

    [2298] modify the xsd template file
    
    The XSD contents are fixed.

commit d23d5485fa10b66d227b7e7f39cc99e93db6f294
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 16 11:15:38 2012 +0900

    [2298] add copyright and update copyrights

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                          |    8 ---
 src/bin/stats/tests/b10-stats-httpd_test.py        |    7 +-
 src/lib/util/Makefile.am                           |    6 +-
 src/lib/util/interprocess_sync_file.cc             |   74 ++------------------
 src/lib/util/interprocess_sync_file.h              |   12 +---
 src/lib/util/tests/Makefile.am                     |    1 -
 .../util/tests/interprocess_sync_file_unittest.cc  |   47 +------------
 src/lib/util/threads/lock.cc                       |   13 ----
 src/lib/util/threads/lock.h                        |   55 ++-------------
 src/lib/util/threads/tests/lock_unittest.cc        |   38 ----------
 src/lib/util/unittests/Makefile.am                 |    3 +-
 11 files changed, 22 insertions(+), 242 deletions(-)

-----------------------------------------------------------------------
diff --git a/ChangeLog b/ChangeLog
index bbb78d9..9e76a18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,3 @@
-nnn.	[bug]*		naokikambe
-	Fixed an XML display by b10-stats-httpd. When viewing per-zone counters
-	as zones of Xfrout, that display wasn't an exact XML document. A zone
-	name can be specified in URI as
-	/bind10/statistics/xml/Xfrout/zones/example.org/xfrreqdone. XSD and XSL
-	formats are also changed to constant ones due to these changes.
-	(Trac #2298, git tbd)
-
 494.	[bug]		jinmei
 	Fixed a problem that shutting down BIND 10 kept some of the
 	processes alive.  It was two-fold: when the main bind10 process
diff --git a/src/bin/stats/tests/b10-stats-httpd_test.py b/src/bin/stats/tests/b10-stats-httpd_test.py
index e95ed72..33c4d54 100644
--- a/src/bin/stats/tests/b10-stats-httpd_test.py
+++ b/src/bin/stats/tests/b10-stats-httpd_test.py
@@ -222,7 +222,7 @@ class TestHttpHandler(unittest.TestCase):
         # reset the signal handler
         self.sig_handler.reset()
 
-    @unittest.skipUnless(xml_parser, "skipping the test using XMLParser") 
+    @unittest.skipUnless(xml_parser, "skipping the test using XMLParser")
     def test_do_GET(self):
         self.assertTrue(type(self.stats_httpd.httpd) is list)
         self.assertEqual(len(self.stats_httpd.httpd), 1)
@@ -253,7 +253,7 @@ class TestHttpHandler(unittest.TestCase):
                     '<?xml-stylesheet type="text/xsl" href="' + 
                     stats_httpd.XSL_URL_PATH
                     + '"?>'))
-            for elem in root.iterfind('item'):
+            for elem in root.find('item'):
                 attr = elem.attrib
                 value = isc.cc.data.find(DUMMY_DATA, attr['identifier'])
                 if type(value) is list or type(value) is dict:
@@ -838,6 +838,7 @@ class TestStatsHttpd(unittest.TestCase):
             )
         self.assertEqual(ret, 1)
 
+    @unittest.skipUnless(xml_parser, "skipping the test using XMLParser")
     def test_xml_handler(self):
         self.stats_httpd = MyStatsHttpd(get_availaddr())
         module_name = 'Dummy'
@@ -956,6 +957,7 @@ class TestStatsHttpd(unittest.TestCase):
             self.assertFalse('item_format' in spec)
             self.assertFalse('format' in stats_xml[i].attrib)
 
+    @unittest.skipUnless(xml_parser, "skipping the test using XMLParser") 
     def test_xsd_handler(self):
         self.stats_httpd = MyStatsHttpd(get_availaddr())
         xsd_string = self.stats_httpd.xsd_handler()
@@ -990,6 +992,7 @@ class TestStatsHttpd(unittest.TestCase):
                 self.assertEqual(attribs[i][1], stats_xsd[i].attrib['type'])
             self.assertEqual(attribs[i][2], stats_xsd[i].attrib['use'])
 
+    @unittest.skipUnless(xml_parser, "skipping the test using XMLParser") 
     def test_xsl_handler(self):
         self.stats_httpd = MyStatsHttpd(get_availaddr())
         xsl_string = self.stats_httpd.xsl_handler()
diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am
index 99b54eb..13f8f7b 100644
--- a/src/lib/util/Makefile.am
+++ b/src/lib/util/Makefile.am
@@ -1,5 +1,4 @@
-# InterprocessSyncFile has a dependency on isc::util::thread::Mutex
-SUBDIRS = io unittests threads . tests pyunittests python
+SUBDIRS = . io unittests tests pyunittests python threads
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
@@ -32,8 +31,7 @@ libb10_util_la_SOURCES += random/random_number_generator.h
 
 EXTRA_DIST = python/pycppwrapper_util.h
 
-libb10_util_la_LIBADD =  $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
-libb10_util_la_LIBADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
+libb10_util_la_LIBADD = $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
 CLEANFILES = *.gcno *.gcda
 
 libb10_util_includedir = $(includedir)/$(PACKAGE_NAME)/util
diff --git a/src/lib/util/interprocess_sync_file.cc b/src/lib/util/interprocess_sync_file.cc
index 6da3f14..d045449 100644
--- a/src/lib/util/interprocess_sync_file.cc
+++ b/src/lib/util/interprocess_sync_file.cc
@@ -14,9 +14,6 @@
 
 #include "interprocess_sync_file.h"
 
-#include <boost/weak_ptr.hpp>
-
-#include <map>
 #include <string>
 
 #include <stdlib.h>
@@ -26,38 +23,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-using namespace isc::util::thread;
-
 namespace isc {
 namespace util {
 
-namespace { // unnamed namespace
-
-typedef std::map<std::string, boost::weak_ptr<Mutex> > SyncMap;
-
-Mutex sync_map_mutex;
-SyncMap sync_map;
-
-} // end of unnamed namespace
-
-InterprocessSyncFile::InterprocessSyncFile(const std::string& task_name) :
-    InterprocessSync(task_name),
-    fd_(-1)
-{
-    Mutex::Locker locker(sync_map_mutex);
-
-    SyncMap::iterator it = sync_map.find(task_name);
-    if (it != sync_map.end()) {
-        mutex_ = it->second.lock();
-    } else {
-        mutex_.reset(new Mutex());
-        sync_map[task_name] = mutex_;
-    }
-
-    // Lock on sync_map_mutex is automatically unlocked during
-    // destruction when basic block is exited.
-}
-
 InterprocessSyncFile::~InterprocessSyncFile() {
     if (fd_ != -1) {
         // This will also release any applied locks.
@@ -65,23 +33,6 @@ InterprocessSyncFile::~InterprocessSyncFile() {
         // The lockfile will continue to exist, and we must not delete
         // it.
     }
-
-    Mutex::Locker locker(sync_map_mutex);
-
-    // Unref the shared mutex.
-    locker_.reset();
-    mutex_.reset();
-
-    // Remove name from the map if it is unused anymore.
-    SyncMap::iterator it = sync_map.find(task_name_);
-    assert(it != sync_map.end());
-
-    if (it->second.expired()) {
-        sync_map.erase(it);
-    }
-
-    // Lock on sync_map_mutex is automatically unlocked during
-    // destruction when basic block is exited.
 }
 
 bool
@@ -139,13 +90,8 @@ InterprocessSyncFile::lock() {
         return (true);
     }
 
-    // First grab the thread lock...
-    LockerPtr locker(new Mutex::Locker(*mutex_));
-
-    // ... then the file lock.
     if (do_lock(F_SETLKW, F_WRLCK)) {
         is_locked_ = true;
-        locker_ = locker;
         return (true);
     }
 
@@ -158,18 +104,8 @@ InterprocessSyncFile::tryLock() {
         return (true);
     }
 
-    // First grab the thread lock...
-    LockerPtr locker;
-    try {
-        locker.reset(new Mutex::Locker(*mutex_, false));
-    } catch (const Mutex::Locker::AlreadyLocked&) {
-        return (false);
-    }
-
-    // ... then the file lock.
     if (do_lock(F_SETLK, F_WRLCK)) {
         is_locked_ = true;
-        locker_ = locker;
         return (true);
     }
 
@@ -182,14 +118,12 @@ InterprocessSyncFile::unlock() {
         return (true);
     }
 
-    // First release the file lock...
-    if (do_lock(F_SETLKW, F_UNLCK) == 0) {
-        return (false);
+    if (do_lock(F_SETLKW, F_UNLCK)) {
+        is_locked_ = false;
+        return (true);
     }
 
-    locker_.reset();
-    is_locked_ = false;
-    return (true);
+    return (false);
 }
 
 } // namespace util
diff --git a/src/lib/util/interprocess_sync_file.h b/src/lib/util/interprocess_sync_file.h
index 5cb64c1..fd8da1b 100644
--- a/src/lib/util/interprocess_sync_file.h
+++ b/src/lib/util/interprocess_sync_file.h
@@ -16,11 +16,8 @@
 #define __INTERPROCESS_SYNC_FILE_H__
 
 #include <util/interprocess_sync.h>
-#include <util/threads/lock.h>
 #include <exceptions/exceptions.h>
 
-#include <boost/shared_ptr.hpp>
-
 namespace isc {
 namespace util {
 
@@ -58,7 +55,9 @@ public:
     /// \param name Name of the synchronization task. This has to be
     /// identical among the various processes that need to be
     /// synchronized for the same task.
-    InterprocessSyncFile(const std::string& task_name);
+    InterprocessSyncFile(const std::string& task_name) :
+        InterprocessSync(task_name), fd_(-1)
+    {}
 
     /// \brief Destructor
     virtual ~InterprocessSyncFile();
@@ -84,11 +83,6 @@ private:
     bool do_lock(int cmd, short l_type);
 
     int fd_; ///< The descriptor for the open file
-
-    typedef boost::shared_ptr<isc::util::thread::Mutex> MutexPtr;
-    typedef boost::shared_ptr<isc::util::thread::Mutex::Locker> LockerPtr;
-    MutexPtr mutex_;   ///< A mutex for mutual exclusion among threads
-    LockerPtr locker_; ///< A locker on mutex_
 };
 
 } // namespace util
diff --git a/src/lib/util/tests/Makefile.am b/src/lib/util/tests/Makefile.am
index 1a9c96a..105322f 100644
--- a/src/lib/util/tests/Makefile.am
+++ b/src/lib/util/tests/Makefile.am
@@ -46,7 +46,6 @@ run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
 
 run_unittests_LDADD = $(top_builddir)/src/lib/util/libb10-util.la
-run_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
 run_unittests_LDADD += $(top_builddir)/src/lib/util/io/libb10-util-io.la
 run_unittests_LDADD += \
 	$(top_builddir)/src/lib/util/unittests/libutil_unittests.la
diff --git a/src/lib/util/tests/interprocess_sync_file_unittest.cc b/src/lib/util/tests/interprocess_sync_file_unittest.cc
index 242cc5b..9a1b025 100644
--- a/src/lib/util/tests/interprocess_sync_file_unittest.cc
+++ b/src/lib/util/tests/interprocess_sync_file_unittest.cc
@@ -12,15 +12,10 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <util/interprocess_sync_file.h>
-#include <util/threads/thread.h>
-
+#include "util/interprocess_sync_file.h"
 #include <gtest/gtest.h>
-#include <boost/bind.hpp>
-
 #include <unistd.h>
 
-using namespace isc::util::thread;
 using namespace std;
 
 namespace isc {
@@ -113,46 +108,6 @@ TEST(InterprocessSyncFileTest, TestLock) {
   EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test_lockfile"));
 }
 
-void
-threadTest(bool* locked)
-{
-    InterprocessSyncFile sync2("test");
-    InterprocessSyncLocker locker2(sync2);
-
-    *locked = !locker2.tryLock();
-}
-
-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.
-    Thread thread(boost::bind(&threadTest, &locked_in_other_thread));
-    thread.wait();
-
-    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());
-
-    Thread thread2(boost::bind(&threadTest, &locked_in_other_thread));
-    thread2.wait();
-
-    EXPECT_FALSE(locked_in_other_thread);
-
-    EXPECT_EQ (0, unlink(TEST_DATA_TOPBUILDDIR "/test_lockfile"));
-}
-
 TEST(InterprocessSyncFileTest, TestMultipleFilesDirect) {
   InterprocessSyncFile sync("test1");
   InterprocessSyncLocker locker(sync);
diff --git a/src/lib/util/threads/lock.cc b/src/lib/util/threads/lock.cc
index acc73d6..6a165aa 100644
--- a/src/lib/util/threads/lock.cc
+++ b/src/lib/util/threads/lock.cc
@@ -119,19 +119,6 @@ Mutex::lock() {
     ++impl_->locked_count; // Only in debug mode
 }
 
-bool
-Mutex::tryLock() {
-    assert(impl_ != NULL);
-    const int result = pthread_mutex_trylock(&impl_->mutex);
-    if (result == EBUSY) {
-        return (false);
-    } else if (result != 0) {
-        isc_throw(isc::InvalidOperation, std::strerror(result));
-    }
-    ++impl_->locked_count; // Only in debug mode
-    return (true);
-}
-
 void
 Mutex::unlock() {
     assert(impl_ != NULL);
diff --git a/src/lib/util/threads/lock.h b/src/lib/util/threads/lock.h
index 4992bdb..fef537b 100644
--- a/src/lib/util/threads/lock.h
+++ b/src/lib/util/threads/lock.h
@@ -15,7 +15,6 @@
 #ifndef B10_THREAD_LOCK_H
 #define B10_THREAD_LOCK_H
 
-#include <exceptions/exceptions.h>
 #include <boost/noncopyable.hpp>
 
 #include <cstdlib> // for NULL.
@@ -77,39 +76,21 @@ public:
     /// of function no matter by what means.
     class Locker : public boost::noncopyable {
     public:
-        /// \brief Exception thrown when the mutex is already locked and
-        ///     a non-blocking locker is attempted around it.
-        struct AlreadyLocked : public isc::InvalidParameter {
-            AlreadyLocked(const char* file, size_t line, const char* what) :
-                isc::InvalidParameter(file, line, what)
-            {}
-        };
-
         /// \brief Constructor.
         ///
-        /// Locks the mutex. May block for extended period of time if
-        /// \c block is true.
+        /// Locks the mutex. May block for extended period of time.
         ///
         /// \throw isc::InvalidOperation when OS reports error. This usually
         ///     means an attempt to use the mutex in a wrong way (locking
         ///     a mutex second time from the same thread, for example).
-        /// \throw AlreadyLocked if \c block is false and the mutex is
-        ///     already locked.
-        Locker(Mutex& mutex, bool block = true) :
+        Locker(Mutex& mutex) :
             mutex_(NULL)
         {
             // Set the mutex_ after we acquire the lock. This is because of
             // exception safety. If lock() throws, it didn't work, so we must
             // not unlock when we are destroyed. In such case, mutex_ is
             // NULL and checked in the destructor.
-            if (block) {
-                mutex.lock();
-            } else {
-                if (!mutex.tryLock()) {
-                    isc_throw(AlreadyLocked, "The mutex is already locked");
-                }
-            }
-
+            mutex.lock();
             mutex_ = &mutex;
         }
 
@@ -124,7 +105,6 @@ public:
     private:
         Mutex* mutex_;
     };
-
     /// \brief If the mutex is currently locked
     ///
     /// This is debug aiding method only. And it might be unavailable in
@@ -133,36 +113,11 @@ public:
     ///
     /// \todo Disable in non-debug build
     bool locked() const;
-
-private:
-    /// \brief Lock the mutex
-    ///
-    /// This method blocks until the mutex can be locked.
-    ///
-    /// Please consider not using this method directly and instead using
-    /// a Mutex::Locker object instead.
-    void lock();
-
-    /// \brief Try to lock the mutex
-    ///
-    /// This method doesn't block and returns immediately with a status
-    /// on whether the lock operation was successful.
-    ///
-    /// Please consider not using this method directly and instead using
-    /// a Mutex::Locker object instead.
-    ///
-    /// \return true if the lock was successful, false otherwise.
-    bool tryLock();
-
-    /// \brief Unlock the mutex
-    ///
-    /// Please consider not using this method directly and instead using
-    /// a Mutex::Locker object instead.
-    void unlock();
-
 private:
     class Impl;
     Impl* impl_;
+    void lock();
+    void unlock();
 };
 
 
diff --git a/src/lib/util/threads/tests/lock_unittest.cc b/src/lib/util/threads/tests/lock_unittest.cc
index 8d337d5..0b4d3ce 100644
--- a/src/lib/util/threads/tests/lock_unittest.cc
+++ b/src/lib/util/threads/tests/lock_unittest.cc
@@ -37,44 +37,6 @@ TEST(MutexTest, lockMultiple) {
         Mutex::Locker l2(mutex); // Attempt to lock again.
     }, isc::InvalidOperation);
     EXPECT_TRUE(mutex.locked()); // Debug-only build
-
-    // block=true explicitly.
-    Mutex mutex2;
-    EXPECT_FALSE(mutex2.locked()); // Debug-only build
-    Mutex::Locker l12(mutex2, true);
-    EXPECT_TRUE(mutex2.locked()); // Debug-only build
-}
-
-void
-testThread(Mutex* mutex)
-{
-    // block=false (tryLock).  This should not block indefinitely, but
-    // throw AlreadyLocked. If block were true, this would block
-    // indefinitely here.
-    EXPECT_THROW({
-        Mutex::Locker l3(*mutex, false);
-    }, Mutex::Locker::AlreadyLocked);
-
-    EXPECT_TRUE(mutex->locked()); // Debug-only build
-}
-
-// Test the non-blocking variant using a second thread.
-TEST(MutexTest, lockNonBlocking) {
-    // block=false (tryLock).
-    Mutex mutex;
-    Mutex::Locker l1(mutex, false);
-    EXPECT_TRUE(mutex.locked()); // Debug-only build
-
-    // First, try another locker from the same thread.
-    EXPECT_THROW({
-        Mutex::Locker l2(mutex, false);
-    }, Mutex::Locker::AlreadyLocked);
-
-    EXPECT_TRUE(mutex.locked()); // Debug-only build
-
-    // Now try another locker from a different thread.
-    Thread thread(boost::bind(&testThread, &mutex));
-    thread.wait();
 }
 
 // Destroying a locked mutex is a bad idea as well
diff --git a/src/lib/util/unittests/Makefile.am b/src/lib/util/unittests/Makefile.am
index 6caa6bf..451ab4e 100644
--- a/src/lib/util/unittests/Makefile.am
+++ b/src/lib/util/unittests/Makefile.am
@@ -20,7 +20,8 @@ if HAVE_GTEST
 libutil_unittests_la_CPPFLAGS += $(GTEST_INCLUDES)
 endif
 
-libutil_unittests_la_LIBADD  = $(top_builddir)/src/lib/util/io/libb10-util-io.la
+libutil_unittests_la_LIBADD  = $(top_builddir)/src/lib/util/libb10-util.la
+libutil_unittests_la_LIBADD += $(top_builddir)/src/lib/util/io/libb10-util-io.la
 libutil_unittests_la_LIBADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
 
 CLEANFILES = *.gcno *.gcda



More information about the bind10-changes mailing list