Browse Source
create a custom barrier structure that allows synchronization of each iteration of the meassurement loop
master
create a custom barrier structure that allows synchronization of each iteration of the meassurement loop
master
Constantin Fürst
1 year ago
4 changed files with 65 additions and 27 deletions
-
45benchmarks/barrier.hpp
-
23benchmarks/benchmark.hpp
-
18benchmarks/task-data.hpp
-
6benchmarks/task-description.json
@ -0,0 +1,45 @@ |
|||
#pragma once
|
|||
|
|||
#include <mutex>
|
|||
#include <atomic>
|
|||
#include <semaphore.h>
|
|||
|
|||
class barrier { |
|||
private: |
|||
std::mutex mutex_; |
|||
uint32_t waiting_count_; |
|||
const uint32_t barrier_size_; |
|||
sem_t semaphore_; |
|||
|
|||
barrier(const barrier& other) = delete; |
|||
|
|||
public: |
|||
barrier(const uint32_t size); |
|||
~barrier(); |
|||
|
|||
void wait(); |
|||
void signal(); |
|||
}; |
|||
|
|||
inline barrier::~barrier() { |
|||
sem_destroy(&semaphore_); |
|||
} |
|||
|
|||
inline barrier::barrier(const uint32_t size) : barrier_size_(size) { |
|||
sem_init(&semaphore_, 0, 0); |
|||
waiting_count_ = 0; |
|||
} |
|||
|
|||
inline void barrier::wait() { |
|||
mutex_.lock(); |
|||
|
|||
if (++waiting_count_ >= barrier_size_) { |
|||
for (uint32_t i = 1; i < waiting_count_; i++) sem_post(&semaphore_); |
|||
mutex_.unlock(); |
|||
} |
|||
else { |
|||
mutex_.unlock(); |
|||
sem_wait(&semaphore_); |
|||
} |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue