Last change
on this file was
d4da6886,
checked in by Thierry Delisle <tdelisle@…>, 4 years ago
|
Some renaming to move away from dlopen in toy program
|
-
Property mode set to
100644
|
File size:
974 bytes
|
Line | |
---|
1 | #include <cassert> |
---|
2 | #include <libfibre/cfibre.h> |
---|
3 | |
---|
4 | typedef cfibre_t thread_t; |
---|
5 | static_assert(sizeof(thread_t) == sizeof(void*), "thread_t musst be of same size as void*"); |
---|
6 | |
---|
7 | void * fibre_runner(void * arg) { |
---|
8 | auto the_main = (void (*)( thread_t ))arg; |
---|
9 | the_main( cfibre_self() ); |
---|
10 | return nullptr; |
---|
11 | } |
---|
12 | |
---|
13 | extern "C" { |
---|
14 | //-------------------- |
---|
15 | // Basic thread support |
---|
16 | thread_t thrdlib_create( void (*the_main)( thread_t ) ) { |
---|
17 | thread_t fibre; |
---|
18 | cfibre_create( &fibre, nullptr, fibre_runner, (void*)the_main ); |
---|
19 | return fibre; |
---|
20 | } |
---|
21 | |
---|
22 | void thrdlib_join( thread_t handle ) { |
---|
23 | cfibre_join( handle, nullptr ); |
---|
24 | } |
---|
25 | |
---|
26 | void thrdlib_park( thread_t handle ) { |
---|
27 | assert( handle == cfibre_self() ); |
---|
28 | cfibre_park(); |
---|
29 | } |
---|
30 | |
---|
31 | void thrdlib_unpark( thread_t handle ) { |
---|
32 | cfibre_unpark( handle ); |
---|
33 | } |
---|
34 | |
---|
35 | void thrdlib_yield( void ) { |
---|
36 | cfibre_yield(); |
---|
37 | } |
---|
38 | |
---|
39 | //-------------------- |
---|
40 | // Basic kernel features |
---|
41 | void thrdlib_init( int procs ) { |
---|
42 | cfibre_init_n(1, procs ); |
---|
43 | } |
---|
44 | |
---|
45 | void thrdlib_clean( void ) { |
---|
46 | |
---|
47 | } |
---|
48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.