source: src/libcfa/concurrency/thread @ 55f5c59

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 55f5c59 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
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//
[75a17f1]8// thread --
[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
[75a17f1]23#include "coroutine"
[cb0e6de]24#include "monitor"
[8118303]25
26//-----------------------------------------------------------------------------
27// Coroutine trait
28// Anything that implements this trait can be resumed.
29// Anything that is resumed is a coroutine.
[0c92c9f]30trait is_thread(dtype T) {
[cb0e6de]31      void ^?{}(T* mutex this);
[7fbe450]32      void main(T* this);
[348006f]33      thread_desc* get_thread(T* this);
[8118303]34};
35
[17af7d1]36#define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
[8f49a54]37
[0c92c9f]38forall( dtype T | is_thread(T) )
[c3acb841]39static inline coroutine_desc* get_coroutine(T* this) {
[17af7d1]40        return &get_thread(this)->cor;
[8118303]41}
42
[cb0e6de]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) {
[17af7d1]49        return &this->cor;
[c84e80a]50}
51
[cb0e6de]52static inline monitor_desc* get_monitor(thread_desc * this) {
53        return &this->mon;
54}
55
[348006f]56thread_desc * this_thread(void);
[bd98b58]57
[bd4d011]58forall( dtype T | is_thread(T) )
59void __thrd_start( T* this );
60
[8118303]61//-----------------------------------------------------------------------------
62// Ctors and dtors
[348006f]63void ?{}(thread_desc* this);
64void ^?{}(thread_desc* this);
[8118303]65
66//-----------------------------------------------------------------------------
67// thread runner
68// Structure that actually start and stop threads
[8def349]69forall( dtype T | sized(T) | is_thread(T) )
[e15df4c]70struct scoped {
[8118303]71        T handle;
72};
73
[8def349]74forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
[e15df4c]75void ?{}( scoped(T)* this );
[8118303]76
[8def349]77forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
[e15df4c]78void ?{}( scoped(T)* this, P params );
[8118303]79
[9f1695b]80forall( dtype T | sized(T) | is_thread(T) )
[e15df4c]81void ^?{}( scoped(T)* this );
[8118303]82
[bd98b58]83void yield();
[44264c5]84void yield( unsigned times );
[596f987b]85
[17e5e2b]86#endif //THREADS_H
87
[78b3f52]88// Local Variables: //
89// mode: c //
90// tab-width: 4 //
91// End: //
Note: See TracBrowser for help on using the repository browser.