Line data Source code
1 1 : /** 2 : * @file arch/thread.h 3 : * 4 : * @brief Generic architecture management facilities 5 : * 6 : * This module provides generic facilities for thread and core management. 7 : * In particular, helper functions to startup worker threads are exposed, 8 : * and a function to synchronize multiple threads on a software barrier. 9 : * 10 : * The software barrier also offers a leader election facility, so that 11 : * once all threads are synchronized on the barrier, the function returns 12 : * true to only one of them. 13 : * 14 : * SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com> 15 : * SPDX-License-Identifier: GPL-3.0-only 16 : */ 17 : #pragma once 18 : 19 : #include <arch/platform.h> 20 : 21 : #if defined(__POSIX) 22 : #define _GNU_SOURCE 23 : #include <pthread.h> 24 : 25 : #define THREAD_CALL_CONV 26 : typedef void * thr_ret_t; 27 : typedef pthread_t thr_id_t; 28 : 29 : #define THREAD_RET_FAILURE ((void *) 1) 30 : #define THREAD_RET_SUCCESS ((void *) 0) 31 : 32 : #elif defined(__WINDOWS) 33 : 34 : #define WIN32_LEAN_AND_MEAN 35 : #include <windows.h> 36 : #undef WIN32_LEAN_AND_MEAN 37 : 38 : #define THREAD_CALL_CONV WINAPI 39 : typedef DWORD arch_thr_ret_t; 40 : typedef HANDLE arch_thr_t; 41 : 42 : #define THREAD_RET_FAILURE (1) 43 : #define THREAD_RET_SUCCESS (0) 44 : 45 : #endif 46 : 47 : /// The function type of a new thread entry point 48 1 : typedef thr_ret_t THREAD_CALL_CONV (*thr_run_fnc)(void *); 49 : 50 1 : extern int thread_start(thr_id_t *thr_p, thr_run_fnc t_fnc, void *t_fnc_arg); 51 1 : extern int thread_affinity_set(thr_id_t thr, unsigned core); 52 1 : extern int thread_wait(thr_id_t thr, thr_ret_t *ret); 53 1 : extern unsigned thread_cores_count(void);