source: src/libcfa/concurrency/thread @ 94ddede

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 94ddede was b10affd, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

thread-local storage converted to structure and thread-local macros for access

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[0e76cf4f]1//
[78b3f52]2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
[0e76cf4f]3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[75a17f1]7// thread --
[0e76cf4f]8//
[78b3f52]9// Author           : Thierry Delisle
[f07e037]10// Created On       : Tue Jan 17 12:27:26 2017
[91c389a]11// Last Modified By : Peter A. Buhr
[b10affd]12// Last Modified On : Thu Mar 29 14:07:11 2018
13// Update Count     : 4
[0e76cf4f]14//
15
[6b0b624]16#pragma once
[0e76cf4f]17
[91c389a]18#include <assert.h>
[8118303]19#include "invoke.h"
[78b3f52]20
[75a17f1]21#include "coroutine"
[cb0e6de]22#include "monitor"
[8118303]23
24//-----------------------------------------------------------------------------
25// Coroutine trait
26// Anything that implements this trait can be resumed.
27// Anything that is resumed is a coroutine.
[0c92c9f]28trait is_thread(dtype T) {
[242a902]29      void ^?{}(T& mutex this);
[83a071f9]30      void main(T& this);
31      thread_desc* get_thread(T& this);
[8118303]32};
33
[83a071f9]34#define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this)
[8f49a54]35
[0c92c9f]36forall( dtype T | is_thread(T) )
[83a071f9]37static inline coroutine_desc* get_coroutine(T & this) {
[b18830e]38        return &get_thread(this)->self_cor;
[8118303]39}
40
[cb0e6de]41forall( dtype T | is_thread(T) )
[83a071f9]42static inline monitor_desc* get_monitor(T & this) {
[b18830e]43        return &get_thread(this)->self_mon;
[cb0e6de]44}
45
46static inline coroutine_desc* get_coroutine(thread_desc * this) {
[b18830e]47        return &this->self_cor;
[c84e80a]48}
49
[cb0e6de]50static inline monitor_desc* get_monitor(thread_desc * this) {
[b18830e]51        return &this->self_mon;
[cb0e6de]52}
53
[b10affd]54//extern thread_local thread_desc * volatile this_thread;
[bd98b58]55
[bd4d011]56forall( dtype T | is_thread(T) )
[83a071f9]57void __thrd_start( T & this );
[bd4d011]58
[8118303]59//-----------------------------------------------------------------------------
60// Ctors and dtors
[242a902]61void ?{}(thread_desc& this);
62void ^?{}(thread_desc& this);
[8118303]63
64//-----------------------------------------------------------------------------
65// thread runner
66// Structure that actually start and stop threads
[8def349]67forall( dtype T | sized(T) | is_thread(T) )
[e15df4c]68struct scoped {
[8118303]69        T handle;
70};
71
[242a902]72forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
73void ?{}( scoped(T)& this );
[8118303]74
[242a902]75forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
76void ?{}( scoped(T)& this, P params );
[8118303]77
[9f1695b]78forall( dtype T | sized(T) | is_thread(T) )
[242a902]79void ^?{}( scoped(T)& this );
[8118303]80
[bd98b58]81void yield();
[44264c5]82void yield( unsigned times );
[596f987b]83
[78b3f52]84// Local Variables: //
85// mode: c //
86// tab-width: 4 //
87// End: //
Note: See TracBrowser for help on using the repository browser.