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

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

Converted CtxGet? from asm function to asm statement for more robustness, should fix full build

  • Property mode set to 100644
File size: 4.9 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
[db6f06a]31      struct spinlock {
32            volatile int lock;
33      };
34
[5ea06d6]35      struct __thread_queue_t {
[348006f]36            struct thread_desc * head;
37            struct thread_desc ** tail;
[bd98b58]38      };
39
[0c78741]40      struct __condition_stack_t {
41            struct __condition_criterion_t * top;
[690f13c]42      };
43
[bd98b58]44      #ifdef __CFORALL__
45      extern "Cforall" {
[5ea06d6]46            void ?{}( struct __thread_queue_t * );
47            void append( struct __thread_queue_t *, struct thread_desc * );
48            struct thread_desc * pop_head( struct __thread_queue_t * );
[db6f06a]49
[0c78741]50            void ?{}( struct __condition_stack_t * );
51            void push( struct __condition_stack_t *, struct __condition_criterion_t * );
52            struct __condition_criterion_t * pop( struct __condition_stack_t * );
[690f13c]53
[db6f06a]54            void ?{}(spinlock * this);
55            void ^?{}(spinlock * this);
[bd98b58]56      }
57      #endif
[596f987b]58
59      struct coStack_t {
[5ea06d6]60            unsigned int size;                        // size of stack
61            void *storage;                            // pointer to stack
62            void *limit;                              // stack grows towards stack limit
63            void *base;                               // base of stack
64            void *context;                            // address of cfa_context_t
65            void *top;                                // address of top of storage
66            bool userStack;                           // whether or not the user allocated the stack
[5c81105]67      };
[78b3f52]68
[ee897e4b]69      enum coroutine_state { Halted, Start, Inactive, Active, Primed };
[78b3f52]70
[c3acb841]71      struct coroutine_desc {
[5ea06d6]72            struct coStack_t stack;                   // stack information of the coroutine
73            const char *name;                         // textual name for coroutine/task, initialized by uC++ generated code
74            int errno_;                               // copy of global UNIX variable errno
75            enum coroutine_state state;               // current execution status for coroutine
76            struct coroutine_desc *starter;           // first coroutine to resume this one
77            struct coroutine_desc *last;                    // last coroutine to resume this one
[5c81105]78      };
[78b3f52]79
[cb0e6de]80      struct monitor_desc {
[5ea06d6]81            struct spinlock lock;                     // spinlock to protect internal data
82            struct thread_desc * owner;               // current owner of the monitor
83            struct __thread_queue_t entry_queue;      // queue of threads that are blocked waiting for the monitor
[0c78741]84            struct __condition_stack_t signal_stack;  // stack of conditions to run next once we exit the monitor
[5ea06d6]85            struct monitor_desc * stack_owner;        // if bulk acquiring was used we need to synchronize signals with an other monitor
86            unsigned int recursion;                   // monitor routines can be called recursively, we need to keep track of that
[cb0e6de]87      };
88
[348006f]89      struct thread_desc {
[5ea06d6]90            struct coroutine_desc cor;                // coroutine body used to store context
91            struct monitor_desc mon;                  // monitor body used for mutual exclusion
92            struct thread_desc * next;                // instrusive link field for threads
93            struct monitor_desc ** current_monitors;  // currently held monitors
94            unsigned short current_monitor_count;     // number of currently held monitors
[8118303]95      };
96
[5c81105]97#endif //_INVOKE_H_
98#else //! defined(__CFA_INVOKE_PRIVATE__)
99#ifndef _INVOKE_PRIVATE_H_
100#define _INVOKE_PRIVATE_H_
[f32e53e]101
[596f987b]102      struct machine_context_t {
[5c81105]103            void *SP;
104            void *FP;
105            void *PC;
106      };
[78b3f52]107
[5c81105]108      // assembler routines that performs the context switch
[b58a5772]109      extern void CtxInvokeStub( void );
[eb2e723]110      void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
[f32e53e]111
112      #if   defined( __x86_64__ )
113      #define CtxGet( ctx ) __asm__ ( \
114                  "movq %%rsp,%0\n"   \
115                  "movq %%rbp,%1\n"   \
116            : "=rm" (ctx.SP), "=rm" (ctx.FP) )
117      #elif defined( __i386__ )
118      #define CtxGet( ctx ) __asm__ ( \
119                  "movl %%esp,%0\n"   \
120                  "movl %%ebp,%1\n"   \
121            : "=rm" (ctx.SP), "=rm" (ctx.FP) )
122      #endif
[78b3f52]123
[5c81105]124#endif //_INVOKE_PRIVATE_H_
125#endif //! defined(__CFA_INVOKE_PRIVATE__)
126#ifdef __CFORALL__
127}
128#endif
Note: See TracBrowser for help on using the repository browser.