Zth (libzth)
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019-2026 Jochem Rutgers
3 *
4 * SPDX-License-Identifier: MPL-2.0
5 */
6
7#include <libzth/async.h>
8#include <libzth/config.h>
9#include <libzth/worker.h>
10
11__attribute__((weak)) int main_fiber(int UNUSED_PAR(argc), char** UNUSED_PAR(argv))
12{
13 return 0;
14}
15#ifndef DOXYGEN
17#endif
18
27__attribute__((weak)) void zth_preinit() {}
28
39__attribute__((weak)) int zth_postdeinit()
40{
41 return 0;
42}
43
44#ifndef ZTH_OS_WINDOWS
45__attribute__((weak))
46#endif
47int main(int argc, char** argv)
48{
50 zth_dbg(thread, "main()");
51
52 int res = 0;
53 {
55 main_fiber_future f =
56 zth_async main_fiber(argc, argv) << zth::setName(
59 ? "main_fiber"
60 : nullptr);
61
62 w.run();
63 if(f->valid())
64 res = f->value();
65 }
66
67 zth_dbg(thread, "main() returns %d", res);
68
69 int res_post = zth_postdeinit();
70 // cppcheck-suppress knownConditionTrueFalse
71 if(res_post)
72 res = res_post;
73
74 return res;
75}
#define zth_fiber_define_1(storage, f)
Definition async.h:781
The class that manages the fibers within this thread.
Definition worker.h:35
void run(TimeInterval const &duration=TimeInterval())
Definition worker.h:307
Change the name of a fiber returned by zth_async.
Definition async.h:173
#define zth_async
Run a function as a new fiber.
Definition async.h:828
#define zth_dbg(group, fmt, a...)
Debug printf()-like function.
Definition util.h:189
#define UNUSED_PAR(name)
Definition macros.h:78
int main(int argc, char **argv)
Definition main.cpp:47
int zth_postdeinit()
Initialization function to be called by the default-supplied main(), just before shutting down.
Definition main.cpp:39
void zth_preinit()
Initialization function to be called by the default-supplied main(), before doing anything else.
Definition main.cpp:27
int main_fiber(int argc, char **argv)
Definition main.cpp:11
static bool const EnablePerfEvent
Enable (but not necessarily record) perf.
Definition config.h:173
static bool const EnableDebugPrint
Actually do print the debug output.
Definition config.h:97
static bool const EnableStackWaterMark
When true, enable stack watermark to detect maximum stack usage.
Definition config.h:143