Jackalope / jlib (public) (License: GPLv3 or later) (since 2019-11-18) (hash sha1)
jlib C++ template library
Used to replace std functionality without exception handling.
- data structures
- filesystem routines
- crossplatform threads interface (currently only pthreads implementation)
- thread pool
- crossplatform dynamic memory functions interface (allocate, reallocate, deallocate) with alignment support
- high percision timer routines based on timespec
List of commits:
Subject Hash Author Date (UTC)
Resolved issues and warnings with GCC. c9ee73408a660c723dd51b74311d572ec4ef2320 Jackalope 2020-05-26 14:19:43
Thread result can be only pointer now. 645f6ce75c773fd2fad543bfd542202d02925288 Jackalope 2020-05-26 14:19:11
Option JLIB_STATIC to select static or shared library. 08b3a60286a7487ce445f66852f0afdd0f99be69 Jackalope 2020-05-26 14:17:11
Add warning compilation flags. 071b3c83090367f7c2beea5394b926c14620dc66 Jackalope 2020-05-26 13:25:37
New thread pool implementation. 849910e5b45ab543231e24650368289a180452d6 Jackalope 2020-05-26 08:59:03
rarray::iterator_index function 7ee95c6b048973f209fc4e365af36a3dcdb06c4b Jackalope 2020-05-26 08:58:20
darray::remove_last_if_exist logic fix 1664bbfba9d4d8098542c8138a548e4377304aa6 Jackalope 2020-05-26 08:55:31
remove float convertion warning 1ea4783034b873f7711e2ecf840955818c07bcd0 Jackalope 2020-05-26 08:54:04
threads refactoring 9b03fd0beb928de9f3f3e492bb1d324356152de3 Jackalope 2020-05-26 08:52:26
changed notice about native compilation 7b48919f0f46df08f14c8a867d7d1c5d14c19efb Jackalope 2020-05-24 16:37:16
remove LTO option a95b60656c6c00d64efd769d5047853315964556 Jackalope 2020-05-24 13:39:59
compiler options and optimizations 92bc2d91c14c58ce630a7f4f400b5d076ac03286 Jackalope 2020-05-24 01:16:59
cpu_number return unsigned int b9c11a1b4474747c313957bef5573d1db6c481ff Jackalope 2020-05-24 00:13:29
ThreadPool moved to jl namespace, same for cpu_number function 2e486f0d57347197a875abe79b4c637e7c925ecc Jackalope 2020-05-23 23:26:00
removed inline keyword from functions in fs.cpp 295f11fb3a3f285c5393687675d8dd2c86e726b8 Jackalope 2020-05-23 23:25:12
make assert constexpr compatible again 378556f2203439749e7c4003031c3e1de1511f6d Jackalope 2020-05-23 23:24:04
renamed Doxygen options cbda01d11706d12d842d088e917dd3e7866689a2 Jackalope 2020-05-23 23:23:30
Updated license notice 0d013874b3eca0e34ad14cbb4dc4aa7628549a4b Jackalope 2020-05-23 22:52:50
Moved some implementation to library obj target 43b7241f3ded0b0b049d15bf337dac6b25b577e6 Jackalope 2020-05-23 22:44:45
CMake documentation target 8ab15abc55ba97919ffa4b07bdf9389b0ff57a24 Jackalope 2020-05-23 21:19:36
Commit c9ee73408a660c723dd51b74311d572ec4ef2320 - Resolved issues and warnings with GCC.
Author: Jackalope
Author date (UTC): 2020-05-26 14:19
Committer name: Jackalope
Committer date (UTC): 2020-05-26 14:19
Parent(s): 645f6ce75c773fd2fad543bfd542202d02925288
Signing key:
Tree: 53ed08127f3e26aaf30f6fc8070a476a00f0bb36
File Lines added Lines deleted
include/jlib/threads.h 8 7
src/thread_pool.cpp 15 11
File include/jlib/threads.h changed (mode: 100644) (index 6b5b199..8b5506c)
... ... namespace jl::threads {
33 33 using Spinlock [[deprecated]] = spinlock_pth; using Spinlock [[deprecated]] = spinlock_pth;
34 34 using Condition [[deprecated]] = condition_pth; using Condition [[deprecated]] = condition_pth;
35 35
36 template<lock_type T>
37 using Lock [[deprecated]] = typename
38 std::conditional<T == lock_type::SPINLOCK,Spinlock,Mutex>::type;
39
40 36 template<typename result_t> template<typename result_t>
41 using thread = Thread<result_t>;
42 template<lock_type T>
43 using lock = Lock<T>;
37 using thread = thread_pth<result_t>;
44 38 using mutex = mutex_pth; using mutex = mutex_pth;
45 39 using spinlock = spinlock_pth; using spinlock = spinlock_pth;
46 40 using condition = condition_pth; using condition = condition_pth;
41
42 template<lock_type T>
43 using lock [[deprecated]] = typename
44 std::conditional<T == lock_type::SPINLOCK,spinlock,mutex>::type;
45
46 template<lock_type T>
47 using Lock [[deprecated]] = lock<T>;
47 48 } }
48 49 namespace jth = jl::threads; namespace jth = jl::threads;
File src/thread_pool.cpp changed (mode: 100644) (index 668fa40..f5c4d97)
20 20 #include <jlib/rarray.h> #include <jlib/rarray.h>
21 21 #include <jlib/darray.h> #include <jlib/darray.h>
22 22 #include <jlib/threads.h> #include <jlib/threads.h>
23 #ifdef __clang__
23 24 #pragma clang diagnostic ignored "-Wdeprecated" #pragma clang diagnostic ignored "-Wdeprecated"
25 #elif defined __GNUC__
26 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
27 #endif
24 28 constexpr static const unsigned int STASK_UNLOADED = -1u; constexpr static const unsigned int STASK_UNLOADED = -1u;
25 29 using namespace jl; using namespace jl;
26 30 using namespace jl::threads; using namespace jl::threads;
 
... ... struct TaskQueues {
28 32 jl::rarray<jl::darray<Task>> queues; jl::rarray<jl::darray<Task>> queues;
29 33 mutex queues_lock; mutex queues_lock;
30 34 unsigned int in_progress_count; unsigned int in_progress_count;
31 condition idle_condition;
32 condition condition;
35 condition wait_idle_condition;
36 condition wait_task_condition;
33 37 bool has_tasks; bool has_tasks;
34 38 bool brodcast_empty; bool brodcast_empty;
35 39 }; };
 
... ... queues_init(TaskQueues *p, unsigned int count) {
71 75 for (auto &queue : p->queues) for (auto &queue : p->queues)
72 76 queue.init(); queue.init();
73 77 p->queues_lock.init(); p->queues_lock.init();
74 p->condition.init();
75 p->idle_condition.init();
78 p->wait_task_condition.init();
79 p->wait_idle_condition.init();
76 80 p->has_tasks = false; p->has_tasks = false;
77 81 p->brodcast_empty = false; p->brodcast_empty = false;
78 82 p->in_progress_count = 0; p->in_progress_count = 0;
 
... ... queues_destroy(TaskQueues *p) {
83 87 for (auto &queue : p->queues) for (auto &queue : p->queues)
84 88 queue.destroy(); queue.destroy();
85 89 p->queues.destroy(); p->queues.destroy();
86 p->idle_condition.destroy();
87 p->condition.destroy();
90 p->wait_idle_condition.destroy();
91 p->wait_task_condition.destroy();
88 92 } }
89 93 [[nodiscard]] static bool [[nodiscard]] static bool
90 94 queues_submit_task(TaskQueues *p, const Task& task, unsigned int queue_i) { queues_submit_task(TaskQueues *p, const Task& task, unsigned int queue_i) {
 
... ... queues_submit_task(TaskQueues *p, const Task& task, unsigned int queue_i) {
93 97 result = p->queues[queue_i].insert(task); result = p->queues[queue_i].insert(task);
94 98 if (result or not p->has_tasks) { if (result or not p->has_tasks) {
95 99 p->has_tasks = true; p->has_tasks = true;
96 p->condition.wake_up_threads();
100 p->wait_task_condition.wake_up_threads();
97 101 } }
98 102 p->queues_lock.unlock(); p->queues_lock.unlock();
99 103 return result; return result;
 
... ... queues_get_task(TaskQueues *p, Task *p_dst, bool *p_stop, bool job_done) {
107 111 while (not p->has_tasks and not *p_stop) { WAIT: while (not p->has_tasks and not *p_stop) { WAIT:
108 112 if (p->brodcast_empty) { if (p->brodcast_empty) {
109 113 p->brodcast_empty = false; p->brodcast_empty = false;
110 p->idle_condition.wake_up_thread();
114 p->wait_idle_condition.wake_up_thread();
111 115 } }
112 p->condition.wait(&p->queues_lock);
116 p->wait_task_condition.wait(&p->queues_lock);
113 117 } }
114 118 if (*p_stop) { if (*p_stop) {
115 119 continue_to_work = false; continue_to_work = false;
 
... ... C_T:
271 275 static void static void
272 276 pool_stop(ThreadPool::Data *p) { pool_stop(ThreadPool::Data *p) {
273 277 p->stop_work = true; p->stop_work = true;
274 p->task_queues.condition.wake_up_threads();
278 p->task_queues.wait_task_condition.wake_up_threads();
275 279 for (auto &th : p->threads) for (auto &th : p->threads)
276 280 th.instance.join(); th.instance.join();
277 281 p->stask_queue.destroy(); p->stask_queue.destroy();
 
... ... wait_idle() {
316 320 or or
317 321 p->task_queues.in_progress_count > 0) { p->task_queues.in_progress_count > 0) {
318 322 p->task_queues.brodcast_empty = true; p->task_queues.brodcast_empty = true;
319 p->task_queues.idle_condition.wait(&p->task_queues.queues_lock);
323 p->task_queues.wait_idle_condition.wait(&p->task_queues.queues_lock);
320 324 } }
321 325 p->task_queues.queues_lock.unlock(); p->task_queues.queues_lock.unlock();
322 326 } }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/Jackalope/jlib

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/Jackalope/jlib

Clone this repository using git:
git clone git://git.rocketgit.com/user/Jackalope/jlib

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main