From 0f6a90098bbb4993d027ba976c48eb5c9ea8653c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 1 Dec 2020 09:57:49 +0100 Subject: [PATCH] Remove experimental unused stuff. --- Common/Thread/Channel.h | 55 -------------------------------------- Common/Thread/Event.h | 1 + Common/Thread/Promise.h | 6 ----- Common/Thread/ThreadUtil.h | 31 --------------------- 4 files changed, 1 insertion(+), 92 deletions(-) diff --git a/Common/Thread/Channel.h b/Common/Thread/Channel.h index bea46045d4..ae5327094b 100644 --- a/Common/Thread/Channel.h +++ b/Common/Thread/Channel.h @@ -63,58 +63,3 @@ struct Mailbox { private: std::atomic refcount_; }; - - -// POD so can be moved around freely. -// TODO: I can't quite get this to work with all the moves, the refcount blows up. I'll just use mailboxes directly. - -/* -template -class Rx { -public: - Rx() : mbx_(nullptr) {} - Rx(Mailbox *mbx) : mbx_(mbx) { mbx_->AddRef(); } - Rx(Rx &&rx) { mbx_ = rx.mbx_; } - Rx& operator=(Rx &&rx) { mbx_ = rx.mbx_; return *this; } - ~Rx() { - mbx_->Release(); - } - bool Poll(T **data) { - return mbx_->Poll(data); - } - T *Wait() { - return mbx_->Wait(); - } - -private: - Mailbox *mbx_; -}; - -// POD so can be moved around freely. -template -class Tx { -public: - Tx() : mbx_(nullptr) {} - Tx(Mailbox *mbx) : mbx_(mbx) { mbx_->AddRef(); } - Tx(Tx &&rx) { mbx_ = rx.mbx_; } - Tx& operator=(Tx &&rx) { mbx_ = rx.mbx_; return *this; } - - ~Tx() { - mbx_->Release(); - } - bool Send(T *t) { - return mbx_->Send(t); - } - -private: - Mailbox *mbx_; -}; - -template -std::pair, Tx> CreateChannel() { - Mailbox *mbx = new Mailbox(); - auto retval = std::make_pair(Rx(mbx), Tx(mbx)); - mbx->Release(); - return retval; -} -*/ diff --git a/Common/Thread/Event.h b/Common/Thread/Event.h index ae608a6eb6..3baf465373 100644 --- a/Common/Thread/Event.h +++ b/Common/Thread/Event.h @@ -1,6 +1,7 @@ #pragma once #include "Common/Thread/ThreadManager.h" + #include #include diff --git a/Common/Thread/Promise.h b/Common/Thread/Promise.h index c8f2c2ea23..c4f34a3996 100644 --- a/Common/Thread/Promise.h +++ b/Common/Thread/Promise.h @@ -44,12 +44,6 @@ public: mailbox->AddRef(); return promise; } - /* - Promise(Promise &&promise) noexcept { - data_ = promise.data_; - ready_ = promise.ready_; - rx_ = promise.rx_; - }*/ ~Promise() { if (rx_) { diff --git a/Common/Thread/ThreadUtil.h b/Common/Thread/ThreadUtil.h index 336ce9337b..d702ec566b 100644 --- a/Common/Thread/ThreadUtil.h +++ b/Common/Thread/ThreadUtil.h @@ -2,37 +2,6 @@ #include -// I plan to experiment with these to see if this approach can also work in C++. -// The major advantage compared to a normal mutex is that we use the type system -// to enforce that the resource is only accessed when the mutex is locked. - -template -class RustMutexProxy { -public: - RustMutexProxy(T *data, std::mutex &mutex) : data_(data), mutex_(mutex) {} - ~RustMutexProxy() { mutex_.unlock(); } - T &operator*() { return *data_; } - T *operator->() { return data_; } -private: - T *data_; - std::mutex &mutex_; -}; - -template -class RustMutex { -public: - RustMutex(T && t) : t_(t) {} - - RustMutexProxy lock() { - mutex_.lock(); - return RustMutexProxy(&t_, mutex_); - } - -private: - T t_; - std::mutex mutex_; -}; - // Note that name must be a global string that lives until the end of the process, // for AssertCurrentThreadName to work. void SetCurrentThreadName(const char *threadName);