source: src/libcfa/concurrency/thread@ b32ada31

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since b32ada31 was 17af7d1, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Some clean-up of runtime code

  • Property mode set to 100644
File size: 1.9 KB
Line 
1// -*- Mode: CFA -*-
2//
3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
7//
8// thread --
9//
10// Author : Thierry Delisle
11// Created On : Tue Jan 17 12:27:26 2017
12// Last Modified By : Thierry Delisle
13// Last Modified On : --
14// Update Count : 0
15//
16
17#ifndef THREADS_H
18#define THREADS_H
19
20#include "assert"
21#include "invoke.h"
22
23#include "coroutine"
24
25//-----------------------------------------------------------------------------
26// Coroutine trait
27// Anything that implements this trait can be resumed.
28// Anything that is resumed is a coroutine.
29trait is_thread(dtype T) {
30 void ^?{}(T* this);
31 void main(T* this);
32 thread_desc* get_thread(T* this);
33};
34
35#define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
36
37forall( dtype T | is_thread(T) )
38static inline coroutine_desc* get_coroutine(T* this) {
39 return &get_thread(this)->cor;
40}
41
42static inline coroutine_desc* get_coroutine(thread_desc* this) {
43 return &this->cor;
44}
45
46thread_desc * this_thread(void);
47
48//-----------------------------------------------------------------------------
49// Ctors and dtors
50void ?{}(thread_desc* this);
51void ^?{}(thread_desc* this);
52
53//-----------------------------------------------------------------------------
54// thread runner
55// Structure that actually start and stop threads
56forall( dtype T | sized(T) | is_thread(T) )
57struct scoped {
58 T handle;
59};
60
61forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
62void ?{}( scoped(T)* this );
63
64forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
65void ?{}( scoped(T)* this, P params );
66
67forall( dtype T | sized(T) | is_thread(T) )
68void ^?{}( scoped(T)* this );
69
70void yield();
71
72#endif //THREADS_H
73
74// Local Variables: //
75// mode: c //
76// tab-width: 4 //
77// End: //
Note: See TracBrowser for help on using the repository browser.