source: src/libcfa/concurrency/threads @ f07e037

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 f07e037 was f07e037, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Basic monitor implementation

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