source: src/libcfa/concurrency/invoke.h @ 17af7d1

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

Some clean-up of runtime code

  • Property mode set to 100644
File size: 3.5 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
31      struct spinlock {
32            volatile int lock;
33      };
34
35      struct simple_thread_list {
36            struct thread_desc * head;
37            struct thread_desc ** tail;
38      };
39
40      struct signal_once {
41            volatile bool condition;
42            struct spinlock lock;
43            struct simple_thread_list blocked;
44      };
45
46      #ifdef __CFORALL__
47      extern "Cforall" {
48            void ?{}( struct simple_thread_list * );
49            void append( struct simple_thread_list *, struct thread_desc * );
50            struct thread_desc * pop_head( struct simple_thread_list * );
51
52            void ?{}(spinlock * this);
53            void ^?{}(spinlock * this);
54
55            void ?{}(signal_once * this);
56            void ^?{}(signal_once * this);
57      }
58      #endif
59
60      struct coStack_t {
61            unsigned int size;                  // size of stack
62            void *storage;                      // pointer to stack
63            void *limit;                        // stack grows towards stack limit
64            void *base;                         // base of stack
65            void *context;                      // address of cfa_context_t
66            void *top;                          // address of top of storage
67            bool userStack;                     // whether or not the user allocated the stack
68      };
69
70      enum coroutine_state { Halted, Start, Inactive, Active, Primed };
71
72      struct coroutine_desc {
73            struct coStack_t stack;             // stack information of the coroutine
74            const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code
75            int errno_;                         // copy of global UNIX variable errno
76            enum coroutine_state state;         // current execution status for coroutine
77            struct coroutine_desc *starter;     // first coroutine to resume this one
78            struct coroutine_desc *last;              // last coroutine to resume this one
79      };
80
81      struct thread_desc {
82            struct coroutine_desc cor;            // coroutine body used to store context
83            struct signal_once terminated;      // indicate if execuation state is not halted
84            struct thread_desc * next;          // instrusive link field for threads
85      };
86
87#endif //_INVOKE_H_
88#else //! defined(__CFA_INVOKE_PRIVATE__)
89#ifndef _INVOKE_PRIVATE_H_
90#define _INVOKE_PRIVATE_H_
91     
92      struct machine_context_t {
93            void *SP;
94            void *FP;
95            void *PC;
96      };
97
98      // assembler routines that performs the context switch
99      extern void CtxInvokeStub( void );
100      void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
101      void CtxGet( void * this ) asm ("CtxGet");
102
103#endif //_INVOKE_PRIVATE_H_
104#endif //! defined(__CFA_INVOKE_PRIVATE__)
105#ifdef __CFORALL__
106}
107#endif
Note: See TracBrowser for help on using the repository browser.