Skip to content

Commit

Permalink
Make this compile
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerkaraszewski committed Oct 3, 2024
1 parent 63c6f7b commit 71d7941
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion BedrockServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void BedrockServer::sync()
SINFO("Starting " << workerThreads << " worker threads.");
list<ResourceMonitorThread> workerThreadList;
for (int threadId = 0; threadId < workerThreads; threadId++) {
workerThreadList.emplace_back(&BedrockServer::worker, this, threadId);
workerThreadList.emplace_back([this, threadId](){this->worker(threadId);});
}

// Now we jump into our main command processing loop.
Expand Down
2 changes: 2 additions & 0 deletions libstuff/ResourceMonitorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "libstuff/libstuff.h"
#include "format"

thread_local uint64_t ResourceMonitorThread::startTime;
thread_local double ResourceMonitorThread::cpuStartTime;

void ResourceMonitorThread::before(){
startTime = STimeNow();
Expand Down
20 changes: 10 additions & 10 deletions libstuff/ResourceMonitorThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ using namespace std;

class ResourceMonitorThread: public thread
{
ResourceMonitorThread(const ResourceMonitorThread&) = delete;
ResourceMonitorThread(ResourceMonitorThread&&) = delete;
public:
template<typename F, typename... Args,
typename = _Require<__not_<is_same<__remove_cvref_t<F>, thread>>>>
explicit
ResourceMonitorThread(F&& f, Args&&... args): thread(&wrapper<F, Args...>, forward<F>(f), forward<Args>(args)...){};

template<typename F, typename... Args>
ResourceMonitorThread(F&& f, Args&&... args):
thread(ResourceMonitorThread::wrapper<F&&, Args&&...>, forward<F&&>(f), forward<Args&&>(args)...){};
private:
static thread_local uint64_t startTime;
static thread_local double cpuStartTime;

static void before();
static void after();

template<typename F, typename... Args>
inline static function<void(F&& f, Args&&... args)> wrapper = [](F&& f, Args&&... args){
static void wrapper(F&& f, Args&&... args) {
before();
std::invoke(f, std::forward<Args>(args)...);
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
after();
};
};

}
};
2 changes: 1 addition & 1 deletion sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ void SQLiteNode::_onMESSAGE(SQLitePeer* peer, const SData& message) {
SDEBUG("Spawning concurrent replicate thread (blocks until DB handle available): " << threadID);
try {
uint64_t threadAttemptStartTimestamp = STimeNow();
ResourceMonitorThread(&SQLiteNode::_replicate, this, peer, message, _dbPool->getIndex(false), threadAttemptStartTimestamp).detach();
ResourceMonitorThread([=, this](){this->_replicate(peer, message, _dbPool->getIndex(false), threadAttemptStartTimestamp);}).detach();
} catch (const system_error& e) {
// If the server is strugling and falling behind on replication, we might have too many threads
// causing a resource exhaustion. If that happens, all the transactions that are already threaded
Expand Down

0 comments on commit 71d7941

Please sign in to comment.