source: libcfa/src/concurrency/clib/cfathread.cfa @ 4e39f51

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 4e39f51 was bb662027, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Added cfathread C library which encapsulates a small part of libcfa threads in a C interface.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// clib/cfathread.cfa --
8//
9// Author           : Thierry Delisle
10// Created On       : Tue Sep 22 15:31:20 2020
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#include "kernel.hfa"
17#include "thread.hfa"
18
19thread CRunner {
20        void (*themain)( CRunner * );
21};
22
23static void ?{}( CRunner & this, void (*themain)( CRunner * ) ) {
24        this.themain = themain;
25}
26
27void main( CRunner & this ) {
28        this.themain( &this );
29}
30
31processor * procs = 0p;
32int proc_cnt = 1;
33
34extern "C" {
35        //--------------------
36        // Basic thread managenemt
37        CRunner * cfathread_create( void (*main)( CRunner * ) ) {
38                return new( main );
39        }
40
41        void cfathread_join( CRunner * thrd ) {
42                delete( thrd );
43        }
44
45        void cfathread_park( void ) {
46                park( __cfaabi_dbg_ctx );
47        }
48
49        void cfathread_unpark( CRunner * thrd ) {
50                unpark( *thrd __cfaabi_dbg_ctx2 );
51        }
52
53        void cfathread_yield( void ) {
54                yield();
55        }
56
57        //--------------------
58        // Basic kernel features
59        void cfathread_setproccnt( int ncnt ) {
60                assert( ncnt >= 1 );
61                adelete(proc_cnt, procs);
62
63                proc_cnt = ncnt - 1;
64                procs = anew(proc_cnt);
65        }
66}
Note: See TracBrowser for help on using the repository browser.