Changeset 87d13cd for src/libcfa


Ignore:
Timestamp:
Mar 21, 2017, 10:07:52 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
cb91437
Parents:
829c907 (diff), a53e10a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

fix conflicit in iostream.c

Location:
src/libcfa
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/coroutine

    r829c907 r87d13cd  
    3030};
    3131
    32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->c; } void main(X* this)
     32#define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->__cor; } void main(X* this)
    3333
    3434//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/invoke.c

    r829c907 r87d13cd  
    2929
    3030extern void __suspend_internal(void);
    31 extern void __thread_signal_termination(struct thread_desc*);
     31extern void __leave_monitor_desc( struct monitor_desc * this );
    3232
    3333void CtxInvokeCoroutine(
     
    5656
    5757void CtxInvokeThread(
     58      void (*dtor)(void *),
    5859      void (*main)(void *),
    5960      struct thread_desc *(*get_thread)(void *),
     
    6364
    6465      struct thread_desc* thrd = get_thread( this );
    65       struct coroutine_desc* cor = &thrd->c;
     66      struct coroutine_desc* cor = &thrd->cor;
     67      struct monitor_desc* mon = &thrd->mon;
    6668      cor->state = Active;
    6769
     
    6971      main( this );
    7072
    71       __thread_signal_termination(thrd);
     73      __leave_monitor_desc( mon );
    7274
    7375      //Final suspend, should never return
     
    9193        struct FakeStack {
    9294            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
    93             uint32_t mxcr;                              // SSE Status and Control bits (control bits are preserved across function calls)
    94             uint16_t fcw;                               // X97 FPU control word (preserved across function calls)
    95             void *rturn;                                // where to go on return from uSwitch
     95            uint32_t mxcr;                        // SSE Status and Control bits (control bits are preserved across function calls)
     96          uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
     97            void *rturn;                          // where to go on return from uSwitch
    9698            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
    9799            void *argument[3];                          // for 16-byte ABI, 16-byte alignment starts here
     
    105107        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this;     // argument to invoke
    106108        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
     109      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
     110      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    107111
    108112#elif defined( __x86_64__ )
    109113
    110114      struct FakeStack {
    111             void *fixedRegisters[5];                    // fixed registers rbx, r12, r13, r14, r15
    112             uint32_t mxcr;                              // SSE Status and Control bits (control bits are preserved across function calls)
    113             uint16_t fcw;                               // X97 FPU control word (preserved across function calls)
    114             void *rturn;                                // where to go on return from uSwitch
    115             void *dummyReturn;                          // NULL return address to provide proper alignment
     115            void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
     116            uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
     117            uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
     118            void *rturn;                        // where to go on return from uSwitch
     119            void *dummyReturn;                  // NULL return address to provide proper alignment
    116120      };
    117121
  • src/libcfa/concurrency/invoke.h

    r829c907 r87d13cd  
    2828      #define unlikely(x)    __builtin_expect(!!(x), 0)
    2929      #define thread_local _Thread_local
    30       #define SCHEDULER_CAPACITY 10
    3130
    3231      struct spinlock {
     
    3938      };
    4039
    41       struct signal_once {
    42             volatile bool condition;
    43             struct spinlock lock;
    44             struct simple_thread_list blocked;
    45       };
    46 
    4740      #ifdef __CFORALL__
    4841      extern "Cforall" {
     
    5346            void ?{}(spinlock * this);
    5447            void ^?{}(spinlock * this);
    55 
    56             void ?{}(signal_once * this);
    57             void ^?{}(signal_once * this);
    5848      }
    5949      #endif
    6050
    6151      struct coStack_t {
    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
    68             bool userStack;     
     52            unsigned int size;                  // size of stack
     53            void *storage;                      // pointer to stack
     54            void *limit;                        // stack grows towards stack limit
     55            void *base;                         // base of stack
     56            void *context;                      // address of cfa_context_t
     57            void *top;                          // address of top of storage
     58            bool userStack;                     // whether or not the user allocated the stack
    6959      };
    7060
     
    7262
    7363      struct coroutine_desc {
    74             struct coStack_t stack;
    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_desc *starter;           // first coroutine to resume this one
    79             struct coroutine_desc *last;                      // last coroutine to resume this one
     64            struct coStack_t stack;             // stack information of the coroutine
     65            const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code
     66            int errno_;                         // copy of global UNIX variable errno
     67            enum coroutine_state state;         // current execution status for coroutine
     68            struct coroutine_desc *starter;     // first coroutine to resume this one
     69            struct coroutine_desc *last;              // last coroutine to resume this one
     70      };
     71
     72      struct monitor_desc {
     73            struct spinlock lock;
     74            struct thread_desc * owner;
     75            struct simple_thread_list entry_queue;
     76            unsigned int recursion;
    8077      };
    8178
    8279      struct thread_desc {
    83             struct coroutine_desc c;                 // coroutine body used to store context
    84             struct signal_once terminated;      // indicate if execuation state is not halted
    85             struct thread_desc * next;               // instrusive link field for threads
     80            struct coroutine_desc cor;          // coroutine body used to store context
     81            struct monitor_desc mon;            // monitor body used for mutual exclusion
     82            struct thread_desc * next;          // instrusive link field for threads
    8683      };
    8784
  • src/libcfa/concurrency/kernel

    r829c907 r87d13cd  
    3030void lock( spinlock * );
    3131void unlock( spinlock * );
     32
     33struct signal_once {
     34        volatile bool condition;
     35        struct spinlock lock;
     36        struct simple_thread_list blocked;
     37};
     38
     39void ?{}(signal_once * this);
     40void ^?{}(signal_once * this);
    3241
    3342void wait( signal_once * );
  • src/libcfa/concurrency/kernel.c

    r829c907 r87d13cd  
    107107
    108108void ?{}( thread_desc * this, current_stack_info_t * info) {
    109         (&this->c){ info };
     109        (&this->cor){ info };
    110110}
    111111
     
    113113// Processor coroutine
    114114void ?{}(processorCtx_t * this, processor * proc) {
    115         (&this->c){};
     115        (&this->__cor){};
    116116        this->proc = proc;
    117117        proc->runner = this;
     
    119119
    120120void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) {
    121         (&this->c){ info };
     121        (&this->__cor){ info };
    122122        this->proc = proc;
    123123        proc->runner = this;
     
    255255        processorCtx_t proc_cor_storage = { proc, &info };
    256256
    257         LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.c.stack.base);
     257        LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
    258258
    259259        //Set global state
    260         proc->current_coroutine = &proc->runner->c;
     260        proc->current_coroutine = &proc->runner->__cor;
    261261        proc->current_thread = NULL;
    262262
     
    268268        // back to here. Instead directly call the main since we already are on the
    269269        // appropriate stack.
    270         proc_cor_storage.c.state = Active;
     270        proc_cor_storage.__cor.state = Active;
    271271      main( &proc_cor_storage );
    272       proc_cor_storage.c.state = Halted;
     272      proc_cor_storage.__cor.state = Halted;
    273273
    274274        // Main routine of the core returned, the core is now fully terminated
     
    359359        this_processor = systemProcessor;
    360360        this_processor->current_thread = mainThread;
    361         this_processor->current_coroutine = &mainThread->c;
     361        this_processor->current_coroutine = &mainThread->cor;
    362362
    363363        // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
  • src/libcfa/concurrency/kernel_private.h

    r829c907 r87d13cd  
    3535struct processorCtx_t {
    3636        processor * proc;
    37         coroutine_desc c;
     37        coroutine_desc __cor;
    3838};
    3939
  • src/libcfa/concurrency/monitor

    r829c907 r87d13cd  
    2222#include "stdlib"
    2323
    24 struct monitor_desc {
    25         spinlock lock;
    26         thread_desc * owner;
    27         simple_thread_list entry_queue;
    28         unsigned int recursion;
    29 };
    30 
    3124static inline void ?{}(monitor_desc * this) {
    3225        this->owner = 0;
    3326        this->recursion = 0;
    3427}
    35 
    36 //Basic entering routine
    37 void enter(monitor_desc *);
    38 void leave(monitor_desc *);
    3928
    4029//Array entering routine
     
    4938static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
    5039        return ((intptr_t)lhs) < ((intptr_t)rhs);
    51 }
    52 
    53 static inline void ?{}( monitor_guard_t * this, monitor_desc ** m ) {
    54         this->m = m;
    55         this->count = 1;
    56         enter( *this->m );
    5740}
    5841
  • src/libcfa/concurrency/monitor.c

    r829c907 r87d13cd  
    1919#include "kernel_private.h"
    2020
    21 void enter(monitor_desc * this) {
    22         lock( &this->lock );
    23         thread_desc * thrd = this_thread();
     21extern "C" {
     22        void __enter_monitor_desc(monitor_desc * this) {
     23                lock( &this->lock );
     24                thread_desc * thrd = this_thread();
    2425
    25         if( !this->owner ) {
    26                 //No one has the monitor, just take it
    27                 this->owner = thrd;
    28                 this->recursion = 1;
    29         }
    30         else if( this->owner == thrd) {
    31                 //We already have the monitor, just not how many times we took it
    32                 assert( this->recursion > 0 );
    33                 this->recursion += 1;
    34         }
    35         else {
    36                 //Some one else has the monitor, wait in line for it
    37                 append( &this->entry_queue, thrd );
    38                 ScheduleInternal( &this->lock );
     26                if( !this->owner ) {
     27                        //No one has the monitor, just take it
     28                        this->owner = thrd;
     29                        this->recursion = 1;
     30                }
     31                else if( this->owner == thrd) {
     32                        //We already have the monitor, just not how many times we took it
     33                        assert( this->recursion > 0 );
     34                        this->recursion += 1;
     35                }
     36                else {
     37                        //Some one else has the monitor, wait in line for it
     38                        append( &this->entry_queue, thrd );
     39                        ScheduleInternal( &this->lock );
    3940
    40                 //ScheduleInternal will unlock spinlock, no need to unlock ourselves
    41                 return;
     41                        //ScheduleInternal will unlock spinlock, no need to unlock ourselves
     42                        return;
     43                }
     44
     45                unlock( &this->lock );
    4246        }
    4347
    44         unlock( &this->lock );
    45 }
     48        void __leave_monitor_desc(monitor_desc * this) {
     49                lock( &this->lock );
    4650
    47 void leave(monitor_desc * this) {
    48         lock( &this->lock );
     51                thread_desc * thrd = this_thread();
     52                assert( thrd == this->owner );
    4953
    50         thread_desc * thrd = this_thread();
    51         assert( thrd == this->owner );
     54                //Leaving a recursion level, decrement the counter
     55                this->recursion -= 1;
    5256
    53         //Leaving a recursion level, decrement the counter
    54         this->recursion -= 1;
     57                //If we left the last level of recursion it means we are changing who owns the monitor
     58                thread_desc * new_owner = 0;
     59                if( this->recursion == 0) {
     60                        //Get the next thread in the list
     61                        new_owner = this->owner = pop_head( &this->entry_queue );
    5562
    56         //If we left the last level of recursion it means we are changing who owns the monitor
    57         thread_desc * new_owner = 0;
    58         if( this->recursion == 0) {
    59                 //Get the next thread in the list
    60                 new_owner = this->owner = pop_head( &this->entry_queue );
     63                        //We are passing the monitor to someone else, which means recursion level is not 0
     64                        this->recursion = new_owner ? 1 : 0;
     65                }       
    6166
    62                 //We are passing the monitor to someone else, which means recursion level is not 0
    63                 this->recursion = new_owner ? 1 : 0;
    64         }       
     67                unlock( &this->lock );
    6568
    66         unlock( &this->lock );
    67 
    68         //If we have a new owner, we need to wake-up the thread
    69         if( new_owner ) {
    70                 ScheduleThread( new_owner );
     69                //If we have a new owner, we need to wake-up the thread
     70                if( new_owner ) {
     71                        ScheduleThread( new_owner );
     72                }
    7173        }
    7274}
     
    7476void enter(monitor_desc ** monitors, int count) {
    7577        for(int i = 0; i < count; i++) {
    76                 // printf("%d\n", i);
    77                 enter( monitors[i] );
     78                __enter_monitor_desc( monitors[i] );
    7879        }
    7980}
     
    8182void leave(monitor_desc ** monitors, int count) {
    8283        for(int i = count - 1; i >= 0; i--) {
    83                 // printf("%d\n", i);
    84                 leave( monitors[i] );
     84                __leave_monitor_desc( monitors[i] );
    8585        }
    8686}
  • src/libcfa/concurrency/thread

    r829c907 r87d13cd  
    2222
    2323#include "coroutine"
     24#include "monitor"
    2425
    2526//-----------------------------------------------------------------------------
     
    2829// Anything that is resumed is a coroutine.
    2930trait is_thread(dtype T) {
     31      void ^?{}(T* mutex this);
    3032      void main(T* this);
    3133      thread_desc* get_thread(T* this);
    3234};
    3335
    34 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->t; } void main(X* this)
     36#define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
    3537
    3638forall( dtype T | is_thread(T) )
    3739static inline coroutine_desc* get_coroutine(T* this) {
    38         return &get_thread(this)->c;
     40        return &get_thread(this)->cor;
    3941}
    4042
    41 static inline coroutine_desc* get_coroutine(thread_desc* this) {
    42         return &this->c;
     43forall( dtype T | is_thread(T) )
     44static inline monitor_desc* get_monitor(T * this) {
     45        return &get_thread(this)->mon;
     46}
     47
     48static inline coroutine_desc* get_coroutine(thread_desc * this) {
     49        return &this->cor;
     50}
     51
     52static inline monitor_desc* get_monitor(thread_desc * this) {
     53        return &this->mon;
    4354}
    4455
     
    6475void ?{}( scoped(T)* this, P params );
    6576
    66 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
     77forall( dtype T | sized(T) | is_thread(T) )
    6778void ^?{}( scoped(T)* this );
    6879
  • src/libcfa/concurrency/thread.c

    r829c907 r87d13cd  
    3535void start( T* this );
    3636
    37 forall( dtype T | is_thread(T) )
    38 void stop( T* this );
    39 
    4037//-----------------------------------------------------------------------------
    4138// Thread ctors and dtors
    4239
    4340void ?{}(thread_desc* this) {
    44         (&this->c){};
    45         this->c.name = "Anonymous Coroutine";
    46         (&this->terminated){};
     41        (&this->cor){};
     42        this->cor.name = "Anonymous Coroutine";
     43        this->mon.owner = this;
     44        this->mon.recursion = 1;
    4745        this->next = NULL;
    4846}
    4947
    5048void ^?{}(thread_desc* this) {
    51         ^(&this->c){};
     49        ^(&this->cor){};
    5250}
    5351
     
    6462}
    6563
    66 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
     64forall( dtype T | sized(T) | is_thread(T) )
    6765void ^?{}( scoped(T)* this ) {
    68         stop(&this->handle);
    6966        ^(&this->handle){};
    7067}
     
    8683
    8784        ScheduleThread(thrd_h);
    88 }
    89 
    90 forall( dtype T | is_thread(T) )
    91 void stop( T* this ) {
    92         wait( & get_thread(this)->terminated );
    9385}
    9486
     
    116108}
    117109
    118 // C Helper to signal the termination of a thread_desc
    119 // Used in invoke.c
    120 extern "C" {
    121         void __thread_signal_termination( thread_desc * this ) {
    122                 this->c.state = Halted;
    123                 LIB_DEBUG_PRINTF("Thread end : %p\n", this);
    124                 signal( &this->terminated );   
    125         }
    126 }
    127 
    128110// Local Variables: //
    129111// mode: c //
  • src/libcfa/iostream.c

    r829c907 r87d13cd  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 21 20:58:48 2017
    13 // Update Count     : 347
     12// Last Modified On : Tue Mar 21 22:05:57 2017
     13// Update Count     : 348
    1414//
    1515
Note: See TracChangeset for help on using the changeset viewer.