source: src/libcfa/concurrency/invoke.h @ db6f06a

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

Implemented better condition lock to solve race condition on thread/processor termination

  • Property mode set to 100644
File size: 3.3 KB
Line 
1//                              -*- Mode: C -*-
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// invoke.h --
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 <stdbool.h>
18#include <stdint.h>
19
20#ifdef __CFORALL__
21extern "C" {
22#endif
23
24#if ! defined(__CFA_INVOKE_PRIVATE__)
25#ifndef _INVOKE_H_
26#define _INVOKE_H_
27
28      #define unlikely(x)    __builtin_expect(!!(x), 0)
29      #define thread_local _Thread_local
30      #define SCHEDULER_CAPACITY 10
31
32      struct spinlock {
33            volatile int lock;
34      };
35
36      struct simple_thread_list {
37            struct thread * head;
38            struct thread ** tail;
39      };
40
41      // struct simple_lock {
42      //        struct simple_thread_list blocked;
43      // };
44
45      struct signal_once {
46            volatile bool condition;
47            struct spinlock lock;
48            struct simple_thread_list blocked;
49      };
50
51      #ifdef __CFORALL__
52      extern "Cforall" {
53            void ?{}( struct simple_thread_list * );
54            void append( struct simple_thread_list *, struct thread * );
55            struct thread * pop_head( struct simple_thread_list * );
56
57            // void ?{}(simple_lock * this);
58            // void ^?{}(simple_lock * this);
59
60            void ?{}(spinlock * this);
61            void ^?{}(spinlock * this);
62
63            void ?{}(signal_once * this);
64            void ^?{}(signal_once * this);
65      }
66      #endif
67
68      struct coStack_t {
69            unsigned int size;          // size of stack
70            void *storage;                      // pointer to stack
71            void *limit;                        // stack grows towards stack limit
72            void *base;                         // base of stack
73            void *context;                      // address of cfa_context_t
74            void *top;                          // address of top of storage
75            bool userStack;     
76      };
77
78      enum coroutine_state { Start, Inactive, Active, Halt, Primed };
79
80      struct coroutine {
81            struct coStack_t stack;
82            const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code
83            int errno_;                         // copy of global UNIX variable errno
84            enum coroutine_state state; // current execution status for coroutine
85            bool notHalted;                   // indicate if execuation state is not halted
86            struct coroutine *starter;  // first coroutine to resume this one
87            struct coroutine *last;             // last coroutine to resume this one
88      };
89
90      struct thread {
91            struct coroutine c;
92            signal_once terminated;             // indicate if execuation state is not halted
93            struct thread * next;
94      };
95
96#endif //_INVOKE_H_
97#else //! defined(__CFA_INVOKE_PRIVATE__)
98#ifndef _INVOKE_PRIVATE_H_
99#define _INVOKE_PRIVATE_H_
100     
101      struct machine_context_t {
102            void *SP;
103            void *FP;
104            void *PC;
105      };
106
107      // assembler routines that performs the context switch
108      extern void CtxInvokeStub( void );
109      void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
110      void CtxGet( void * this ) asm ("CtxGet");
111
112#endif //_INVOKE_PRIVATE_H_
113#endif //! defined(__CFA_INVOKE_PRIVATE__)
114#ifdef __CFORALL__
115}
116#endif
Note: See TracBrowser for help on using the repository browser.