Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion port/port_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class CondVar {
Mutex* mu_;
};

using Thread = std::thread;
using Thread = std::jthread;

static inline void AsmVolatilePause() {
#if defined(__i386__) || defined(__x86_64__)
Expand Down
2 changes: 1 addition & 1 deletion port/win/port_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class CondVar {
};

#ifdef _POSIX_THREADS
using Thread = std::thread;
using Thread = std::jthread;
#else
// Wrapper around the platform efficient
// or otherwise preferrable implementation
Expand Down
18 changes: 7 additions & 11 deletions port/win/win_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#if defined(OS_WIN)
// Most Mingw builds support std::thread only when using posix threads.
// In that case, some of these functions will be unavailable.
// Note that we're using either WindowsThread or std::thread, depending on
// Note that we're using either WindowsThread or std::jthread, depending on
// which one is available.
#ifndef _POSIX_THREADS

Expand Down Expand Up @@ -65,16 +65,12 @@ void WindowsThread::Init(std::function<void()>&& func) {
WindowsThread::WindowsThread() : data_(nullptr), th_id_(0) {}

WindowsThread::~WindowsThread() {
// Must be joined or detached
// before destruction.
// This is the same as std::thread
if (data_) {
if (joinable()) {
assert(false);
std::terminate();
}
data_.reset();
// Is joined and detached on destruction.
// This is the same as std::jthread.
if (joinable()) {
join();
}
data_.reset();
}

WindowsThread::WindowsThread(WindowsThread&& o) noexcept : WindowsThread() {
Expand Down Expand Up @@ -102,7 +98,7 @@ WindowsThread::native_handle_type WindowsThread::native_handle() const {
}

unsigned WindowsThread::hardware_concurrency() {
return std::thread::hardware_concurrency();
return std::jthread::hardware_concurrency();
}

void WindowsThread::join() {
Expand Down
6 changes: 3 additions & 3 deletions port/win/win_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
namespace ROCKSDB_NAMESPACE {
namespace port {

// This class is a replacement for std::thread
// 2 reasons we do not like std::thread:
// This class is a replacement for std::jthread
// 2 reasons we do not like std::jthread:
// -- is that it dynamically allocates its internals that are automatically
// freed when the thread terminates and not on the destruction of the
// freed when the thread terminates and not necessarily on the destruction of the
// object. This makes it difficult to control the source of memory
// allocation
// - This implements Pimpl so we can easily replace the guts of the
Expand Down