source: src/libcfa/concurrency/invoke.h @ 75a17f1

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 75a17f1 was cc7f4b1, checked in by Thierry Delisle <tdelisle@…>, 7 years ago
  • renamed monitor to monitor_t since the type should not be exposed to users
  • added support for recursion in monitors
  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[0157ca7]1//                              -*- Mode: C -*-
[8def349]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
[5c81105]17#include <stdbool.h>
18#include <stdint.h>
[78b3f52]19
[5c81105]20#ifdef __CFORALL__
21extern "C" {
22#endif
23
24#if ! defined(__CFA_INVOKE_PRIVATE__)
[78b3f52]25#ifndef _INVOKE_H_
26#define _INVOKE_H_
27
[596f987b]28      #define unlikely(x)    __builtin_expect(!!(x), 0)
[8def349]29      #define thread_local _Thread_local
[bd98b58]30      #define SCHEDULER_CAPACITY 10
31
[db6f06a]32      struct spinlock {
33            volatile int lock;
34      };
35
[bd98b58]36      struct simple_thread_list {
[e15df4c]37            struct thread * head;
38            struct thread ** tail;
[bd98b58]39      };
40
[db6f06a]41      struct signal_once {
42            volatile bool condition;
43            struct spinlock lock;
44            struct simple_thread_list blocked;
45      };
46
[bd98b58]47      #ifdef __CFORALL__
48      extern "Cforall" {
49            void ?{}( struct simple_thread_list * );
[e15df4c]50            void append( struct simple_thread_list *, struct thread * );
51            struct thread * pop_head( struct simple_thread_list * );
[db6f06a]52
53            void ?{}(spinlock * this);
54            void ^?{}(spinlock * this);
55
56            void ?{}(signal_once * this);
57            void ^?{}(signal_once * this);
[bd98b58]58      }
59      #endif
[596f987b]60
61      struct coStack_t {
[cc7f4b1]62            unsigned int size;                // size of stack
63            void *storage;                            // pointer to stack
64            void *limit;                              // stack grows towards stack limit
65            void *base;                               // base of stack
66            void *context;                            // address of cfa_context_t
67            void *top;                                // address of top of storage
[5c81105]68            bool userStack;     
69      };
[78b3f52]70
[ee897e4b]71      enum coroutine_state { Halted, Start, Inactive, Active, Primed };
[78b3f52]72
[5c81105]73      struct coroutine {
74            struct coStack_t stack;
[cc7f4b1]75            const char *name;                         // textual name for coroutine/task, initialized by uC++ generated code
76            int errno_;                               // copy of global UNIX variable errno
77            enum coroutine_state state;       // current execution status for coroutine
78            struct coroutine *starter;        // first coroutine to resume this one
79            struct coroutine *last;                   // last coroutine to resume this one
[5c81105]80      };
[78b3f52]81
[e15df4c]82      struct thread {
[cc7f4b1]83            struct coroutine c;                 // coroutine body used to store context
84            struct signal_once terminated;      // indicate if execuation state is not halted
85            struct thread * next;               // instrusive link field for threads
[8118303]86      };
87
[5c81105]88#endif //_INVOKE_H_
89#else //! defined(__CFA_INVOKE_PRIVATE__)
90#ifndef _INVOKE_PRIVATE_H_
91#define _INVOKE_PRIVATE_H_
92     
[596f987b]93      struct machine_context_t {
[5c81105]94            void *SP;
95            void *FP;
96            void *PC;
97      };
[78b3f52]98
[5c81105]99      // assembler routines that performs the context switch
[b58a5772]100      extern void CtxInvokeStub( void );
[eb2e723]101      void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
102      void CtxGet( void * this ) asm ("CtxGet");
[78b3f52]103
[5c81105]104#endif //_INVOKE_PRIVATE_H_
105#endif //! defined(__CFA_INVOKE_PRIVATE__)
106#ifdef __CFORALL__
107}
108#endif
Note: See TracBrowser for help on using the repository browser.