summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2015-09-11 13:34:34 -0400
committerScott Hernandez <scotthernandez@gmail.com>2015-09-11 14:49:18 -0400
commite582523ba15d9fae2af2318e1f2c5e23f82c40ff (patch)
tree38eadf4b2e7b7379ab386d288d38f4816dd50bc9
parentf392156ae941c58c7c1dbe9151e1656afd5b0eec (diff)
downloadmongo-e582523ba15d9fae2af2318e1f2c5e23f82c40ff.tar.gz
SERVER-20161: allow capped collection insert notifier to externally notified
-rw-r--r--src/mongo/db/catalog/collection.cpp12
-rw-r--r--src/mongo/db/catalog/collection.h14
2 files changed, 25 insertions, 1 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index fd48011e54f..c754ce46254 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -125,6 +125,11 @@ void CappedInsertNotifier::notifyOfInsert(int count) {
_cappedNewDataNotifier.notify_all();
}
+void CappedInsertNotifier::notifyAll() {
+ stdx::lock_guard<stdx::mutex> lk(_cappedNewDataMutex);
+ _cappedNewDataNotifier.notify_all();
+}
+
uint64_t CappedInsertNotifier::getCount() const {
stdx::lock_guard<stdx::mutex> lk(_cappedNewDataMutex);
return _cappedInsertCount;
@@ -139,6 +144,13 @@ void CappedInsertNotifier::waitForInsert(uint64_t referenceCount, Microseconds t
}
}
+void CappedInsertNotifier::waitForInsert(uint64_t referenceCount) const {
+ stdx::unique_lock<stdx::mutex> lk(_cappedNewDataMutex);
+ while (!_dead && referenceCount == _cappedInsertCount) {
+ _cappedNewDataNotifier.wait(lk);
+ }
+}
+
void CappedInsertNotifier::kill() {
stdx::lock_guard<stdx::mutex> lk(_cappedNewDataMutex);
_dead = true;
diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h
index 61d32a53aef..6a5e3819fbb 100644
--- a/src/mongo/db/catalog/collection.h
+++ b/src/mongo/db/catalog/collection.h
@@ -114,6 +114,11 @@ public:
void notifyOfInsert(int count);
/**
+ * Wakes up all threads waiting but doesn't increment the count.
+ */
+ void notifyAll();
+
+ /**
* Get a counter value which is incremented on every insert into a capped collection.
* The return value should be used as a reference value to pass into waitForCappedInsert().
*/
@@ -122,11 +127,18 @@ public:
/**
* Waits for 'timeout' microseconds, or until notifyAll() is called to indicate that new
* data is available in the capped collection.
+ *
+ * NOTE: Waiting threads can be signaled by calling kill or notify* methods.
*/
void waitForInsert(uint64_t referenceCount, Microseconds timeout) const;
/**
- * Cancels the notifier if the collection is dropped/invalidated.
+ * Same as above but without a timeout.
+ */
+ void waitForInsert(uint64_t referenceCount) const;
+
+ /**
+ * Cancels the notifier if the collection is dropped/invalidated, and wakes all waiting.
*/
void kill();