// -*- Mode: CFA -*- // // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // threads -- // // Author : Thierry Delisle // Created On : Tue Jan 17 12:27:26 2016 // Last Modified By : Thierry Delisle // Last Modified On : -- // Update Count : 0 // #ifndef THREADS_H #define THREADS_H #include "assert" #include "invoke.h" #include "coroutines" //----------------------------------------------------------------------------- // Coroutine trait // Anything that implements this trait can be resumed. // Anything that is resumed is a coroutine. trait is_thread(dtype T /*| sized(T)*/) { void main(T* this); thread_h* get_thread(T* this); /*void ?{}(T*); void ^?{}(T*);*/ }; forall(otype T | is_thread(T) ) static inline coroutine* get_coroutine(T* this) { return &get_thread(this)->c; } //----------------------------------------------------------------------------- // Ctors and dtors void ?{}(thread_h* this); void ^?{}(thread_h* this); //----------------------------------------------------------------------------- // thread runner // Structure that actually start and stop threads forall(otype T | is_thread(T) ) struct thread { T handle; }; forall(otype T | is_thread(T) ) void ?{}( thread(T)* this ); forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } ) void ?{}( thread(T)* this, P params ); forall(otype T | is_thread(T) ) void ^?{}( thread(T)* this ); //----------------------------------------------------------------------------- // PRIVATE exposed because of inline #endif //THREADS_H // Local Variables: // // mode: c // // tab-width: 4 // // End: //