File indexing completed on 2026-11-07 10:15:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef THREAD_POOL_H
0013 #define THREAD_POOL_H
0014
0015 #include "flint.h"
0016
0017 #if FLINT_USES_PTHREAD
0018 #include <pthread.h>
0019 #endif
0020
0021 #ifdef __cplusplus
0022 extern "C" {
0023 #endif
0024
0025 typedef struct
0026 {
0027 #if FLINT_USES_PTHREAD
0028 pthread_t pth;
0029 pthread_mutex_t mutex;
0030 pthread_cond_t sleep1;
0031 pthread_cond_t sleep2;
0032 #endif
0033 volatile int idx;
0034 volatile int available;
0035 volatile int max_workers;
0036 void (* fxn)(void *);
0037 void * fxnarg;
0038 volatile int working;
0039 volatile int exit;
0040 } thread_pool_entry_struct;
0041
0042 typedef thread_pool_entry_struct thread_pool_entry_t[1];
0043
0044 typedef struct
0045 {
0046 #if FLINT_USES_CPUSET && FLINT_USES_PTHREAD
0047 void * original_affinity;
0048 #endif
0049 #if FLINT_USES_PTHREAD
0050 pthread_mutex_t mutex;
0051 #endif
0052 thread_pool_entry_struct * tdata;
0053 slong length;
0054 } thread_pool_struct;
0055
0056 typedef thread_pool_struct thread_pool_t[1];
0057
0058 FLINT_DLL extern thread_pool_t global_thread_pool;
0059 FLINT_DLL extern int global_thread_pool_initialized;
0060
0061 void * thread_pool_idle_loop(void * varg);
0062
0063 void thread_pool_init(thread_pool_t T, slong size);
0064
0065 int thread_pool_set_affinity(thread_pool_t T,
0066 int * cpus, slong length);
0067
0068 int thread_pool_restore_affinity(thread_pool_t T);
0069
0070 slong thread_pool_get_size(thread_pool_t T);
0071
0072 int thread_pool_set_size(thread_pool_t T, slong new_size);
0073
0074 slong thread_pool_request(thread_pool_t T,
0075 thread_pool_handle * out, slong requested);
0076
0077 void thread_pool_wake(thread_pool_t T, thread_pool_handle i,
0078 int max_workers, void (*f)(void*), void * a);
0079
0080 void thread_pool_wait(thread_pool_t T, thread_pool_handle i);
0081
0082 void thread_pool_give_back(thread_pool_t T, thread_pool_handle i);
0083
0084 void thread_pool_clear(thread_pool_t T);
0085
0086
0087
0088 void _thread_pool_distribute_work_2(slong start, slong stop,
0089 slong * Astart, slong * Astop, slong Alen,
0090 slong * Bstart, slong * Bstop, slong FLINT_UNUSED(Blen));
0091
0092 ulong _thread_pool_find_work_2(ulong a, ulong alpha,
0093 ulong b, ulong beta, ulong yn, ulong yd);
0094
0095 #ifdef __cplusplus
0096 }
0097 #endif
0098
0099 #endif