2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2015-10-27 13:03:43 +01:00
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
#include "util/threadpool_imp.h"
|
2016-05-13 03:34:04 +02:00
|
|
|
#include <algorithm>
|
2016-08-26 19:41:35 +02:00
|
|
|
#include <atomic>
|
2016-05-13 03:34:04 +02:00
|
|
|
|
|
|
|
#ifndef OS_WIN
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2015-10-27 13:03:43 +01:00
|
|
|
#ifdef OS_LINUX
|
2016-05-13 03:34:04 +02:00
|
|
|
# include <sys/syscall.h>
|
2015-10-27 13:03:43 +01:00
|
|
|
#endif
|
|
|
|
|
2016-06-06 02:23:38 +02:00
|
|
|
#ifdef OS_FREEBSD
|
|
|
|
# include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-10-27 13:03:43 +01:00
|
|
|
namespace rocksdb {
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::PthreadCall(const char* label, int result) {
|
2015-10-27 13:03:43 +01:00
|
|
|
if (result != 0) {
|
|
|
|
fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 03:34:04 +02:00
|
|
|
namespace {
|
|
|
|
#ifdef ROCKSDB_STD_THREADPOOL
|
|
|
|
|
|
|
|
struct Lock {
|
|
|
|
std::unique_lock<std::mutex> ul_;
|
2016-08-26 19:41:35 +02:00
|
|
|
explicit Lock(const std::mutex& m) : ul_(m, std::defer_lock) {}
|
2016-05-13 03:34:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
using Condition = std::condition_variable;
|
|
|
|
|
2016-05-27 03:38:05 +02:00
|
|
|
inline int ThreadPoolMutexLock(Lock& mutex) {
|
2016-05-13 03:34:04 +02:00
|
|
|
mutex.ul_.lock();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ConditionWait(Condition& condition, Lock& lock) {
|
|
|
|
condition.wait(lock.ul_);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ConditionSignalAll(Condition& condition) {
|
|
|
|
condition.notify_all();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ConditionSignal(Condition& condition) {
|
|
|
|
condition.notify_one();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int MutexUnlock(Lock& mutex) {
|
|
|
|
mutex.ul_.unlock();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void ThreadJoin(std::thread& thread) {
|
|
|
|
thread.join();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ThreadDetach(std::thread& thread) {
|
|
|
|
thread.detach();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
using Lock = pthread_mutex_t&;
|
|
|
|
using Condition = pthread_cond_t&;
|
|
|
|
|
2016-05-27 03:38:05 +02:00
|
|
|
inline int ThreadPoolMutexLock(Lock mutex) {
|
2016-05-13 03:34:04 +02:00
|
|
|
return pthread_mutex_lock(&mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ConditionWait(Condition condition, Lock lock) {
|
|
|
|
return pthread_cond_wait(&condition, &lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ConditionSignalAll(Condition condition) {
|
|
|
|
return pthread_cond_broadcast(&condition);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ConditionSignal(Condition condition) {
|
|
|
|
return pthread_cond_signal(&condition);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int MutexUnlock(Lock mutex) {
|
|
|
|
return pthread_mutex_unlock(&mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void ThreadJoin(pthread_t& thread) {
|
|
|
|
pthread_join(thread, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int ThreadDetach(pthread_t& thread) {
|
|
|
|
return pthread_detach(thread);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
ThreadPoolImpl::ThreadPoolImpl()
|
2015-10-27 13:03:43 +01:00
|
|
|
: total_threads_limit_(1),
|
|
|
|
bgthreads_(0),
|
|
|
|
queue_(),
|
2016-05-13 03:34:04 +02:00
|
|
|
queue_len_(),
|
2015-10-27 13:03:43 +01:00
|
|
|
exit_all_threads_(false),
|
|
|
|
low_io_priority_(false),
|
|
|
|
env_(nullptr) {
|
2016-05-13 03:34:04 +02:00
|
|
|
#ifndef ROCKSDB_STD_THREADPOOL
|
2015-10-27 13:03:43 +01:00
|
|
|
PthreadCall("mutex_init", pthread_mutex_init(&mu_, nullptr));
|
|
|
|
PthreadCall("cvar_init", pthread_cond_init(&bgsignal_, nullptr));
|
2016-05-13 03:34:04 +02:00
|
|
|
#endif
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
ThreadPoolImpl::~ThreadPoolImpl() { assert(bgthreads_.size() == 0U); }
|
2016-05-13 03:34:04 +02:00
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::JoinAllThreads() {
|
2016-05-13 03:34:04 +02:00
|
|
|
Lock lock(mu_);
|
2016-05-27 03:38:05 +02:00
|
|
|
PthreadCall("lock", ThreadPoolMutexLock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
assert(!exit_all_threads_);
|
|
|
|
exit_all_threads_ = true;
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("signalall", ConditionSignalAll(bgsignal_));
|
|
|
|
PthreadCall("unlock", MutexUnlock(lock));
|
|
|
|
|
|
|
|
for (auto& th : bgthreads_) {
|
|
|
|
ThreadJoin(th);
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
2016-05-13 03:34:04 +02:00
|
|
|
|
2015-10-27 13:03:43 +01:00
|
|
|
bgthreads_.clear();
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::LowerIOPriority() {
|
2015-10-27 13:03:43 +01:00
|
|
|
#ifdef OS_LINUX
|
|
|
|
PthreadCall("lock", pthread_mutex_lock(&mu_));
|
|
|
|
low_io_priority_ = true;
|
|
|
|
PthreadCall("unlock", pthread_mutex_unlock(&mu_));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::BGThread(size_t thread_id) {
|
2015-10-27 13:03:43 +01:00
|
|
|
bool low_io_priority = false;
|
|
|
|
while (true) {
|
2016-05-13 03:34:04 +02:00
|
|
|
// Wait until there is an item that is ready to run
|
|
|
|
Lock uniqueLock(mu_);
|
2016-05-27 03:38:05 +02:00
|
|
|
PthreadCall("lock", ThreadPoolMutexLock(uniqueLock));
|
2015-10-27 13:03:43 +01:00
|
|
|
// Stop waiting if the thread needs to do work or needs to terminate.
|
|
|
|
while (!exit_all_threads_ && !IsLastExcessiveThread(thread_id) &&
|
|
|
|
(queue_.empty() || IsExcessiveThread(thread_id))) {
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("wait", ConditionWait(bgsignal_, uniqueLock));
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
2016-05-13 03:34:04 +02:00
|
|
|
|
2015-10-27 13:03:43 +01:00
|
|
|
if (exit_all_threads_) { // mechanism to let BG threads exit safely
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(uniqueLock));
|
2015-10-27 13:03:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-05-13 03:34:04 +02:00
|
|
|
|
2015-10-27 13:03:43 +01:00
|
|
|
if (IsLastExcessiveThread(thread_id)) {
|
|
|
|
// Current thread is the last generated one and is excessive.
|
|
|
|
// We always terminate excessive thread in the reverse order of
|
|
|
|
// generation time.
|
2016-05-13 03:34:04 +02:00
|
|
|
auto& terminating_thread = bgthreads_.back();
|
|
|
|
PthreadCall("detach", ThreadDetach(terminating_thread));
|
2015-10-27 13:03:43 +01:00
|
|
|
bgthreads_.pop_back();
|
|
|
|
if (HasExcessiveThread()) {
|
|
|
|
// There is still at least more excessive thread to terminate.
|
|
|
|
WakeUpAllThreads();
|
|
|
|
}
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(uniqueLock));
|
2015-10-27 13:03:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-05-13 03:34:04 +02:00
|
|
|
|
2015-10-27 13:03:43 +01:00
|
|
|
void (*function)(void*) = queue_.front().function;
|
|
|
|
void* arg = queue_.front().arg;
|
|
|
|
queue_.pop_front();
|
|
|
|
queue_len_.store(static_cast<unsigned int>(queue_.size()),
|
|
|
|
std::memory_order_relaxed);
|
|
|
|
|
|
|
|
bool decrease_io_priority = (low_io_priority != low_io_priority_);
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(uniqueLock));
|
2015-10-27 13:03:43 +01:00
|
|
|
|
|
|
|
#ifdef OS_LINUX
|
|
|
|
if (decrease_io_priority) {
|
|
|
|
#define IOPRIO_CLASS_SHIFT (13)
|
|
|
|
#define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
|
|
|
|
// Put schedule into IOPRIO_CLASS_IDLE class (lowest)
|
|
|
|
// These system calls only have an effect when used in conjunction
|
|
|
|
// with an I/O scheduler that supports I/O priorities. As at
|
|
|
|
// kernel 2.6.17 the only such scheduler is the Completely
|
|
|
|
// Fair Queuing (CFQ) I/O scheduler.
|
|
|
|
// To change scheduler:
|
|
|
|
// echo cfq > /sys/block/<device_name>/queue/schedule
|
|
|
|
// Tunables to consider:
|
|
|
|
// /sys/block/<device_name>/queue/slice_idle
|
|
|
|
// /sys/block/<device_name>/queue/slice_sync
|
|
|
|
syscall(SYS_ioprio_set, 1, // IOPRIO_WHO_PROCESS
|
|
|
|
0, // current thread
|
|
|
|
IOPRIO_PRIO_VALUE(3, 0));
|
|
|
|
low_io_priority = true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void)decrease_io_priority; // avoid 'unused variable' error
|
|
|
|
#endif
|
|
|
|
(*function)(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper struct for passing arguments when creating threads.
|
|
|
|
struct BGThreadMetadata {
|
2016-08-26 19:41:35 +02:00
|
|
|
ThreadPoolImpl* thread_pool_;
|
2015-10-27 13:03:43 +01:00
|
|
|
size_t thread_id_; // Thread count in the thread.
|
2016-08-26 19:41:35 +02:00
|
|
|
BGThreadMetadata(ThreadPoolImpl* thread_pool, size_t thread_id)
|
2015-10-27 13:03:43 +01:00
|
|
|
: thread_pool_(thread_pool), thread_id_(thread_id) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void* BGThreadWrapper(void* arg) {
|
|
|
|
BGThreadMetadata* meta = reinterpret_cast<BGThreadMetadata*>(arg);
|
|
|
|
size_t thread_id = meta->thread_id_;
|
2016-08-26 19:41:35 +02:00
|
|
|
ThreadPoolImpl* tp = meta->thread_pool_;
|
2015-10-27 13:03:43 +01:00
|
|
|
#if ROCKSDB_USING_THREAD_STATUS
|
|
|
|
// for thread-status
|
|
|
|
ThreadStatusUtil::RegisterThread(
|
|
|
|
tp->GetHostEnv(), (tp->GetThreadPriority() == Env::Priority::HIGH
|
|
|
|
? ThreadStatus::HIGH_PRIORITY
|
|
|
|
: ThreadStatus::LOW_PRIORITY));
|
|
|
|
#endif
|
|
|
|
delete meta;
|
|
|
|
tp->BGThread(thread_id);
|
|
|
|
#if ROCKSDB_USING_THREAD_STATUS
|
|
|
|
ThreadStatusUtil::UnregisterThread();
|
|
|
|
#endif
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::WakeUpAllThreads() {
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("signalall", ConditionSignalAll(bgsignal_));
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::SetBackgroundThreadsInternal(int num, bool allow_reduce) {
|
2016-05-13 03:34:04 +02:00
|
|
|
Lock lock(mu_);
|
2016-05-27 03:38:05 +02:00
|
|
|
PthreadCall("lock", ThreadPoolMutexLock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
if (exit_all_threads_) {
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (num > total_threads_limit_ ||
|
|
|
|
(num < total_threads_limit_ && allow_reduce)) {
|
|
|
|
total_threads_limit_ = std::max(1, num);
|
|
|
|
WakeUpAllThreads();
|
|
|
|
StartBGThreads();
|
|
|
|
}
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::IncBackgroundThreadsIfNeeded(int num) {
|
2015-10-27 13:03:43 +01:00
|
|
|
SetBackgroundThreadsInternal(num, false);
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::SetBackgroundThreads(int num) {
|
2015-10-27 13:03:43 +01:00
|
|
|
SetBackgroundThreadsInternal(num, true);
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::StartBGThreads() {
|
2015-10-27 13:03:43 +01:00
|
|
|
// Start background thread if necessary
|
|
|
|
while ((int)bgthreads_.size() < total_threads_limit_) {
|
2016-05-13 03:34:04 +02:00
|
|
|
#ifdef ROCKSDB_STD_THREADPOOL
|
|
|
|
std::thread p_t(&BGThreadWrapper,
|
|
|
|
new BGThreadMetadata(this, bgthreads_.size()));
|
|
|
|
bgthreads_.push_back(std::move(p_t));
|
|
|
|
#else
|
2015-10-27 13:03:43 +01:00
|
|
|
pthread_t t;
|
|
|
|
PthreadCall("create thread",
|
|
|
|
pthread_create(&t, nullptr, &BGThreadWrapper,
|
|
|
|
new BGThreadMetadata(this, bgthreads_.size())));
|
|
|
|
// Set the thread name to aid debugging
|
|
|
|
#if defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ)
|
|
|
|
#if __GLIBC_PREREQ(2, 12)
|
|
|
|
char name_buf[16];
|
|
|
|
snprintf(name_buf, sizeof name_buf, "rocksdb:bg%" ROCKSDB_PRIszt,
|
|
|
|
bgthreads_.size());
|
|
|
|
name_buf[sizeof name_buf - 1] = '\0';
|
|
|
|
pthread_setname_np(t, name_buf);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
bgthreads_.push_back(t);
|
2016-05-13 03:34:04 +02:00
|
|
|
#endif
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
void ThreadPoolImpl::Schedule(void (*function)(void* arg1), void* arg,
|
|
|
|
void* tag, void (*unschedFunction)(void* arg)) {
|
2016-05-13 03:34:04 +02:00
|
|
|
Lock lock(mu_);
|
2016-05-27 03:38:05 +02:00
|
|
|
PthreadCall("lock", ThreadPoolMutexLock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
|
|
|
|
if (exit_all_threads_) {
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StartBGThreads();
|
|
|
|
|
|
|
|
// Add to priority queue
|
|
|
|
queue_.push_back(BGItem());
|
|
|
|
queue_.back().function = function;
|
|
|
|
queue_.back().arg = arg;
|
|
|
|
queue_.back().tag = tag;
|
Running manual compactions in parallel with other automatic or manual compactions in restricted cases
Summary:
This diff provides a framework for doing manual
compactions in parallel with other compactions. We now have a deque of manual compactions. We also pass manual compactions as an argument from RunManualCompactions down to
BackgroundCompactions, so that RunManualCompactions can be reentrant.
Parallelism is controlled by the two routines
ConflictingManualCompaction to allow/disallow new parallel/manual
compactions based on already existing ManualCompactions. In this diff, by default manual compactions still have to run exclusive of other compactions. However, by setting the compaction option, exclusive_manual_compaction to false, it is possible to run other compactions in parallel with a manual compaction. However, we are still restricted to one manual compaction per column family at a time. All of these restrictions will be relaxed in future diffs.
I will be adding more tests later.
Test Plan: Rocksdb regression + new tests + valgrind
Reviewers: igor, anthony, IslamAbdelRahman, kradhakrishnan, yhchiang, sdong
Reviewed By: sdong
Subscribers: yoshinorim, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D47973
2015-12-14 20:20:34 +01:00
|
|
|
queue_.back().unschedFunction = unschedFunction;
|
2015-10-27 13:03:43 +01:00
|
|
|
queue_len_.store(static_cast<unsigned int>(queue_.size()),
|
|
|
|
std::memory_order_relaxed);
|
|
|
|
|
|
|
|
if (!HasExcessiveThread()) {
|
|
|
|
// Wake up at least one waiting thread.
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("signal", ConditionSignal(bgsignal_));
|
2015-10-27 13:03:43 +01:00
|
|
|
} else {
|
|
|
|
// Need to wake up all threads to make sure the one woken
|
|
|
|
// up is not the one to terminate.
|
|
|
|
WakeUpAllThreads();
|
|
|
|
}
|
|
|
|
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
int ThreadPoolImpl::UnSchedule(void* arg) {
|
2015-10-27 13:03:43 +01:00
|
|
|
int count = 0;
|
2016-05-13 03:34:04 +02:00
|
|
|
|
|
|
|
Lock lock(mu_);
|
2016-05-27 03:38:05 +02:00
|
|
|
PthreadCall("lock", ThreadPoolMutexLock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
|
|
|
|
// Remove from priority queue
|
|
|
|
BGQueue::iterator it = queue_.begin();
|
|
|
|
while (it != queue_.end()) {
|
|
|
|
if (arg == (*it).tag) {
|
Running manual compactions in parallel with other automatic or manual compactions in restricted cases
Summary:
This diff provides a framework for doing manual
compactions in parallel with other compactions. We now have a deque of manual compactions. We also pass manual compactions as an argument from RunManualCompactions down to
BackgroundCompactions, so that RunManualCompactions can be reentrant.
Parallelism is controlled by the two routines
ConflictingManualCompaction to allow/disallow new parallel/manual
compactions based on already existing ManualCompactions. In this diff, by default manual compactions still have to run exclusive of other compactions. However, by setting the compaction option, exclusive_manual_compaction to false, it is possible to run other compactions in parallel with a manual compaction. However, we are still restricted to one manual compaction per column family at a time. All of these restrictions will be relaxed in future diffs.
I will be adding more tests later.
Test Plan: Rocksdb regression + new tests + valgrind
Reviewers: igor, anthony, IslamAbdelRahman, kradhakrishnan, yhchiang, sdong
Reviewed By: sdong
Subscribers: yoshinorim, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D47973
2015-12-14 20:20:34 +01:00
|
|
|
void (*unschedFunction)(void*) = (*it).unschedFunction;
|
|
|
|
void* arg1 = (*it).arg;
|
|
|
|
if (unschedFunction != nullptr) {
|
|
|
|
(*unschedFunction)(arg1);
|
|
|
|
}
|
2015-10-27 13:03:43 +01:00
|
|
|
it = queue_.erase(it);
|
|
|
|
count++;
|
|
|
|
} else {
|
2016-05-13 03:34:04 +02:00
|
|
|
++it;
|
2015-10-27 13:03:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
queue_len_.store(static_cast<unsigned int>(queue_.size()),
|
|
|
|
std::memory_order_relaxed);
|
2016-05-13 03:34:04 +02:00
|
|
|
PthreadCall("unlock", MutexUnlock(lock));
|
2015-10-27 13:03:43 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:41:35 +02:00
|
|
|
ThreadPool* NewThreadPool(int num_threads) {
|
|
|
|
ThreadPoolImpl* thread_pool = new ThreadPoolImpl();
|
|
|
|
thread_pool->SetBackgroundThreads(num_threads);
|
|
|
|
return thread_pool;
|
|
|
|
}
|
|
|
|
|
2015-10-27 13:03:43 +01:00
|
|
|
} // namespace rocksdb
|