source: doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/fibre.cpp @ 29185fc

arm-ehjacob/cs343-translationnew-ast-unique-expr
Last change on this file since 29185fc was 29185fc, checked in by Thierry Delisle <tdelisle@…>, 14 months ago

Working towards allowing different thread frameworks to be picked from the command line

  • Property mode set to 100644
File size: 974 bytes
Line 
1#include <cassert>
2#include <libfibre/cfibre.h>
3
4typedef cfibre_t thread_t;
5static_assert(sizeof(thread_t) == sizeof(void*), "thread_t musst be of same size as void*");
6
7void * fibre_runner(void * arg) {
8        auto the_main = (void (*)( thread_t ))arg;
9        the_main( cfibre_self() );
10        return nullptr;
11}
12
13extern "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.