diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-01-13 16:16:21 -0500 |
---|---|---|
committer | Eddie Louie <eddie.louie@mongodb.com> | 2017-05-02 15:44:34 -0400 |
commit | edf81ac9673164b487534afc7047c789238be0f0 (patch) | |
tree | d80f7bc91f617027b69713a349cb4f4659f0aa63 | |
parent | b36663f746b5ed671c9fd73388ad0f9f2478c0f6 (diff) | |
download | mongo-edf81ac9673164b487534afc7047c789238be0f0.tar.gz |
SERVER-27727 Hide idle threads in hang analyzer (extras)
(cherry picked from commit 63d1f4c049587e7923a1154fc31f29bc190316df)
28 files changed, 105 insertions, 117 deletions
diff --git a/src/mongo/db/auth/user_cache_invalidator_job.cpp b/src/mongo/db/auth/user_cache_invalidator_job.cpp index f941e1d87b1..479a2b7f7c8 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 4cc2dd643a4..858875a7cb8 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 { @@ -271,6 +272,7 @@ public: cursorStatsTimedOut.increment( CursorManager::timeoutCursorsGlobal(&txn, t.millisReset())); } + IdleThreadBlock markIdle; sleepsecs(clientCursorMonitorFrequencySecs); } } diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 05cb617eda9..24ff0dcc942 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -122,7 +122,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" @@ -831,6 +831,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 6f574293e21..ba00172e328 100644 --- a/src/mongo/db/range_deleter.cpp +++ b/src/mongo/db/range_deleter.cpp @@ -39,6 +39,7 @@ #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/service_context.h" #include "mongo/db/write_concern_options.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" @@ -423,8 +424,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 1a98d8fdfe7..9329f4048fb 100644 --- a/src/mongo/db/repl/noop_writer.cpp +++ b/src/mongo/db/repl/noop_writer.cpp @@ -38,6 +38,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 { @@ -81,6 +82,7 @@ private: OperationContext& txn = *txnPtr; { 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 99567642a17..f318a27682d 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -87,6 +87,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" @@ -1192,6 +1193,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 9ce0a24c2d7..0d2e794dc9f 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" @@ -181,13 +182,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(txn.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(txn.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 6096c0e42ba..aaa5bfdbe50 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" @@ -467,6 +468,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 c1088f4d12f..c9255e10e62 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 4eb0b4ea16b..8a5c5241f6f 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" @@ -211,7 +212,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 4423a963e72..451139d014a 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 eea04cbab64..92ff3d5aba9 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 6ce589d087a..be026dc88ca 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); } } @@ -1698,8 +1700,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 444afb3686c..591b43aeaee 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 (!inShutdown()) { - sleepsecs(ttlMonitorSleepSecs); + { + IdleThreadBlock markIdle; + sleepsecs(ttlMonitorSleepSecs); + } LOG(3) << "thread awake"; diff --git a/src/mongo/executor/network_interface_asio.cpp b/src/mongo/executor/network_interface_asio.cpp index 8acfa3885ed..e64665b6b81 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 eff613f66b6..10a8169a222 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 068d06ac98a..a1e11c9d523 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" @@ -71,6 +72,8 @@ void ClusterCursorCleanupJob::run() { manager->killMortalCursorsInactiveSince(Date_t::now() - Milliseconds(cursorTimeoutMillis.load())); manager->incrementCursorsTimedOut(manager->reapZombieCursors()); + + IdleThreadBlock markIdle; sleepsecs(clientCursorMonitorFrequencySecs); } } diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index a6e21f8b5f3..52795659900 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -84,6 +84,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" @@ -328,6 +329,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 ba5f3690822..b65b32ca728 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" @@ -109,6 +110,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 ded15319ae1..3e9dddda072 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 81b4666760b..21371973b3f 100644 --- a/src/mongo/util/background_thread_clock_source.cpp +++ b/src/mongo/util/background_thread_clock_source.cpp @@ -35,6 +35,7 @@ #include "mongo/stdx/memory.h" #include "mongo/stdx/thread.h" +#include "mongo/util/concurrency/idle_thread_block.h" #include "mongo/util/time_support.h" namespace mongo { @@ -68,12 +69,17 @@ 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); while (!_shutdownTimer) { - if (_condition.wait_for(lock, _granularity.toSystemDuration()) == - stdx::cv_status::timeout) { - _updateCurrent(); + { + IdleThreadBlock markIdle; + if (_condition.wait_for(lock, _granularity.toSystemDuration()) != + stdx::cv_status::timeout) { + continue; + } } + _updateCurrent(); } }); } diff --git a/src/mongo/util/concurrency/SConscript b/src/mongo/util/concurrency/SConscript index f8dc8f06d77..78a29709ea1 100644 --- a/src/mongo/util/concurrency/SConscript +++ b/src/mongo/util/concurrency/SConscript @@ -57,16 +57,6 @@ env.CppUnitTest( ) env.Library( - target='task', - source=[ - 'task.cpp', - ], - LIBDEPS=[ - '$BUILD_DIR/mongo/util/background_job', - ], -) - -env.Library( target='rwlock', source=[ 'rwlockimpl.cpp', 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 7f76fbf8fac..d30008cd62e 100644 --- a/src/mongo/util/net/listen.cpp +++ b/src/mongo/util/net/listen.cpp @@ -40,6 +40,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" @@ -291,7 +292,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 27571b0f775..a92a204a520 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() { 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: |