source: src/libcfa/concurrency/thread @ 8c700c1

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 8c700c1 was 44264c5, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Working implementation of internal scheduling, TODO some cleanup

  • Property mode set to 100644
File size: 2.2 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#include "monitor"
25
26//-----------------------------------------------------------------------------
27// Coroutine trait
28// Anything that implements this trait can be resumed.
29// Anything that is resumed is a coroutine.
30trait is_thread(dtype T) {
31      void ^?{}(T* mutex this);
32      void main(T* this);
33      thread_desc* get_thread(T* this);
34};
35
36#define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
37
38forall( dtype T | is_thread(T) )
39static inline coroutine_desc* get_coroutine(T* this) {
40        return &get_thread(this)->cor;
41}
42
43forall( dtype T | is_thread(T) )
44static inline monitor_desc* get_monitor(T * this) {
45        return &get_thread(this)->mon;
46}
47
48static inline coroutine_desc* get_coroutine(thread_desc * this) {
49        return &this->cor;
50}
51
52static inline monitor_desc* get_monitor(thread_desc * this) {
53        return &this->mon;
54}
55
56thread_desc * this_thread(void);
57
58forall( dtype T | is_thread(T) )
59void __thrd_start( T* this );
60
61//-----------------------------------------------------------------------------
62// Ctors and dtors
63void ?{}(thread_desc* this);
64void ^?{}(thread_desc* this);
65
66//-----------------------------------------------------------------------------
67// thread runner
68// Structure that actually start and stop threads
69forall( dtype T | sized(T) | is_thread(T) )
70struct scoped {
71        T handle;
72};
73
74forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
75void ?{}( scoped(T)* this );
76
77forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
78void ?{}( scoped(T)* this, P params );
79
80forall( dtype T | sized(T) | is_thread(T) )
81void ^?{}( scoped(T)* this );
82
83void yield();
84void yield( unsigned times );
85
86#endif //THREADS_H
87
88// Local Variables: //
89// mode: c //
90// tab-width: 4 //
91// End: //
Note: See TracBrowser for help on using the repository browser.