source: src/libcfa/concurrency/thread @ cb0e6de

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since cb0e6de was cb0e6de, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Threads now use monitor semantics to wait until completion

  • 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
58//-----------------------------------------------------------------------------
59// Ctors and dtors
60void ?{}(thread_desc* this);
61void ^?{}(thread_desc* this);
62
63//-----------------------------------------------------------------------------
64// thread runner
65// Structure that actually start and stop threads
66forall( dtype T | sized(T) | is_thread(T) )
67struct scoped {
68        T handle;
69};
70
71forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
72void ?{}( scoped(T)* this );
73
74forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
75void ?{}( scoped(T)* this, P params );
76
77forall( dtype T | sized(T) | is_thread(T) )
78void ^?{}( scoped(T)* this );
79
80void yield();
81
82#endif //THREADS_H
83
84// Local Variables: //
85// mode: c //
86// tab-width: 4 //
87// End: //
Note: See TracBrowser for help on using the repository browser.