thread: rename thread primitives from job namespace
This commit is contained in:
parent
6cd2bef17d
commit
36f4ba035c
@ -87,9 +87,9 @@ list (
|
||||
##-----------------------------------------------------------------------------
|
||||
if (LINUX)
|
||||
list (APPEND UTIL_FILES
|
||||
job/event_linux.cpp
|
||||
job/flag_linux.cpp
|
||||
job/semaphore_linux.cpp
|
||||
thread/event_linux.cpp
|
||||
thread/flag_linux.cpp
|
||||
thread/semaphore_linux.cpp
|
||||
)
|
||||
endif ()
|
||||
|
||||
@ -125,9 +125,9 @@ if (WINDOWS)
|
||||
exe_win32.cpp
|
||||
io_win32.cpp
|
||||
io_win32.hpp
|
||||
job/event_win32.cpp
|
||||
job/flag_win32.cpp
|
||||
job/semaphore_win32.cpp
|
||||
thread/event_win32.cpp
|
||||
thread/flag_win32.cpp
|
||||
thread/semaphore_win32.cpp
|
||||
library_win32.cpp
|
||||
library_win32.hpp
|
||||
time_win32.cpp
|
||||
@ -277,17 +277,8 @@ list (
|
||||
io.hpp
|
||||
iterator.hpp
|
||||
job/fwd.hpp
|
||||
job/event.hpp
|
||||
job/flag.hpp
|
||||
job/monitor.cpp
|
||||
job/monitor.hpp
|
||||
job/queue.cpp
|
||||
job/queue.hpp
|
||||
job/semaphore.hpp
|
||||
job/ticketlock.cpp
|
||||
job/ticketlock.hpp
|
||||
job/spinlock.cpp
|
||||
job/spinlock.hpp
|
||||
json/fwd.hpp
|
||||
json/except.cpp
|
||||
json/except.hpp
|
||||
@ -377,6 +368,15 @@ list (
|
||||
tap.hpp
|
||||
term.cpp
|
||||
term.hpp
|
||||
thread/event.hpp
|
||||
thread/flag.hpp
|
||||
thread/monitor.cpp
|
||||
thread/monitor.hpp
|
||||
thread/semaphore.hpp
|
||||
thread/ticketlock.cpp
|
||||
thread/ticketlock.hpp
|
||||
thread/spinlock.cpp
|
||||
thread/spinlock.hpp
|
||||
time.cpp
|
||||
time.hpp
|
||||
time/parse.hpp
|
||||
@ -500,13 +500,7 @@ if (TESTS)
|
||||
hton
|
||||
introspection
|
||||
iterator
|
||||
job/event
|
||||
job/flag
|
||||
job/monitor
|
||||
job/queue
|
||||
job/semaphore
|
||||
job/spinlock
|
||||
job/ticketlock
|
||||
json_types
|
||||
json2/event
|
||||
maths
|
||||
@ -532,6 +526,12 @@ if (TESTS)
|
||||
string
|
||||
stringid
|
||||
strongdef
|
||||
thread/event
|
||||
thread/flag
|
||||
thread/monitor
|
||||
thread/semaphore
|
||||
thread/spinlock
|
||||
thread/ticketlock
|
||||
time/8601
|
||||
traits
|
||||
tuple
|
||||
|
@ -19,10 +19,10 @@
|
||||
|
||||
#include "../pool.hpp"
|
||||
|
||||
#include "ticketlock.hpp"
|
||||
#include "semaphore.hpp"
|
||||
#include "flag.hpp"
|
||||
#include "monitor.hpp"
|
||||
#include "../thread/ticketlock.hpp"
|
||||
#include "../thread/semaphore.hpp"
|
||||
#include "../thread/flag.hpp"
|
||||
#include "../thread/monitor.hpp"
|
||||
|
||||
#include "../parallel/queue.hpp"
|
||||
|
||||
@ -185,8 +185,8 @@ namespace util::job {
|
||||
std::array<char,64> data;
|
||||
|
||||
std::function<void(task&)> function;
|
||||
semaphore references = 0;
|
||||
flag done;
|
||||
thread::semaphore references = 0;
|
||||
thread::flag done;
|
||||
};
|
||||
|
||||
private:
|
||||
@ -197,9 +197,9 @@ namespace util::job {
|
||||
std::atomic<int> m_running = 0;
|
||||
|
||||
struct {
|
||||
monitor<
|
||||
thread::monitor<
|
||||
std::deque<task*>,
|
||||
ticketlock
|
||||
thread::ticketlock
|
||||
> pending;
|
||||
|
||||
pool<task> store;
|
||||
@ -207,11 +207,11 @@ namespace util::job {
|
||||
std::vector<task*> notified;
|
||||
} m_tasks;
|
||||
|
||||
semaphore m_pending;
|
||||
thread::semaphore m_pending;
|
||||
|
||||
std::vector<std::thread> m_threads;
|
||||
|
||||
semaphore m_doomed;
|
||||
thread::semaphore m_doomed;
|
||||
std::thread m_reaper;
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "parallel/queue.hpp"
|
||||
#include "job/flag.hpp"
|
||||
#include "job/semaphore.hpp"
|
||||
#include "thread/flag.hpp"
|
||||
#include "thread/semaphore.hpp"
|
||||
#include "debug.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
@ -12,7 +12,7 @@ static constexpr uint32_t slots = 4;
|
||||
static constexpr int parallelism = 8;
|
||||
static constexpr int chunk_size = 1<<12;
|
||||
|
||||
util::job::flag start;
|
||||
util::thread::flag start;
|
||||
|
||||
using queue_t = util::parallel::queue<int,slots>;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "job/event.hpp"
|
||||
#include "thread/event.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <atomic>
|
||||
@ -17,7 +17,7 @@ main ()
|
||||
// the test isn't 100% deterministic (because we're attempting to create
|
||||
// specific timings by just waiting). but it's a decent first check.
|
||||
std::atomic<int> val = 0;
|
||||
util::job::event a;
|
||||
util::thread::event a;
|
||||
|
||||
std::thread t ([&] () {
|
||||
a.wait ();
|
@ -1,4 +1,4 @@
|
||||
#include "job/flag.hpp"
|
||||
#include "thread/flag.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <thread>
|
||||
@ -9,7 +9,7 @@ main ()
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
util::job::flag f;
|
||||
util::thread::flag f;
|
||||
std::atomic<int> value = 0;
|
||||
|
||||
std::thread t1 ([&] () {
|
||||
@ -45,7 +45,7 @@ main ()
|
||||
constexpr int parallelism = 16;
|
||||
|
||||
std::vector<
|
||||
std::array<util::job::flag,parallelism>
|
||||
std::array<util::thread::flag,parallelism>
|
||||
> flags (iterations);
|
||||
|
||||
const auto func = [&flags] (const int idx) {
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
|
||||
#include "tap.hpp"
|
||||
#include "job/monitor.hpp"
|
||||
#include "job/event.hpp"
|
||||
#include "job/semaphore.hpp"
|
||||
#include "thread/monitor.hpp"
|
||||
#include "thread/event.hpp"
|
||||
#include "thread/semaphore.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
@ -40,8 +40,8 @@ struct foo {
|
||||
}
|
||||
|
||||
std::atomic<int> value = 0;
|
||||
util::job::semaphore enter;
|
||||
util::job::semaphore leave;
|
||||
util::thread::semaphore enter;
|
||||
util::thread::semaphore leave;
|
||||
};
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ main ()
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
util::job::monitor<foo> obj;
|
||||
util::thread::monitor<foo> obj;
|
||||
const auto &value = obj->value;
|
||||
auto &enter = obj->enter;
|
||||
auto &leave = obj->leave;
|
@ -1,5 +1,5 @@
|
||||
#include "job/semaphore.hpp"
|
||||
#include "job/flag.hpp"
|
||||
#include "thread/semaphore.hpp"
|
||||
#include "thread/flag.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <thread>
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
fight (util::job::semaphore &sem, const int iterations)
|
||||
fight (util::thread::semaphore &sem, const int iterations)
|
||||
{
|
||||
for (int i = 0; i < iterations; ++i)
|
||||
std::lock_guard {sem};
|
||||
@ -22,14 +22,14 @@ main ()
|
||||
util::TAP::logger tap;
|
||||
|
||||
{
|
||||
util::job::semaphore sem (0);
|
||||
util::thread::semaphore sem (0);
|
||||
tap.expect_eq (sem.value (), 0, "initialisation is respected");
|
||||
tap.expect_eq (sem.unlock (), 1, "bare release increments without blocking");
|
||||
tap.expect_eq (sem.lock (), 0, "bare acquire decrements without blocking");
|
||||
}
|
||||
|
||||
{
|
||||
util::job::semaphore sem (1);
|
||||
util::thread::semaphore sem (1);
|
||||
|
||||
std::atomic<int> test = 0;
|
||||
std::thread t ([&] () {
|
||||
@ -53,7 +53,7 @@ main ()
|
||||
constexpr int iterations = 1 << 16;
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
util::job::semaphore sem (0);
|
||||
util::thread::semaphore sem (0);
|
||||
|
||||
for (unsigned i = 0; i < parallelism; ++i)
|
||||
threads.emplace_back (fight, std::ref (sem), iterations);
|
@ -14,8 +14,8 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include "job/flag.hpp"
|
||||
#include "job/spinlock.hpp"
|
||||
#include "thread/flag.hpp"
|
||||
#include "thread/spinlock.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <thread>
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
fight (util::job::flag &start, util::job::spinlock &l, int iterations)
|
||||
fight (util::thread::flag &start, util::thread::spinlock &l, int iterations)
|
||||
{
|
||||
start.wait ();
|
||||
for (int count = 0; count < iterations; ++count)
|
||||
@ -38,7 +38,7 @@ main ()
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
util::job::spinlock l;
|
||||
util::thread::spinlock l;
|
||||
l.lock ();
|
||||
tap.expect (true, "locked without contention");
|
||||
|
||||
@ -49,7 +49,7 @@ main ()
|
||||
tap.skip ("n-way fight");
|
||||
} else {
|
||||
constexpr int iterations = 1 << 12;
|
||||
util::job::flag start_flag;
|
||||
util::thread::flag start_flag;
|
||||
|
||||
std::vector<std::thread> contestants;
|
||||
for (unsigned i = 0; i < std::thread::hardware_concurrency (); ++i)
|
@ -14,8 +14,8 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include "job/flag.hpp"
|
||||
#include "job/ticketlock.hpp"
|
||||
#include "thread/flag.hpp"
|
||||
#include "thread/ticketlock.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <thread>
|
||||
@ -28,7 +28,7 @@ using ffs_t = std::chrono::high_resolution_clock;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
fight (util::job::flag &start, util::job::ticketlock &l, int total, ffs_t::time_point &finish) {
|
||||
fight (util::thread::flag &start, util::thread::ticketlock &l, int total, ffs_t::time_point &finish) {
|
||||
start.wait ();
|
||||
|
||||
for (int count = 0; count < total; ++count)
|
||||
@ -45,7 +45,7 @@ main ()
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
util::job::ticketlock l;
|
||||
util::thread::ticketlock l;
|
||||
l.lock ();
|
||||
tap.expect (true, "locked without contention");
|
||||
|
||||
@ -67,7 +67,7 @@ main ()
|
||||
// there's liable to be a lot of noise in the measurement with a test
|
||||
// that runs in a short enough time period.
|
||||
constexpr int iterations = 1 << 16;
|
||||
util::job::flag start_flag;
|
||||
util::thread::flag start_flag;
|
||||
|
||||
ffs_t::time_point a_finish, b_finish;
|
||||
|
@ -14,12 +14,12 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_JOB_EVENT_HPP
|
||||
#define CRUFT_UTIL_JOB_EVENT_HPP
|
||||
#ifndef CRUFT_UTIL_THREAD_EVENT_HPP
|
||||
#define CRUFT_UTIL_THREAD_EVENT_HPP
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace util::job {
|
||||
namespace util::thread {
|
||||
/// a reusable synchronisation object that allows threads to wait until
|
||||
/// notify is called.
|
||||
///
|
@ -24,7 +24,7 @@
|
||||
#include <cruft/util/posix/except.hpp>
|
||||
#include <limits>
|
||||
|
||||
using util::job::event;
|
||||
using util::thread::event;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -14,12 +14,12 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_JOB_FLAG_HPP
|
||||
#define CRUFT_UTIL_JOB_FLAG_HPP
|
||||
#ifndef CRUFT_UTIL_THREAD_FLAG_HPP
|
||||
#define CRUFT_UTIL_THREAD_FLAG_HPP
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace util::job {
|
||||
namespace util::thread {
|
||||
/// a fire-once event that users can wait upon. if already fired then
|
||||
/// waiting will be a noop.
|
||||
class flag {
|
@ -24,7 +24,7 @@
|
||||
#include <cruft/util/posix/except.hpp>
|
||||
#include <limits>
|
||||
|
||||
using util::job::flag;
|
||||
using util::thread::flag;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -16,4 +16,4 @@
|
||||
|
||||
#include "monitor.hpp"
|
||||
|
||||
using util::job::monitor;
|
||||
using util::thread::monitor;
|
@ -14,15 +14,15 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_JOB_MONITOR_HPP
|
||||
#define CRUFT_UTIL_JOB_MONITOR_HPP
|
||||
#ifndef CRUFT_UTIL_THREAD_MONITOR_HPP
|
||||
#define CRUFT_UTIL_THREAD_MONITOR_HPP
|
||||
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace util::job {
|
||||
namespace util::thread {
|
||||
template <typename ValueT, typename MutexT = std::mutex>
|
||||
class monitor {
|
||||
public:
|
@ -14,12 +14,12 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_JOB_SEMAPHORE_HPP
|
||||
#define CRUFT_UTIL_JOB_SEMAPHORE_HPP
|
||||
#ifndef CRUFT_UTIL_THREAD_SEMAPHORE_HPP
|
||||
#define CRUFT_UTIL_THREAD_SEMAPHORE_HPP
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace util::job {
|
||||
namespace util::thread {
|
||||
/// Explicitly does not conform to BasicLockable.
|
||||
class semaphore {
|
||||
public:
|
@ -25,7 +25,7 @@
|
||||
#include <cruft/util/posix/except.hpp>
|
||||
#include <limits>
|
||||
|
||||
using util::job::semaphore;
|
||||
using util::thread::semaphore;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include "../debug.hpp"
|
||||
|
||||
using util::job::spinlock;
|
||||
using util::thread::spinlock;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -14,12 +14,12 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_JOB_SPINLOCK_HPP
|
||||
#define CRUFT_UTIL_JOB_SPINLOCK_HPP
|
||||
#ifndef CRUFT_UTIL_THREAD_SPINLOCK_HPP
|
||||
#define CRUFT_UTIL_THREAD_SPINLOCK_HPP
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace util::job {
|
||||
namespace util::thread {
|
||||
/// a CPU intensive, but lower latency, lock.
|
||||
///
|
||||
/// std::atomic_flag seems like it might have been a good option on which
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "ticketlock.hpp"
|
||||
|
||||
using util::job::ticketlock;
|
||||
using util::thread::ticketlock;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -14,12 +14,12 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_JOB_TICKETLOCK_HPP
|
||||
#define CRUFT_UTIL_JOB_TICKETLOCK_HPP
|
||||
#ifndef CRUFT_UTIL_THREAD_TICKETLOCK_HPP
|
||||
#define CRUFT_UTIL_THREAD_TICKETLOCK_HPP
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace util::job {
|
||||
namespace util::thread {
|
||||
class ticketlock {
|
||||
public:
|
||||
ticketlock ();
|
Loading…
Reference in New Issue
Block a user