Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
38 changes: 35 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,*,-clang-diagnostic-error,-llvmlibc-*,-llvm-include-order,-misc-include-cleaner,-fuchsia-trailing-return,-modernize-use-trailing-return-type'
WarningsAsErrors: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,*,-clang-diagnostic-error,-llvmlibc-*,-llvm-include-order,-misc-include-cleaner,-fuchsia-trailing-return,-modernize-use-trailing-return-type'
Checks: >
clang-diagnostic-*,
clang-analyzer-*,
cppcoreguidelines-*,
modernize-*,
*,
-clang-diagnostic-error,
-llvmlibc-*,
-llvm-include-order,
-misc-include-cleaner,
-fuchsia-trailing-return,
-modernize-use-trailing-return-type,
-altera-unroll-loops,
-misc-use-anonymous-namespace,
-portability-template-virtual-member-function,
-altera-id-dependent-backward-branch,
-boost-use-ranges
WarningsAsErrors: >
clang-diagnostic-*,
clang-analyzer-*,
cppcoreguidelines-*,
modernize-*,
*,
-clang-diagnostic-error,
-llvmlibc-*,
-llvm-include-order,
-misc-include-cleaner,
-fuchsia-trailing-return,
-modernize-use-trailing-return-type,
-altera-unroll-loops,
-misc-use-anonymous-namespace,
-portability-template-virtual-member-function,
-altera-id-dependent-backward-branch,
-boost-use-ranges
HeaderFilterRegex: '^(?!.*/build/).*'
FormatStyle: google
CheckOptions:
Expand Down Expand Up @@ -30,4 +62,4 @@ CheckOptions:
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
value: 'NULL'
7 changes: 3 additions & 4 deletions .github/workflows/multi-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
Expand All @@ -33,6 +30,8 @@ jobs:
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: cl
- os: windows-latest
c_compiler: gcc
- os: windows-latest
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ else()
endif()

# Libraries list
add_library(cxx_setup INTERFACE multithreading/utilities)
add_library(cxx_setup INTERFACE multithreading/utilities
multithreading/benchmark/src/SpeedMeasurement.cpp)

# General compiler options
if (MSVC)
Expand Down
18 changes: 16 additions & 2 deletions executables/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
add_executable(print_hello print_hello.cpp)
target_link_libraries(print_hello PRIVATE utilities cxx_setup)
add_executable(unbounded_queue_benchmark
unbounded_queue_benchmark.cpp
benchmarks/src/UnboundedQueueBenchmark.cpp
benchmarks/src/mcmp/UnboundedQueueMCMPBenchmark.cpp)
add_executable(bounded_queue_benchmark
bounded_queue_benchmark.cpp
benchmarks/src/BoundedQueueBenchmark.cpp
benchmarks/src/mcmp/BoundedQueueMCMPBenchmark.cpp)
add_executable(linked_list_benchmark
linked_list_benchmark.cpp
benchmarks/src/LinkedListBenchmark.cpp
benchmarks/src/mcmp/LinkedListMCMPBenchmark.cpp)

target_link_libraries(unbounded_queue_benchmark PRIVATE utilities structures benchmark cxx_setup)
target_link_libraries(bounded_queue_benchmark PRIVATE utilities structures benchmark cxx_setup)
target_link_libraries(linked_list_benchmark PRIVATE utilities structures benchmark cxx_setup)
23 changes: 23 additions & 0 deletions executables/benchmarks/include/BoundedQueueBenchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <multithreading/structures/include/bounded_queue/BoundedQueue.h>

#include <memory>


namespace executables::benchmarks {

class BoundedQueueBenchmark {
protected:
std::shared_ptr<
multithreading::structures::bounded_queue::BoundedQueue<int>
> benchmark_queue;
public:
explicit BoundedQueueBenchmark(
const std::shared_ptr<
multithreading::structures::bounded_queue::BoundedQueue<int>> &queue
);
};


} // namespace executables::benchmarks
17 changes: 17 additions & 0 deletions executables/benchmarks/include/LinkedListBenchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <memory>
#include <multithreading/structures/include/linked_list/LinkedList.h>


namespace executables::benchmarks {

class LinkedListBenchmark {
protected:
const std::shared_ptr<multithreading::structures::linked_list::LinkedList<int>> &benchmark_list;

explicit LinkedListBenchmark(
const std::shared_ptr<multithreading::structures::linked_list::LinkedList<int>> &list
);
};
} // namespace executables::benchmarks
13 changes: 13 additions & 0 deletions executables/benchmarks/include/ThreadConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <cstdint>
#include <thread>


namespace executables::benchmarks {

constexpr size_t THREAD_SIZE = 100;
constexpr size_t DEQUEUE_TIMEOUT_MS = 1000;
constexpr size_t QUEUE_SIZE = 10000;
const size_t THREADS_COUNT = std::thread::hardware_concurrency();
} // namespace executables::benchmarks
23 changes: 23 additions & 0 deletions executables/benchmarks/include/UnboundedQueueBenchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <multithreading/structures/include/unbounded_queue/UnboundedQueue.h>

#include <memory>


namespace executables::benchmarks {

class UnboundedQueueBenchmark {
protected:
std::shared_ptr<
multithreading::structures::unbounded_queue::UnboundedQueue<int>
> benchmark_queue;

explicit UnboundedQueueBenchmark(
const std::shared_ptr<
multithreading::structures::unbounded_queue::UnboundedQueue<int>> &queue
);
};


} // namespace executables::benchmarks
22 changes: 22 additions & 0 deletions executables/benchmarks/include/mcmp/BoundedQueueMCMPBenchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <multithreading/benchmark/include/mcmp/ProducerConsumerBenchmark.h>

#include "../BoundedQueueBenchmark.h"

namespace executables::benchmarks::mcmp {

class BoundedQueueMCMPBenchmark final
: public multithreading::benchmark::mcmp::ProducerConsumerBenchmark
, BoundedQueueBenchmark
{
public:
explicit BoundedQueueMCMPBenchmark(
const std::shared_ptr<
multithreading::structures::bounded_queue::BoundedQueue<int>> &queue
);

void producer_routine(size_t threadSize) override;
void consumer_routine(size_t threadSize) override;
};
} // namespace executables::benchmarks::mcmp
26 changes: 26 additions & 0 deletions executables/benchmarks/include/mcmp/LinkedListMCMPBenchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <multithreading/structures/include/linked_list/FGLockLinkedList.h>
#include <multithreading/benchmark/include/mcmp/ProducerConsumerBenchmark.h>
#include <memory>

#include "../LinkedListBenchmark.h"


namespace executables::benchmarks::mcmp {

class LinkedListMCMPBenchmark final
: public multithreading::benchmark::mcmp::ProducerConsumerBenchmark
, LinkedListBenchmark
{
public:
explicit LinkedListMCMPBenchmark(
const std::shared_ptr<
multithreading::structures::linked_list::LinkedList<int>
> &list
);

void producer_routine(size_t threadSize) override;
void consumer_routine(size_t threadSize) override;
};
} // namespace executables::benchmarks::mcmp
22 changes: 22 additions & 0 deletions executables/benchmarks/include/mcmp/UnboundedQueueMCMPBenchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <multithreading/benchmark/include/mcmp/ProducerConsumerBenchmark.h>

#include "../UnboundedQueueBenchmark.h"

namespace executables::benchmarks::mcmp {

class UnboundedQueueMCMPBenchmark final
: public multithreading::benchmark::mcmp::ProducerConsumerBenchmark
, UnboundedQueueBenchmark
{
public:
explicit UnboundedQueueMCMPBenchmark(
const std::shared_ptr<
multithreading::structures::unbounded_queue::UnboundedQueue<int>> &queue
);

void producer_routine(size_t threadSize) override;
void consumer_routine(size_t threadSize) override;
};
} // namespace executables::benchmarks::mcmp
11 changes: 11 additions & 0 deletions executables/benchmarks/src/BoundedQueueBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "../include/BoundedQueueBenchmark.h"

namespace executables::benchmarks {

BoundedQueueBenchmark::BoundedQueueBenchmark(
const std::shared_ptr<
multithreading::structures::bounded_queue::BoundedQueue<int>> &queue
)
: benchmark_queue(queue)
{}
} // namespace executables::benchmarks
10 changes: 10 additions & 0 deletions executables/benchmarks/src/LinkedListBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "../include/LinkedListBenchmark.h"

namespace executables::benchmarks {

LinkedListBenchmark::LinkedListBenchmark(
const std::shared_ptr<multithreading::structures::linked_list::LinkedList<int>> &list
)
: benchmark_list(list)
{}
} // namespace executables::benchmarks
11 changes: 11 additions & 0 deletions executables/benchmarks/src/UnboundedQueueBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "../include/UnboundedQueueBenchmark.h"

namespace executables::benchmarks {

UnboundedQueueBenchmark::UnboundedQueueBenchmark(
const std::shared_ptr<
multithreading::structures::unbounded_queue::UnboundedQueue<int>> &queue
)
: benchmark_queue(queue)
{}
} // namespace executables::benchmarks
34 changes: 34 additions & 0 deletions executables/benchmarks/src/mcmp/BoundedQueueMCMPBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "../../include/mcmp/BoundedQueueMCMPBenchmark.h"

namespace executables::benchmarks::mcmp {

constexpr size_t MAX_CONSUME_RETRIES = 100;

BoundedQueueMCMPBenchmark::BoundedQueueMCMPBenchmark(
const std::shared_ptr<
multithreading::structures::bounded_queue::BoundedQueue<int>> &queue
)
: BoundedQueueBenchmark(queue)
{}

void BoundedQueueMCMPBenchmark::producer_routine(const size_t threadSize) {
for (size_t j = 0; j < threadSize; j++) {
while (!benchmark_queue->try_enqueue(static_cast<int>(j))) {
// Keep trying until we have space
}
}
}

void BoundedQueueMCMPBenchmark::consumer_routine(const size_t threadSize) {
for (size_t j = 0; j < threadSize; j++) {
size_t retries = 0;
while (!benchmark_queue->try_dequeue().has_value()) {
if (++retries > MAX_CONSUME_RETRIES) {
std::this_thread::yield();
retries = 0;
}
}
}
}

} // namespace executables::benchmarks::mcmp
35 changes: 35 additions & 0 deletions executables/benchmarks/src/mcmp/LinkedListMCMPBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "../../include/mcmp/LinkedListMCMPBenchmark.h"

#include <multithreading/structures/include/linked_list/FGLockLinkedList.h>
#include <thread>
#include <cstdint>


namespace executables::benchmarks::mcmp {

constexpr size_t MAX_CONSUME_RETRIES = 100;

LinkedListMCMPBenchmark::LinkedListMCMPBenchmark(
const std::shared_ptr<multithreading::structures::linked_list::LinkedList<int>> &list
)
: LinkedListBenchmark(list)
{}

void LinkedListMCMPBenchmark::producer_routine(const size_t threadSize) {
for (size_t j = 0; j < threadSize; j++) {
benchmark_list->push_front(static_cast<int>(j));
}
}

void LinkedListMCMPBenchmark::consumer_routine(const size_t threadSize) {
for (size_t j = 0; j < threadSize; j++) {
size_t retries = 0;
while (!benchmark_list->pop_front().has_value()) {
if (++retries > MAX_CONSUME_RETRIES) {
std::this_thread::yield();
retries = 0;
}
}
}
}
} // namespace executables::benchmarks::mcmp
26 changes: 26 additions & 0 deletions executables/benchmarks/src/mcmp/UnboundedQueueMCMPBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "../../include/mcmp/UnboundedQueueMCMPBenchmark.h"

namespace executables::benchmarks::mcmp {

UnboundedQueueMCMPBenchmark::UnboundedQueueMCMPBenchmark(
const std::shared_ptr<
multithreading::structures::unbounded_queue::UnboundedQueue<int>> &queue
)
: UnboundedQueueBenchmark(queue)
{}

void UnboundedQueueMCMPBenchmark::producer_routine(const size_t threadSize) {
for (size_t j = 0; j < threadSize; j++) {
benchmark_queue->enqueue(static_cast<int>(j));
}
}

void UnboundedQueueMCMPBenchmark::consumer_routine(const size_t threadSize) {
for (size_t j = 0; j < threadSize; j++) {
while (!benchmark_queue->try_dequeue().has_value()) {
// Keep trying until we get a value
}
}
}

} // namespace executables::benchmarks::mcmp
Loading