source: libcfa/src/concurrency/thread.hfa @ 73fad25

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 73fad25 was d4e68a6, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

move location of active_xxx routines, and counter for number processors on a cluster

  • Property mode set to 100644
File size: 3.7 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
[d4e68a6]12// Last Modified On : Fri Jun 21 17:51:33 2019
13// Update Count     : 5
[0e76cf4f]14//
15
[6b0b624]16#pragma once
[0e76cf4f]17
[91c389a]18#include <assert.h>
[8118303]19#include "invoke.h"
[78b3f52]20
[58b6d1b]21#include "coroutine.hfa"
22#include "kernel.hfa"
23#include "monitor.hfa"
[8118303]24
25//-----------------------------------------------------------------------------
[de6319f]26// thread trait
[0c92c9f]27trait is_thread(dtype T) {
[242a902]28      void ^?{}(T& mutex this);
[83a071f9]29      void main(T& this);
30      thread_desc* get_thread(T& this);
[8118303]31};
32
[83a071f9]33#define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this)
[8f49a54]34
[0c92c9f]35forall( dtype T | is_thread(T) )
[83a071f9]36static inline coroutine_desc* get_coroutine(T & this) {
[b18830e]37        return &get_thread(this)->self_cor;
[8118303]38}
39
[cb0e6de]40forall( dtype T | is_thread(T) )
[83a071f9]41static inline monitor_desc* get_monitor(T & this) {
[b18830e]42        return &get_thread(this)->self_mon;
[cb0e6de]43}
44
45static inline coroutine_desc* get_coroutine(thread_desc * this) {
[b18830e]46        return &this->self_cor;
[c84e80a]47}
48
[cb0e6de]49static inline monitor_desc* get_monitor(thread_desc * this) {
[b18830e]50        return &this->self_mon;
[cb0e6de]51}
52
[de6319f]53extern struct cluster * mainCluster;
[bd98b58]54
[bd4d011]55forall( dtype T | is_thread(T) )
[83a071f9]56void __thrd_start( T & this );
[bd4d011]57
[8118303]58//-----------------------------------------------------------------------------
59// Ctors and dtors
[de6319f]60void ?{}(thread_desc & this, const char * const name, struct cluster & cl, void * storage, size_t storageSize );
61void ^?{}(thread_desc & this);
62
[b2f6113]63static inline void ?{}(thread_desc & this)                                                                  { this{ "Anonymous Thread", *mainCluster, NULL, 65000 }; }
[de6319f]64static inline void ?{}(thread_desc & this, size_t stackSize )                                               { this{ "Anonymous Thread", *mainCluster, NULL, stackSize }; }
65static inline void ?{}(thread_desc & this, void * storage, size_t storageSize )                             { this{ "Anonymous Thread", *mainCluster, storage, storageSize }; }
[b2f6113]66static inline void ?{}(thread_desc & this, struct cluster & cl )                                            { this{ "Anonymous Thread", cl, NULL, 65000 }; }
67static inline void ?{}(thread_desc & this, struct cluster & cl, size_t stackSize )                          { this{ "Anonymous Thread", cl, NULL, stackSize }; }
[de6319f]68static inline void ?{}(thread_desc & this, struct cluster & cl, void * storage, size_t storageSize )        { this{ "Anonymous Thread", cl, storage, storageSize }; }
[b2f6113]69static inline void ?{}(thread_desc & this, const char * const name)                                         { this{ name, *mainCluster, NULL, 65000 }; }
70static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl )                   { this{ name, cl, NULL, 65000 }; }
[de6319f]71static inline void ?{}(thread_desc & this, const char * const name, struct cluster & cl, size_t stackSize ) { this{ name, cl, NULL, stackSize }; }
[8118303]72
73//-----------------------------------------------------------------------------
74// thread runner
75// Structure that actually start and stop threads
[8def349]76forall( dtype T | sized(T) | is_thread(T) )
[e15df4c]77struct scoped {
[8118303]78        T handle;
79};
80
[242a902]81forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
82void ?{}( scoped(T)& this );
[8118303]83
[242a902]84forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
85void ?{}( scoped(T)& this, P params );
[8118303]86
[9f1695b]87forall( dtype T | sized(T) | is_thread(T) )
[242a902]88void ^?{}( scoped(T)& this );
[8118303]89
[bd98b58]90void yield();
[44264c5]91void yield( unsigned times );
[596f987b]92
[d4e68a6]93static inline struct thread_desc * active_thread () { return TL_GET( this_thread ); }
94
[78b3f52]95// Local Variables: //
96// mode: c //
97// tab-width: 4 //
98// End: //
Note: See TracBrowser for help on using the repository browser.