Changeset 4c925cd for libcfa/src


Ignore:
Timestamp:
Aug 14, 2020, 11:40:04 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5715d43, fa5e0112
Parents:
309d814 (diff), badd22f (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    r309d814 r4c925cd  
    4444
    4545headers = common.hfa fstream.hfa heap.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa \
    46                 time.hfa stdlib.hfa memory.hfa parseargs.hfa \
     46                time.hfa stdlib.hfa parseargs.hfa \
    4747                containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa
    4848
  • libcfa/src/concurrency/invoke.h

    r309d814 r4c925cd  
    2626#ifndef _INVOKE_H_
    2727#define _INVOKE_H_
     28
     29        struct __cfaehm_try_resume_node;
     30        struct __cfaehm_base_exception_t;
     31        struct exception_context_t {
     32                struct __cfaehm_try_resume_node * top_resume;
     33                struct __cfaehm_base_exception_t * current_exception;
     34        };
    2835
    2936        struct __stack_context_t {
     
    5158                // base of stack
    5259                void * base;
     60
     61                // Information for exception handling.
     62                struct exception_context_t exception_context;
    5363        };
    5464
     
    8494        };
    8595
    86         static inline struct __stack_t * __get_stack( struct $coroutine * cor ) { return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2)); }
     96        static inline struct __stack_t * __get_stack( struct $coroutine * cor ) {
     97                return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2));
     98        }
    8799
    88100        // struct which calls the monitor is accepting
  • libcfa/src/concurrency/kernel/startup.cfa

    r309d814 r4c925cd  
    516516        ( this.terminated ){ 0 };
    517517        ( this.runner ){};
    518         init( this, name, _cltr );
     518
     519        disable_interrupts();
     520                init( this, name, _cltr );
     521        enable_interrupts( __cfaabi_dbg_ctx );
    519522
    520523        __cfadbg_print_safe(runtime_core, "Kernel : Starting core %p\n", &this);
     
    540543        free( this.stack );
    541544
    542         deinit( this );
     545        disable_interrupts();
     546                deinit( this );
     547        enable_interrupts( __cfaabi_dbg_ctx );
    543548}
    544549
  • libcfa/src/concurrency/ready_queue.cfa

    r309d814 r4c925cd  
    150150//  queues or removing them.
    151151uint_fast32_t ready_mutate_lock( void ) with(*__scheduler_lock) {
     152        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     153
    152154        // Step 1 : lock global lock
    153155        // It is needed to avoid processors that register mid Critical-Section
     
    164166        }
    165167
     168        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    166169        return s;
    167170}
    168171
    169172void ready_mutate_unlock( uint_fast32_t last_s ) with(*__scheduler_lock) {
     173        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     174
    170175        // Step 1 : release local locks
    171176        // This must be done while the global lock is held to avoid
     
    182187        /*paranoid*/ assert(true == lock);
    183188        __atomic_store_n(&lock, (bool)false, __ATOMIC_RELEASE);
     189
     190        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    184191}
    185192
     
    419426        // Actually pop the list
    420427        struct $thread * thrd;
    421         bool emptied;
    422         [thrd, emptied] = pop(lane);
     428        thrd = pop(lane);
    423429
    424430        /* paranoid */ verify(thrd);
     
    457463                        if(head(lane)->link.next == thrd) {
    458464                                $thread * pthrd;
    459                                 bool emptied;
    460                                 [pthrd, emptied] = pop(lane);
     465                                pthrd = pop(lane);
    461466
    462467                                /* paranoid */ verify( pthrd == thrd );
     
    608613                        while(!is_empty(lanes.data[idx])) {
    609614                                struct $thread * thrd;
    610                                 __attribute__((unused)) bool _;
    611                                 [thrd, _] = pop(lanes.data[idx]);
     615                                thrd = pop(lanes.data[idx]);
    612616
    613617                                push(cltr, thrd);
  • libcfa/src/concurrency/ready_subqueue.hfa

    r309d814 r4c925cd  
    144144// returns popped
    145145// returns true of lane was empty before push, false otherwise
    146 [$thread *, bool] pop(__intrusive_lane_t & this) {
     146$thread * pop(__intrusive_lane_t & this) {
    147147        /* paranoid */ verify(this.lock);
    148148        /* paranoid */ verify(this.before.link.ts != 0ul);
     
    162162        head->link.next = next;
    163163        next->link.prev = head;
    164         node->link.[next, prev] = 0p;
     164        node->link.next = 0p;
     165        node->link.prev = 0p;
    165166
    166167        // Update head time stamp
     
    180181                /* paranoid */ verify(tail(this)->link.prev == head(this));
    181182                /* paranoid */ verify(head(this)->link.next == tail(this));
    182                 return [node, true];
     183                return node;
    183184        }
    184185        else {
     
    187188                /* paranoid */ verify(head(this)->link.next != tail(this));
    188189                /* paranoid */ verify(this.before.link.ts != 0);
    189                 return [node, false];
     190                return node;
    190191        }
    191192}
  • libcfa/src/exception.c

    r309d814 r4c925cd  
    1010// Created On       : Mon Jun 26 15:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May 21 12:18:00 2020
    13 // Update Count     : 20
     12// Last Modified On : Wed Aug 12 13:55:00 2020
     13// Update Count     : 21
    1414//
    1515
     
    2828#include <unwind.h>
    2929#include <bits/debug.hfa>
     30#include "concurrency/invoke.h"
    3031#include "stdhdr/assert.h"
    3132
     
    5960
    6061// Temperary global exception context. Does not work with concurency.
    61 struct exception_context_t {
    62         struct __cfaehm_try_resume_node * top_resume;
    63 
    64         exception_t * current_exception;
    65         int current_handler_index;
    66 } static shared_stack = {NULL, NULL, 0};
     62static struct exception_context_t shared_stack = {NULL, NULL};
    6763
    6864// Get the current exception context.
     
    122118
    123119// MEMORY MANAGEMENT =========================================================
     120
     121struct __cfaehm_node {
     122        struct _Unwind_Exception unwind_exception;
     123        struct __cfaehm_node * next;
     124        int handler_index;
     125};
     126
     127#define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
     128#define EXCEPT_TO_NODE(except) ((struct __cfaehm_node *)(except) - 1)
     129#define UNWIND_TO_NODE(unwind) ((struct __cfaehm_node *)(unwind))
     130#define NULL_MAP(map, ptr) ((ptr) ? (map(ptr)) : NULL)
    124131
    125132// How to clean up an exception in various situations.
     
    137144}
    138145
    139 // We need a piece of storage to raise the exception, for now its a single
    140 // piece.
    141 static struct _Unwind_Exception this_exception_storage;
    142 
    143 struct __cfaehm_node {
    144         struct __cfaehm_node * next;
    145 };
    146 
    147 #define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
    148 #define EXCEPT_TO_NODE(except) ((struct __cfaehm_node *)(except) - 1)
    149 
    150146// Creates a copy of the indicated exception and sets current_exception to it.
    151147static void __cfaehm_allocate_exception( exception_t * except ) {
     
    161157        }
    162158
     159        // Initialize the node:
     160        exception_t * except_store = NODE_TO_EXCEPT(store);
     161        store->unwind_exception.exception_class = __cfaehm_exception_class;
     162        store->unwind_exception.exception_cleanup = __cfaehm_exception_cleanup;
     163        store->handler_index = 0;
     164        except->virtual_table->copy( except_store, except );
     165
    163166        // Add the node to the list:
    164         store->next = EXCEPT_TO_NODE(context->current_exception);
    165         context->current_exception = NODE_TO_EXCEPT(store);
    166 
    167         // Copy the exception to storage.
    168         except->virtual_table->copy( context->current_exception, except );
    169 
    170         // Set up the exception storage.
    171         this_exception_storage.exception_class = __cfaehm_exception_class;
    172         this_exception_storage.exception_cleanup = __cfaehm_exception_cleanup;
     167        store->next = NULL_MAP(EXCEPT_TO_NODE, context->current_exception);
     168        context->current_exception = except_store;
    173169}
    174170
     
    185181        if ( context->current_exception == except ) {
    186182                node = to_free->next;
    187                 context->current_exception = (node) ? NODE_TO_EXCEPT(node) : 0;
     183                context->current_exception = NULL_MAP(NODE_TO_EXCEPT, node);
    188184        } else {
    189185                node = EXCEPT_TO_NODE(context->current_exception);
     
    213209        // Verify actions follow the rules we expect.
    214210        verify((actions & _UA_CLEANUP_PHASE) && (actions & _UA_FORCE_UNWIND));
    215         verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDER_FRAME)));
     211        verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDLER_FRAME)));
    216212
    217213        if ( actions & _UA_END_OF_STACK ) {
     
    222218}
    223219
     220static struct _Unwind_Exception cancel_exception_storage;
     221
    224222// Cancel the current stack, prefroming approprate clean-up and messaging.
    225223void __cfaehm_cancel_stack( exception_t * exception ) {
    226224        // TODO: Detect current stack and pick a particular stop-function.
    227225        _Unwind_Reason_Code ret;
    228         ret = _Unwind_ForcedUnwind( &this_exception_storage, _Stop_Fn, (void*)0x22 );
     226        ret = _Unwind_ForcedUnwind( &cancel_exception_storage, _Stop_Fn, (void*)0x22 );
    229227        printf("UNWIND ERROR %d after force unwind\n", ret);
    230228        abort();
     
    247245static void __cfaehm_begin_unwind(void(*defaultHandler)(exception_t *)) {
    248246        struct exception_context_t * context = this_exception_context();
    249         struct _Unwind_Exception * storage = &this_exception_storage;
    250247        if ( NULL == context->current_exception ) {
    251248                printf("UNWIND ERROR missing exception in begin unwind\n");
    252249                abort();
    253250        }
     251        struct _Unwind_Exception * storage =
     252                &EXCEPT_TO_NODE(context->current_exception)->unwind_exception;
    254253
    255254        // Call stdlibc to raise the exception
     
    419418                                _Unwind_Reason_Code ret = (0 == index)
    420419                                        ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
    421                                 context->current_handler_index = index;
     420                                UNWIND_TO_NODE(unwind_exception)->handler_index = index;
    422421
    423422                                // Based on the return value, check if we matched the exception
     
    425424                                        __cfadbg_print_safe(exception, " handler found\n");
    426425                                } else {
     426                                        // TODO: Continue the search if there is more in the table.
    427427                                        __cfadbg_print_safe(exception, " no handler\n");
    428428                                }
     
    516516        // Exception handler
    517517        // Note: Saving the exception context on the stack breaks termination exceptions.
    518         catch_block( this_exception_context()->current_handler_index,
     518        catch_block( EXCEPT_TO_NODE( this_exception_context()->current_exception )->handler_index,
    519519                     this_exception_context()->current_exception );
    520520}
  • libcfa/src/iostream.cfa

    r309d814 r4c925cd  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 10 09:32:14 2020
    13 // Update Count     : 1126
     12// Last Modified On : Tue Aug 11 22:16:33 2020
     13// Update Count     : 1128
    1414//
    1515
     
    3737
    3838forall( dtype ostype | ostream( ostype ) ) {
    39         ostype & ?|?( ostype & os, zero_t ) {
    40                 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    41                 fmt( os, "%d", 0n );
    42                 return os;
    43         } // ?|?
    44         void ?|?( ostype & os, zero_t z ) {
    45                 (ostype &)(os | z); ends( os );
    46         } // ?|?
    47 
    48         ostype & ?|?( ostype & os, one_t ) {
    49                 if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    50                 fmt( os, "%d", 1n );
    51                 return os;
    52         } // ?|?
    53         void ?|?( ostype & os, one_t o ) {
    54                 (ostype &)(os | o); ends( os );
    55         } // ?|?
    56 
    5739        ostype & ?|?( ostype & os, bool b ) {
    5840                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
  • libcfa/src/iostream.hfa

    r309d814 r4c925cd  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 16 07:43:32 2020
    13 // Update Count     : 348
     12// Last Modified On : Tue Aug 11 22:16:14 2020
     13// Update Count     : 350
    1414//
    1515
     
    6767
    6868forall( dtype ostype | ostream( ostype ) ) {
    69         ostype & ?|?( ostype &, zero_t );
    70         void ?|?( ostype &, zero_t );
    71         ostype & ?|?( ostype &, one_t );
    72         void ?|?( ostype &, one_t );
    73 
    7469        ostype & ?|?( ostype &, bool );
    7570        void ?|?( ostype &, bool );
  • libcfa/src/stdlib.hfa

    r309d814 r4c925cd  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 30 16:14:58 2020
    13 // Update Count     : 490
     12// Last Modified On : Tue Aug 11 21:11:46 2020
     13// Update Count     : 495
    1414//
    1515
     
    136136        T * alloc_set( char fill ) {
    137137                return (T *)memset( (T *)alloc(), (int)fill, sizeof(T) ); // initialize with fill value
    138         } // alloc
    139 
    140         T * alloc_set( T fill ) {
     138        } // alloc_set
     139
     140        T * alloc_set( const T & fill ) {
    141141                return (T *)memcpy( (T *)alloc(), &fill, sizeof(T) ); // initialize with fill value
    142         } // alloc
     142        } // alloc_set
    143143
    144144        T * alloc_set( size_t dim, char fill ) {
    145145                return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value
    146         } // alloc
    147 
    148         T * alloc_set( size_t dim, T fill ) {
     146        } // alloc_set
     147
     148        T * alloc_set( size_t dim, const T & fill ) {
    149149                T * r = (T *)alloc( dim );
    150150                for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value
    151151                return r;
    152         } // alloc
     152        } // alloc_set
    153153
    154154        T * alloc_set( size_t dim, const T fill[] ) {
    155155                return (T *)memcpy( (T *)alloc( dim ), fill, dim * sizeof(T) ); // initialize with fill value
    156         } // alloc
     156        } // alloc_set
    157157
    158158        T * alloc_set( T ptr[], size_t dim, char fill ) {       // realloc array with fill
     
    166166        } // alloc_set
    167167
    168         T * alloc_set( T ptr[], size_t dim, T & fill ) {        // realloc array with fill
     168        T * alloc_set( T ptr[], size_t dim, const T & fill ) {  // realloc array with fill
    169169                size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
    170170                size_t nsize = dim * sizeof(T);                                 // new allocation
     
    177177                } // if
    178178                return nptr;
    179         } // alloc_align_set
     179        } // alloc_set
    180180} // distribution
    181181
     
    204204        T * alloc_align_set( size_t align, char fill ) {
    205205                return (T *)memset( (T *)alloc_align( align ), (int)fill, sizeof(T) ); // initialize with fill value
    206         } // alloc_align
    207 
    208         T * alloc_align_set( size_t align, T fill ) {
     206        } // alloc_align_set
     207
     208        T * alloc_align_set( size_t align, const T & fill ) {
    209209                return (T *)memcpy( (T *)alloc_align( align ), &fill, sizeof(T) ); // initialize with fill value
    210         } // alloc_align
     210        } // alloc_align_set
    211211
    212212        T * alloc_align_set( size_t align, size_t dim, char fill ) {
    213213                return (T *)memset( (T *)alloc_align( align, dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value
    214         } // alloc_align
    215 
    216         T * alloc_align_set( size_t align, size_t dim, T fill ) {
     214        } // alloc_align_set
     215
     216        T * alloc_align_set( size_t align, size_t dim, const T & fill ) {
    217217                T * r = (T *)alloc_align( align, dim );
    218218                for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value
    219219                return r;
    220         } // alloc_align
     220        } // alloc_align_set
    221221
    222222        T * alloc_align_set( size_t align, size_t dim, const T fill[] ) {
    223223                return (T *)memcpy( (T *)alloc_align( align, dim ), fill, dim * sizeof(T) );
    224         } // alloc_align
     224        } // alloc_align_set
    225225
    226226        T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ) {
     
    234234        } // alloc_align_set
    235235
    236         T * alloc_align_set( T ptr[], size_t align, size_t dim, T & fill ) {
     236        T * alloc_align_set( T ptr[], size_t align, size_t dim, const T & fill ) {
    237237                size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
    238238                size_t nsize = dim * sizeof(T);                                 // new allocation
Note: See TracChangeset for help on using the changeset viewer.