source: src/libcfa/concurrency/thread@ 5527759

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since 5527759 was de6319f, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Implemented clusters and added many constructors for threads/coroutines/processors

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