ae2f_docs
Thrd.core.h
Go to the documentation of this file.
1/**
2 * @file Thrd.core.h
3 * @brief Contains unified types and dependencies.
4 * */
5#ifndef ae2f_Sys_Thrd_core_h
6#define ae2f_Sys_Thrd_core_h
7
8#include <ae2f/LangVer.h>
9#include <ae2f/Cast.h>
10
11#include "../Sys.h"
12
13#if ae2f_Sys_WIN(!)0
14#include <windows.h>
15#include <time.h>
16
17#define _ae2f_SysThrdRes_t DWORD /* WINAPI */
18#define _ae2f_SysThrdPrm_t /* __drv_aliasesMem */ LPVOID
19#define _ae2f_SysThrdID_t HANDLE
20
21#elif ae2f_Sys__linux(!)0
22
23/**
24 * @macro __ae2f_SysThrdStckTopOper
25 * A macro to make top pointer.
26 * */
27#ifndef __ae2f_SysThrdStckTopOper
28#define __ae2f_SysThrdStckTopOper(prm_ptr, prm_sz) ((prm_ptr) + (prm_sz))
29#endif
30
31#define _GNU_SOURCE
32#include <sys/mman.h>
33#include <sys/syscall.h>
34#include <unistd.h>
35#include <c89atomic.h>
36#include <sched.h>
37#include <linux/sched.h>
38#include <signal.h>
39#include "./Ftx.h"
40
41#define _ae2f_SysThrdRes_t int
42#define _ae2f_SysThrdPrm_t void*
43#define _ae2f_SysThrdID_t int
44
45ae2f_structdef(struct, _ae2f_SysThrdRunnerPrm_t)
46{
47 int m_ret;
48 /**
49 * if 1, is done.
50 * This member must not be changed by multiple threads
51 * */
52 ae2f_SysFtxEl_t m_done;
53 ae2f_SysFtxRet_t m_ftxret;
54
55 int (*m_fn)(void*);
56 void* m_arg;
57 size_t m_stcksz;
58};
59
60ae2f_structdef(union, _ae2f_SysThrdStckPtr_t)
61{
62 void* ae2f_restrict m_void;
63 char* ae2f_restrict m_char;
64 _ae2f_SysThrdRunnerPrm_t* ae2f_restrict m_prm;
65};
66
67static void _ae2f_SysThrdRunner(_ae2f_SysThrdRunnerPrm_t* prm_stck) {
68
69 if(prm_stck) {
70 /** child section */
71 (prm_stck)->m_done = 0;
72 (prm_stck)->m_ret = (prm_stck->m_fn)((prm_stck)->m_arg);
73 (prm_stck)->m_done = 1;
74
76 (prm_stck)->m_ftxret
77 , (&(prm_stck)->m_done)
78 );
79
80 syscall(SYS_exit, 0);
81 }
82
83 syscall(SYS_exit, -1);
84}
85
86#else
87#include <pthread.h>
88#include <errno.h>
89#include <sched.h>
90
91#define _ae2f_SysThrdRes_t void*
92#define _ae2f_SysThrdPrm_t void*
93#define _ae2f_SysThrdID_t pthread_t
94#endif
95
96#endif
#define ae2f_structdef(key, name)
Definition Cast.h:110
#define ae2f_reinterpret_cast(t, v)
Definition Cast.h:52
#define unless(...)
Invokes when condition is false.
Definition Cast.h:103
#define __ae2f_MACRO_GENERATED
Definition Conv.auto.h:2
#define _ae2f_SysFtxWait(ret_err, prm_uaddr, prm_val)
Definition Ftx.auto.h:109
#define _ae2f_SysFtxWakeOne(ret_err, prm_uaddr)
Definition Ftx.auto.h:147
_ae2f_SysFtxRet_t ae2f_SysFtxRet_t
State for futex operation.
Definition Ftx.h:22
_ae2f_SysFtxEl_t ae2f_SysFtxEl_t
Futex address element type.
Definition Ftx.h:13
#define ae2f_Sys__linux
Definition Sys.h:14
#define ae2f_Sys_WIN
Definition Sys.h:17
#define _ae2f_SysThrdJoin_imp(ret_stat, ret_rtn, ref_thrd)
Definition Thrd.auto.h:333
#define _ae2f_SysThrdYield_imp()
Definition Thrd.auto.h:374
#define _ae2f_SysThrdSleep_imp(ret_stat, prm_req, prm_rem)
Definition Thrd.auto.h:361
#define ae2f_Sys_Thrd_auto_h
Definition Thrd.auto.h:25
#define _ae2f_SysThrdMk_imp(ret_stat, ret_thrd, prm_func, prm_arg, prm_stcksz_unused)
Definition Thrd.auto.h:297
#define _ae2f_SysThrdID_t
Definition Thrd.core.h:93
#define _ae2f_SysThrdPrm_t
Definition Thrd.core.h:92
#define _ae2f_SysThrdRes_t
Definition Thrd.core.h:91
ae2f_eSysThrd_t
enum values related to thread. 't follows C11 thread standard.
Definition Thrd.h:33
@ ae2f_eSysThrdTmOut
Definition Thrd.h:41
@ ae2f_eSysThrdMemOut
Definition Thrd.h:38
@ ae2f_eSysThrdSuccess
Definition Thrd.h:35
_ae2f_SysThrdRes_t ae2f_SysThrdRes_t
Return type for thread.
Definition Thrd.h:14
_ae2f_SysThrdPrm_t ae2f_SysThrdPrm_t
Parameters for thread.
Definition Thrd.h:18
ae2f_SysThrdRes_t ae2f_SysThrdFn_t(ae2f_SysThrdPrm_t)
Thread starting function type.
Definition Thrd.h:25
_ae2f_SysThrdID_t ae2f_SysThrdID_t
Thread ID.
Definition Thrd.h:22
#define ae2f_MAC(...)
Definition mac.h:28