Skip to content

Commit

Permalink
Patched from pull 353
Browse files Browse the repository at this point in the history
  • Loading branch information
wallentx committed Apr 18, 2023
1 parent 83b041f commit 7d19104
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/prover_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <unistd.h>
#endif
#include <stdio.h>

#include <atomic>
#include <algorithm> // std::min
#include <fstream>
#include <future>
Expand Down Expand Up @@ -58,8 +58,10 @@ class ContextQueue {
public:
ContextQueue() {}

ContextQueue(uint32_t context_count, uint32_t thread_count, bool no_cpu_affinity, const uint32_t maxCompressionLevel) {
init(context_count, thread_count, no_cpu_affinity, maxCompressionLevel);
ContextQueue(uint32_t context_count, uint32_t thread_count, bool no_cpu_affinity, const uint32_t maxCompressionLevel) : offset(0) {
//init(context_count, thread_count, no_cpu_affinity, maxCompressionLevel);
this->thread_count = thread_count;
this->no_cpu_affinity = no_cpu_affinity;
}

void init(uint32_t context_count, uint32_t thread_count, bool no_cpu_affinity, const uint32_t maxCompressionLevel) {
Expand Down Expand Up @@ -88,21 +90,16 @@ class ContextQueue {
}

void push(GreenReaperContext* gr) {
std::unique_lock<std::mutex> lock(mutex);
queue.push(gr);
lock.unlock();
condition.notify_one();
grDestroyContext(gr);
}

GreenReaperContext* pop() {
std::unique_lock<std::mutex> lock(mutex);
while (queue.empty()) {
condition.wait(lock);
}
dequeue_lock.lock();
GreenReaperContext* gr = queue.front();
queue.pop();
dequeue_lock.unlock();
GreenReaperConfig cfg = {};
cfg.threadCount = thread_count;
cfg.disableCpuAffinity = no_cpu_affinity;
cfg.cpuOffset = (offset.load() % 100) * thread_count;
auto gr = grCreateContext(&cfg);
++offset;
return gr;
}

Expand All @@ -111,6 +108,9 @@ class ContextQueue {
std::mutex mutex;
std::condition_variable condition;
std::mutex dequeue_lock;
uint32_t thread_count;
bool no_cpu_affinity;
std::atomic<uint64_t> offset;
};

ContextQueue decompresser_context_queue(4, 10, false, 7);
Expand Down

0 comments on commit 7d19104

Please sign in to comment.