26 return sysinfo.dwNumberOfProcessors;
27 #elif __APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __NetBSD__
30 unsigned long n_cpus = 1;
31 size_t n_cpus_length =
sizeof(n_cpus);
36 mib[1] = HW_NCPUONLINE;
37 #elif __OpenBSD__ || __FreeBSD__ || __DragonFly__
43 os_status = sysctl(mib, 2, &n_cpus, &n_cpus_length,
NULL, 0);
46 #if __OpenBSD__ || __FreeBSD__
51 os_status = sysctl(mib, 2, &n_cpus, &n_cpus_length,
NULL, 0);
63 get_system_info(&
info);
64 return info.cpu_count;
66 return sysconf(_SC_NPROCESSORS_ONLN);
83 return RZ_MIN(n_cores, max_cores);
121 for (
ut32 i = 0;
i < pool->size; ++
i) {
122 if (pool->threads[
i]) {
124 pool->threads[
i] =
NULL;
140 for (
ut32 i = 0;
i < pool->size; ++
i) {
141 if (!pool->threads[
i]) {
143 pool->threads[
i] = thread;
160 return pool->threads[index];
172 bool has_exited =
true;
173 for (
ut32 i = 0;
i < pool->size; ++
i) {
174 if (pool->threads[
i]) {
176 has_exited = has_exited &&
rz_th_wait(pool->threads[
i]);
RzBinInfo * info(RzBinFile *bf)
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API void rz_th_free(RZ_NULLABLE RzThread *th)
Frees a RzThread structure.
RZ_API bool rz_th_wait(RZ_NONNULL RzThread *th)
Awaits indefinetely for a thread to join.
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage sysinfo
#define rz_return_val_if_fail(expr, val)
#define RZ_LOG_DEBUG(fmtstr,...)
RzThreadPool is a structure which handles n-threads threads.
RZ_API size_t rz_th_request_physical_cores(size_t max_cores)
Returns the maximum number of cores available regardless of the number of cores requested....
RZ_API void rz_th_pool_free(RZ_NULLABLE RzThreadPool *pool)
Kills (and frees) the threads and frees the RzThreadPool struct.
RZ_API size_t rz_th_physical_core_number()
Returns the number of available physical cores of the host machine.
RZ_API RZ_BORROW RzThread * rz_th_pool_get_thread(RZ_NONNULL RzThreadPool *pool, size_t index)
Returns the n-th thread in the thread pool.
RZ_API bool rz_th_pool_wait(RZ_NONNULL RzThreadPool *pool)
Waits the end of all the threads in the thread pool.
RZ_API bool rz_th_pool_add_thread(RZ_NONNULL RzThreadPool *pool, RZ_NONNULL RzThread *thread)
Adds a thread to the thread pool.
RZ_API size_t rz_th_pool_size(RZ_NONNULL RzThreadPool *pool)
Returns the thread pool size.
RZ_API RZ_OWN RzThreadPool * rz_th_pool_new(size_t max_threads)
returns a new RzThreadPool structure with a pool of thread