summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/auth/user_cache_invalidator_job.cpp2
-rw-r--r--src/mongo/db/clientcursor.cpp2
-rw-r--r--src/mongo/db/db.cpp4
-rw-r--r--src/mongo/db/ftdc/controller.cpp2
-rw-r--r--src/mongo/db/range_deleter.cpp8
-rw-r--r--src/mongo/db/repl/noop_writer.cpp2
-rw-r--r--src/mongo/db/repl/oplog.cpp2
-rw-r--r--src/mongo/db/repl/sync_source_feedback.cpp15
-rw-r--r--src/mongo/db/s/balancer/balancer.cpp2
-rw-r--r--src/mongo/db/stats/snapshots.cpp2
-rw-r--r--src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp7
-rw-r--r--src/mongo/db/storage/mmap_v1/file_allocator.cpp5
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp9
-rw-r--r--src/mongo/db/ttl.cpp6
-rw-r--r--src/mongo/executor/network_interface_asio.cpp3
-rw-r--r--src/mongo/s/catalog/replset_dist_lock_manager.cpp2
-rw-r--r--src/mongo/s/query/cluster_cursor_cleanup_job.cpp3
-rw-r--r--src/mongo/s/server.cpp2
-rw-r--r--src/mongo/s/sharding_uptime_reporter.cpp2
-rw-r--r--src/mongo/scripting/deadline_monitor.h3
-rw-r--r--src/mongo/scripting/mozjs/proxyscope.cpp10
-rw-r--r--src/mongo/util/background.cpp9
-rw-r--r--src/mongo/util/background_thread_clock_source.cpp4
-rw-r--r--src/mongo/util/concurrency/SConscript10
-rw-r--r--src/mongo/util/concurrency/task.cpp85
-rw-r--r--src/mongo/util/concurrency/task.h84
-rw-r--r--src/mongo/util/net/listen.cpp6
-rw-r--r--src/mongo/util/signal_handlers.cpp6
29 files changed, 100 insertions, 199 deletions
diff --git a/src/mongo/db/auth/user_cache_invalidator_job.cpp b/src/mongo/db/auth/user_cache_invalidator_job.cpp
index 707fcb59e17..56a6bd29e86 100644
--- a/src/mongo/db/auth/user_cache_invalidator_job.cpp
+++ b/src/mongo/db/auth/user_cache_invalidator_job.cpp
@@ -45,6 +45,7 @@
#include "mongo/s/grid.h"
#include "mongo/stdx/mutex.h"
#include "mongo/util/background.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
@@ -146,6 +147,7 @@ void UserCacheInvalidator::run() {
lastInvalidationTime + Seconds(userCacheInvalidationIntervalSecs.load());
Date_t now = Date_t::now();
while (now < sleepUntil) {
+ IdleThreadBlock markIdle;
invalidationIntervalChangedCondition.wait_until(lock, sleepUntil.toSystemTimePoint());
sleepUntil = lastInvalidationTime + Seconds(userCacheInvalidationIntervalSecs.load());
now = Date_t::now();
diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp
index a662ac9dfbe..6fd80a3365b 100644
--- a/src/mongo/db/clientcursor.cpp
+++ b/src/mongo/db/clientcursor.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/server_parameters.h"
#include "mongo/util/background.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
namespace mongo {
@@ -279,6 +280,7 @@ public:
cursorStatsTimedOut.increment(
CursorManager::timeoutCursorsGlobal(&opCtx, t.millisReset()));
}
+ IdleThreadBlock markIdle;
sleepsecs(clientCursorMonitorFrequencySecs.load());
}
}
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index e6ae63880e3..686d2de5b76 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -124,7 +124,7 @@
#include "mongo/transport/transport_layer_legacy.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/cmdline_utils/censor_cmdline.h"
-#include "mongo/util/concurrency/task.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/exception_filter_win32.h"
#include "mongo/util/exit.h"
@@ -735,6 +735,8 @@ ExitCode _initAndListen(int listenPort) {
log() << "starting clean exit via failpoint";
exitCleanly(EXIT_CLEAN);
}
+
+ IdleThreadBlock markIdle;
return waitForShutdown();
}
diff --git a/src/mongo/db/ftdc/controller.cpp b/src/mongo/db/ftdc/controller.cpp
index bf3e80437be..a82b242e079 100644
--- a/src/mongo/db/ftdc/controller.cpp
+++ b/src/mongo/db/ftdc/controller.cpp
@@ -40,6 +40,7 @@
#include "mongo/stdx/memory.h"
#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
@@ -177,6 +178,7 @@ void FTDCController::doLoop() {
// Wait for the next run or signal to shutdown
{
stdx::unique_lock<stdx::mutex> lock(_mutex);
+ IdleThreadBlock markIdle;
// We ignore spurious wakeups by just doing an iteration of the loop
auto status = _condvar.wait_until(lock, next_time.toSystemTimePoint());
diff --git a/src/mongo/db/range_deleter.cpp b/src/mongo/db/range_deleter.cpp
index f26ceec85c8..cfd983bc686 100644
--- a/src/mongo/db/range_deleter.cpp
+++ b/src/mongo/db/range_deleter.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/stdx/memory.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
@@ -425,8 +426,11 @@ void RangeDeleter::doWork() {
{
stdx::unique_lock<stdx::mutex> sl(_queueMutex);
while (_taskQueue.empty()) {
- _taskQueueNotEmptyCV.wait_for(
- sl, Milliseconds(kNotEmptyTimeoutMillis).toSystemDuration());
+ {
+ IdleThreadBlock markIdle;
+ _taskQueueNotEmptyCV.wait_for(
+ sl, Milliseconds(kNotEmptyTimeoutMillis).toSystemDuration());
+ }
if (stopRequested()) {
log() << "stopping range deleter worker" << endl;
diff --git a/src/mongo/db/repl/noop_writer.cpp b/src/mongo/db/repl/noop_writer.cpp
index 926db4aff07..5e2abd17dea 100644
--- a/src/mongo/db/repl/noop_writer.cpp
+++ b/src/mongo/db/repl/noop_writer.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/server_parameters.h"
#include "mongo/stdx/functional.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -82,6 +83,7 @@ private:
OperationContext& opCtx = *opCtxPtr;
{
stdx::unique_lock<stdx::mutex> lk(_mutex);
+ IdleThreadBlock markIdle;
_cv.wait_for(lk, waitTime.toSystemDuration(), [&] { return _inShutdown; });
if (_inShutdown)
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 18a1eaa953e..2b319583ccd 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -88,6 +88,7 @@
#include "mongo/platform/random.h"
#include "mongo/scripting/engine.h"
#include "mongo/stdx/memory.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/elapsed_tracker.h"
#include "mongo/util/fail_point_service.h"
#include "mongo/util/file.h"
@@ -1213,6 +1214,7 @@ void SnapshotThread::run() {
break;
}
+ IdleThreadBlock markIdle;
newTimestampNotifier.wait(lock);
}
}
diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp
index b8c41b1e1fd..5f8826d68c0 100644
--- a/src/mongo/db/repl/sync_source_feedback.cpp
+++ b/src/mongo/db/repl/sync_source_feedback.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/repl/reporter.h"
#include "mongo/executor/task_executor.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/log.h"
#include "mongo/util/net/hostandport.h"
#include "mongo/util/scopeguard.h"
@@ -161,13 +162,17 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor, BackgroundSync* b
// this class.
stdx::unique_lock<stdx::mutex> lock(_mtx);
while (!_positionChanged && !_shutdownSignaled) {
- if (_cond.wait_for(lock, keepAliveInterval.toSystemDuration()) ==
- stdx::cv_status::timeout) {
- MemberState state = ReplicationCoordinator::get(opCtx.get())->getMemberState();
- if (!(state.primary() || state.startup())) {
- break;
+ {
+ IdleThreadBlock markIdle;
+ if (_cond.wait_for(lock, keepAliveInterval.toSystemDuration()) !=
+ stdx::cv_status::timeout) {
+ continue;
}
}
+ MemberState state = ReplicationCoordinator::get(opCtx.get())->getMemberState();
+ if (!(state.primary() || state.startup())) {
+ break;
+ }
}
if (_shutdownSignaled) {
diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp
index b85f08b7189..838142fe6f2 100644
--- a/src/mongo/db/s/balancer/balancer.cpp
+++ b/src/mongo/db/s/balancer/balancer.cpp
@@ -52,6 +52,7 @@
#include "mongo/s/grid.h"
#include "mongo/s/shard_util.h"
#include "mongo/stdx/memory.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/timer.h"
@@ -451,6 +452,7 @@ void Balancer::_endRound(OperationContext* opCtx, Seconds waitTimeout) {
_condVar.notify_all();
}
+ IdleThreadBlock markIdle;
_sleepFor(opCtx, waitTimeout);
}
diff --git a/src/mongo/db/stats/snapshots.cpp b/src/mongo/db/stats/snapshots.cpp
index 8e62134e86e..8f36cfa3cb7 100644
--- a/src/mongo/db/stats/snapshots.cpp
+++ b/src/mongo/db/stats/snapshots.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/client.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/service_context.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -113,6 +114,7 @@ void StatsSnapshotThread::run() {
log() << "ERROR in SnapshotThread: " << redact(e.what()) << endl;
}
+ IdleThreadBlock markIdle;
sleepsecs(4);
}
}
diff --git a/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp b/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp
index 8e7ef2a0cb5..6a4bfcc8580 100644
--- a/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp
+++ b/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/storage/mmap_v1/dur_stats.h"
#include "mongo/stdx/functional.h"
#include "mongo/stdx/thread.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/log.h"
#include "mongo/util/timer.h"
@@ -213,7 +214,11 @@ void JournalWriter::_journalWriterThread() {
try {
while (true) {
- Buffer* const buffer = _journalQueue.blockingPop();
+ Buffer* const buffer = [&] {
+ IdleThreadBlock markIdle;
+ return _journalQueue.blockingPop();
+ }();
+
BufferGuard bufferGuard(buffer, &_readyQueue);
if (buffer->_isShutdown) {
diff --git a/src/mongo/db/storage/mmap_v1/file_allocator.cpp b/src/mongo/db/storage/mmap_v1/file_allocator.cpp
index be1378bd093..86f96d0c9de 100644
--- a/src/mongo/db/storage/mmap_v1/file_allocator.cpp
+++ b/src/mongo/db/storage/mmap_v1/file_allocator.cpp
@@ -54,6 +54,7 @@
#include "mongo/platform/posix_fadvise.h"
#include "mongo/stdx/functional.h"
#include "mongo/stdx/thread.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/fail_point_service.h"
@@ -374,8 +375,10 @@ void FileAllocator::run(FileAllocator* fa) {
while (1) {
{
stdx::unique_lock<stdx::mutex> lk(fa->_pendingMutex);
- if (fa->_pending.size() == 0)
+ if (fa->_pending.size() == 0) {
+ IdleThreadBlock markIdle;
fa->_pendingUpdated.wait(lk);
+ }
}
while (1) {
string name;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index bd3c83f555f..67fad96475d 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -69,6 +69,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/background.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/ticketholder.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -113,6 +114,7 @@ public:
ms = 100;
}
+ IdleThreadBlock markIdle;
sleepmillis(ms);
}
LOG(1) << "stopping " << name() << " thread";
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index b10b3cfdc92..f6b698467ee 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -56,6 +56,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
@@ -180,6 +181,7 @@ void WiredTigerRecordStore::OplogStones::awaitHasExcessStonesOrDead() {
// Wait until kill() is called or there are too many oplog stones.
stdx::unique_lock<stdx::mutex> lock(_oplogReclaimMutex);
while (!_isDead && !hasExcessStones()) {
+ IdleThreadBlock markIdle;
_oplogReclaimCv.wait(lock);
}
}
@@ -1708,8 +1710,11 @@ void WiredTigerRecordStore::_oplogJournalThreadLoop(WiredTigerSessionCache* sess
Client::initThread("WTOplogJournalThread");
while (true) {
stdx::unique_lock<stdx::mutex> lk(_uncommittedRecordIdsMutex);
- _opsWaitingForJournalCV.wait(
- lk, [&] { return _shuttingDown || !_opsWaitingForJournal.empty(); });
+ {
+ IdleThreadBlock markIdle;
+ _opsWaitingForJournalCV.wait(
+ lk, [&] { return _shuttingDown || !_opsWaitingForJournal.empty(); });
+ }
while (!_shuttingDown && MONGO_FAIL_POINT(WTPausePrimaryOplogDurabilityLoop)) {
lk.unlock();
diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp
index f9c1d9459d6..e51785cf8c4 100644
--- a/src/mongo/db/ttl.cpp
+++ b/src/mongo/db/ttl.cpp
@@ -56,6 +56,7 @@
#include "mongo/db/server_parameters.h"
#include "mongo/db/ttl_collection_cache.h"
#include "mongo/util/background.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -87,7 +88,10 @@ public:
AuthorizationSession::get(cc())->grantInternalAuthorization();
while (!globalInShutdownDeprecated()) {
- sleepsecs(ttlMonitorSleepSecs.load());
+ {
+ IdleThreadBlock markIdle;
+ sleepsecs(ttlMonitorSleepSecs.load());
+ }
LOG(3) << "thread awake";
diff --git a/src/mongo/executor/network_interface_asio.cpp b/src/mongo/executor/network_interface_asio.cpp
index 4a38893d1c2..3fbca90cd2c 100644
--- a/src/mongo/executor/network_interface_asio.cpp
+++ b/src/mongo/executor/network_interface_asio.cpp
@@ -46,6 +46,7 @@
#include "mongo/rpc/metadata/metadata_hook.h"
#include "mongo/stdx/chrono.h"
#include "mongo/stdx/memory.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/log.h"
#include "mongo/util/net/sock.h"
@@ -185,6 +186,7 @@ void NetworkInterfaceASIO::waitForWork() {
stdx::unique_lock<stdx::mutex> lk(_executorMutex);
// TODO: This can be restructured with a lambda.
while (!_isExecutorRunnable) {
+ IdleThreadBlock markIdle;
_isExecutorRunnableCondition.wait(lk);
}
_isExecutorRunnable = false;
@@ -198,6 +200,7 @@ void NetworkInterfaceASIO::waitForWorkUntil(Date_t when) {
if (waitTime <= Milliseconds(0)) {
break;
}
+ IdleThreadBlock markIdle;
_isExecutorRunnableCondition.wait_for(lk, waitTime.toSystemDuration());
}
_isExecutorRunnable = false;
diff --git a/src/mongo/s/catalog/replset_dist_lock_manager.cpp b/src/mongo/s/catalog/replset_dist_lock_manager.cpp
index 98fbcf94ceb..dfd3ab32e12 100644
--- a/src/mongo/s/catalog/replset_dist_lock_manager.cpp
+++ b/src/mongo/s/catalog/replset_dist_lock_manager.cpp
@@ -43,6 +43,7 @@
#include "mongo/s/grid.h"
#include "mongo/stdx/chrono.h"
#include "mongo/stdx/memory.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/fail_point_service.h"
#include "mongo/util/log.h"
@@ -176,6 +177,7 @@ void ReplSetDistLockManager::doTask() {
}
stdx::unique_lock<stdx::mutex> lk(_mutex);
+ IdleThreadBlock markIdle;
_shutDownCV.wait_for(lk, _pingInterval.toSystemDuration(), [this] { return _isShutDown; });
}
}
diff --git a/src/mongo/s/query/cluster_cursor_cleanup_job.cpp b/src/mongo/s/query/cluster_cursor_cleanup_job.cpp
index 45fe1c44825..441c4bbf235 100644
--- a/src/mongo/s/query/cluster_cursor_cleanup_job.cpp
+++ b/src/mongo/s/query/cluster_cursor_cleanup_job.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/server_parameters.h"
#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_cursor_manager.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/time_support.h"
@@ -70,6 +71,8 @@ void ClusterCursorCleanupJob::run() {
manager->killMortalCursorsInactiveSince(Date_t::now() -
Milliseconds(cursorTimeoutMillis.load()));
manager->incrementCursorsTimedOut(manager->reapZombieCursors());
+
+ IdleThreadBlock markIdle;
sleepsecs(clientCursorMonitorFrequencySecs.load());
}
}
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 7255c8810de..427574a1741 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -89,6 +89,7 @@
#include "mongo/transport/transport_layer_legacy.h"
#include "mongo/util/admin_access.h"
#include "mongo/util/cmdline_utils/censor_cmdline.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/exception_filter_win32.h"
#include "mongo/util/exit.h"
@@ -356,6 +357,7 @@ static ExitCode runMongosServer() {
#endif
// Block until shutdown.
+ IdleThreadBlock markIdle;
return waitForShutdown();
}
diff --git a/src/mongo/s/sharding_uptime_reporter.cpp b/src/mongo/s/sharding_uptime_reporter.cpp
index 8d507dbfce6..8ee3bd59325 100644
--- a/src/mongo/s/sharding_uptime_reporter.cpp
+++ b/src/mongo/s/sharding_uptime_reporter.cpp
@@ -38,6 +38,7 @@
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/catalog/type_mongos.h"
#include "mongo/s/grid.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
@@ -112,6 +113,7 @@ void ShardingUptimeReporter::startPeriodicThread() {
}
}
+ IdleThreadBlock markIdle;
sleepFor(kUptimeReportInterval);
}
});
diff --git a/src/mongo/scripting/deadline_monitor.h b/src/mongo/scripting/deadline_monitor.h
index a39b78971c5..3f50abe5348 100644
--- a/src/mongo/scripting/deadline_monitor.h
+++ b/src/mongo/scripting/deadline_monitor.h
@@ -35,6 +35,7 @@
#include "mongo/stdx/condition_variable.h"
#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/time_support.h"
@@ -132,6 +133,7 @@ private:
* _Task::kill() is invoked.
*/
void deadlineMonitorThread() {
+ setThreadName("DeadlineMonitor");
stdx::unique_lock<stdx::mutex> lk(_deadlineMutex);
Date_t lastInterruptCycle = Date_t::now();
while (!_inShutdown) {
@@ -149,6 +151,7 @@ private:
// wait for a task to be added or a deadline to expire
if (_nearestDeadlineWallclock > now) {
+ IdleThreadBlock markIdle;
if (_nearestDeadlineWallclock == Date_t::max()) {
if ((interruptInterval.count() > 0) &&
(_nearestDeadlineWallclock - now > interruptInterval)) {
diff --git a/src/mongo/scripting/mozjs/proxyscope.cpp b/src/mongo/scripting/mozjs/proxyscope.cpp
index 2b9db2045c2..58084e88ad1 100644
--- a/src/mongo/scripting/mozjs/proxyscope.cpp
+++ b/src/mongo/scripting/mozjs/proxyscope.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/service_context.h"
#include "mongo/platform/decimal128.h"
#include "mongo/scripting/mozjs/implscope.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/destructor_guard.h"
#include "mongo/util/quick_exit.h"
@@ -340,9 +341,12 @@ void MozJSProxyScope::implThread(void* arg) {
while (true) {
stdx::unique_lock<stdx::mutex> lk(proxy->_mutex);
- proxy->_condvar.wait(lk, [proxy] {
- return proxy->_state == State::ProxyRequest || proxy->_state == State::Shutdown;
- });
+ {
+ IdleThreadBlock markIdle;
+ proxy->_condvar.wait(lk, [proxy] {
+ return proxy->_state == State::ProxyRequest || proxy->_state == State::Shutdown;
+ });
+ }
if (proxy->_state == State::Shutdown)
break;
diff --git a/src/mongo/util/background.cpp b/src/mongo/util/background.cpp
index 6e3d27501c6..4c2085caf67 100644
--- a/src/mongo/util/background.cpp
+++ b/src/mongo/util/background.cpp
@@ -38,6 +38,7 @@
#include "mongo/stdx/functional.h"
#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/concurrency/spin_lock.h"
#include "mongo/util/concurrency/thread_name.h"
@@ -309,8 +310,12 @@ void PeriodicTaskRunner::run() {
stdx::unique_lock<stdx::mutex> lock(_mutex);
while (!_shutdownRequested) {
- if (stdx::cv_status::timeout == _cond.wait_for(lock, waitTime.toSystemDuration()))
- _runTasks();
+ {
+ IdleThreadBlock markIdle;
+ if (stdx::cv_status::timeout != _cond.wait_for(lock, waitTime.toSystemDuration()))
+ continue;
+ }
+ _runTasks();
}
}
diff --git a/src/mongo/util/background_thread_clock_source.cpp b/src/mongo/util/background_thread_clock_source.cpp
index b533d52b8ea..4ace0a99ad8 100644
--- a/src/mongo/util/background_thread_clock_source.cpp
+++ b/src/mongo/util/background_thread_clock_source.cpp
@@ -37,6 +37,7 @@
#include "mongo/stdx/memory.h"
#include "mongo/stdx/thread.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
@@ -104,6 +105,7 @@ void BackgroundThreadClockSource::_startTimerThread() {
// Start the background thread that repeatedly sleeps for the specified duration of milliseconds
// and wakes up to store the current time.
_timer = stdx::thread([&]() {
+ setThreadName("BackgroundThreadClockSource");
stdx::unique_lock<stdx::mutex> lock(_mutex);
_started = true;
_condition.notify_one();
@@ -114,10 +116,12 @@ void BackgroundThreadClockSource::_startTimerThread() {
} else {
// Stop running if nothing has read the time since we last updated the time.
_current.store(0);
+ IdleThreadBlock markIdle;
_condition.wait(lock, [this] { return _inShutdown || _current.load() != 0; });
}
const auto sleepUntil = Date_t::fromMillisSinceEpoch(_current.load()) + _granularity;
+ IdleThreadBlock markIdle;
_clockSource->waitForConditionUntil(
_condition, lock, sleepUntil, [this] { return _inShutdown; });
}
diff --git a/src/mongo/util/concurrency/SConscript b/src/mongo/util/concurrency/SConscript
index df0ecc038c2..5038bdca4bb 100644
--- a/src/mongo/util/concurrency/SConscript
+++ b/src/mongo/util/concurrency/SConscript
@@ -57,13 +57,3 @@ env.CppUnitTest(
'$BUILD_DIR/third_party/shim_boost',
],
)
-
-env.Library(
- target='task',
- source=[
- 'task.cpp',
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/util/background_job',
- ],
-)
diff --git a/src/mongo/util/concurrency/task.cpp b/src/mongo/util/concurrency/task.cpp
deleted file mode 100644
index ab9c7b537bd..00000000000
--- a/src/mongo/util/concurrency/task.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-// @file task.cpp
-
-/* Copyright 2009 10gen Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/util/concurrency/task.h"
-
-#include "mongo/util/assert_util.h"
-#include "mongo/util/exit.h"
-#include "mongo/util/time_support.h"
-
-namespace mongo {
-
-namespace task {
-
-Task::Task() : BackgroundJob(true /* deleteSelf */) {
- n = 0;
- repeat = 0;
-}
-
-void Task::halt() {
- repeat = 0;
-}
-
-void Task::setUp() {}
-
-void Task::run() {
- verify(n == 0);
-
- setUp();
-
- while (1) {
- n++;
- try {
- doWork();
- } catch (...) {
- }
- sleepmillis(repeat);
- if (globalInShutdownDeprecated())
- break;
- if (repeat == 0)
- break;
- }
-}
-
-void Task::begin() {
- go();
-}
-
-void fork(Task* t) {
- t->begin();
-}
-
-void repeat(Task* t, unsigned millis) {
- t->repeat = millis;
- t->begin();
-}
-}
-}
diff --git a/src/mongo/util/concurrency/task.h b/src/mongo/util/concurrency/task.h
deleted file mode 100644
index 123434db3ac..00000000000
--- a/src/mongo/util/concurrency/task.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// @file task.h
-
-/**
-* Copyright (C) 2008 10gen Inc.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License, version 3,
-* as published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful,b
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* As a special exception, the copyright holders give permission to link the
-* code of portions of this program with the OpenSSL library under certain
-* conditions as described in each individual source file and distribute
-* linked combinations including the program with the OpenSSL library. You
-* must comply with the GNU Affero General Public License in all respects
-* for all of the code used other than as permitted herein. If you modify
-* file(s) with this exception, you may extend this exception to your
-* version of the file(s), but you are not obligated to do so. If you do not
-* wish to do so, delete this exception statement from your version. If you
-* delete this exception statement from all source files in the program,
-* then also delete it in the license file.
-*/
-
-#pragma once
-
-#include "mongo/util/background.h"
-
-namespace mongo {
-
-namespace task {
-
-/** abstraction around threads. simpler than BackgroundJob which is used behind the scenes.
- allocate the Task dynamically. when the thread terminates, the Task object will delete itself.
-*/
-class Task : private BackgroundJob {
-protected:
- virtual void setUp(); // Override to perform any do-once work for the task.
- virtual void doWork() = 0; // implement the task here.
- virtual std::string name() const = 0; // name the thread
-public:
- Task();
-
- /** for a repeating task, stop after current invocation ends. can be called by other threads
- as long as the Task is still in scope.
- */
- void halt();
-
-private:
- unsigned n, repeat;
- friend void fork(Task* t);
- friend void repeat(Task* t, unsigned millis);
- virtual void run();
- // virtual void ending() { }
- void begin();
-};
-
-/** run once */
-void fork(Task* t);
-
-/** run doWork() over and over, with a pause between runs of millis */
-void repeat(Task* t, unsigned millis);
-
-/*** Example ***
-inline void sample() {
- class Sample : public Task {
- public:
- int result;
- virtual void doWork() { result = 1234; }
- Sample() : result(0) { }
- };
- std::shared_ptr<Sample> q( new Sample() );
- fork(q);
- cout << q->result << std::endl; // could print 1234 or 0.
-}
-*/
-}
-}
diff --git a/src/mongo/util/net/listen.cpp b/src/mongo/util/net/listen.cpp
index 6a3d0446faa..da0e47629f4 100644
--- a/src/mongo/util/net/listen.cpp
+++ b/src/mongo/util/net/listen.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/stdx/memory.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/net/asio_message_port.h"
@@ -294,7 +295,10 @@ void Listener::initAndListen() {
maxSelectTime.tv_sec = 0;
maxSelectTime.tv_usec = 250000;
- const int ret = select(maxfd + 1, fds, nullptr, nullptr, &maxSelectTime);
+ const int ret = [&] {
+ IdleThreadBlock markIdle;
+ return select(maxfd + 1, fds, nullptr, nullptr, &maxSelectTime);
+ }();
if (ret == 0) {
continue;
diff --git a/src/mongo/util/signal_handlers.cpp b/src/mongo/util/signal_handlers.cpp
index 229fd38ae6d..220631c9732 100644
--- a/src/mongo/util/signal_handlers.cpp
+++ b/src/mongo/util/signal_handlers.cpp
@@ -44,6 +44,7 @@
#include "mongo/platform/process_id.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
#include "mongo/util/quick_exit.h"
@@ -169,7 +170,10 @@ void signalProcessingThread(LogFileStatus rotate) {
while (true) {
int actualSignal = 0;
- int status = sigwait(&asyncSignals, &actualSignal);
+ int status = [&] {
+ IdleThreadBlock markIdle;
+ return sigwait(&asyncSignals, &actualSignal);
+ }();
fassert(16781, status == 0);
switch (actualSignal) {
case SIGUSR1: