source: src/libcfa/concurrency/threads.c @ 8118303

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 8118303 was 8118303, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

First prototype of cfa threads running (1 thread on 1 processor)

  • Property mode set to 100644
File size: 2.2 KB
Line 
1//                              -*- Mode: CFA -*-
2//
3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
7//
8// threads.c --
9//
10// Author           : Thierry Delisle
11// Created On       : Tue Jan 17 12:27:26 2016
12// Last Modified By : Thierry Delisle
13// Last Modified On : --
14// Update Count     : 0
15//
16
17#include "threads"
18
19#include "kernel"
20#include "libhdr.h"
21
22#define __CFA_INVOKE_PRIVATE__
23#include "invoke.h"
24
25#include <stdlib>
26
27//-----------------------------------------------------------------------------
28// Forward declarations
29forall(otype T | is_thread(T) )
30void start( thread(T)* this );
31
32forall(otype T | is_thread(T) )
33void stop( thread(T)* this );
34
35//-----------------------------------------------------------------------------
36// Thread ctors and dtors
37
38void ?{}(thread_h* this) {
39        (&this->c){};
40}
41
42void ^?{}(thread_h* this) {
43        ^(&this->c){};
44}
45
46forall(otype T | is_thread(T) )
47void ?{}( thread(T)* this ) {
48        printf("thread() ctor\n");
49        (&this->handle){};
50        start(this);
51}
52
53forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
54void ?{}( thread(T)* this, P params ) {
55        (&this->handle){ params };
56        start(this);
57}
58
59forall(otype T | is_thread(T) )
60void ^?{}( thread(T)* this ) {
61        stop(this);
62        ^(&this->handle){};
63}
64
65//-----------------------------------------------------------------------------
66// Starting and stopping threads
67extern "C" {
68      forall(dtype T | is_thread(T))
69      void CtxInvokeThread(T * this);
70}
71
72forall(otype T | is_thread(T))
73void start( thread(T)* this ) {
74        T* handle  = &this->handle;
75        coroutine* thrd_c = get_coroutine(handle);
76        thread_h*  thrd_h = get_thread   (handle);
77        thrd_c->last = this_coroutine();
78        current_coroutine = thrd_c;
79
80        LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", handle, thrd_c, thrd_h);
81
82        create_stack(&thrd_c->stack, thrd_c->stack.size);
83        CtxStart(handle, CtxInvokeThread);
84        CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
85
86        the_thread = thrd_h;
87}
88
89forall(otype T | is_thread(T) )
90void stop( thread(T)* this ) {
91
92}
93
94// Local Variables: //
95// mode: c //
96// tab-width: 4 //
97// End: //
Note: See TracBrowser for help on using the repository browser.