Changeset ec35498


Ignore:
Timestamp:
Jun 16, 2017, 9:57:33 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
0b33412
Parents:
4e6fb8e (diff), 42b0d73 (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

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • doc/working/exception/impl/exception.c

    r4e6fb8e rec35498  
    4444        __throw_terminate(except);
    4545        // TODO: Default handler for resumption.
     46}
     47
     48/* QUESTION: Could interupts interact with exception handling?
     49Ex. could an context switch stop execution, and we get an exception when we
     50come back? Is so resumption has to go:
     51+ create node (init next and handler)
     52+ prepare cleanup (add a cleanup hook with the ..._cleaup function)
     53  also the cleanup has to be the next node, not just a pop from the list.
     54+ push node on the list (change the existing node)
     55Which if an exception can come from anywhere, might just be required to ensure
     56the list is valid.
     57
     58void __try_resume_setup(struct __try_resume_node * node,
     59                        bool (*handler)(exception except) {
     60        node->next = shared_stack.top_resume;
     61        node->try_to_handle = handler;
     62        shared_stack.top_resume = node;
     63}*/
     64
     65// We have a single cleanup function
     66void __try_resume_cleanup(struct __try_resume_node * node) {
     67        shared_stack.top_resume = node->next;
    4668}
    4769
  • doc/working/exception/impl/exception.h

    r4e6fb8e rec35498  
    66
    77
    8 // These might be given simpler names and made public.
    98void __throw_terminate(exception except) __attribute__((noreturn));
    109void __rethrow_terminate(void) __attribute__((noreturn));
     
    2019};
    2120
     21void __try_resume_cleanup(struct __try_resume_node * node);
     22
    2223struct __cleanup_hook {};
    2324
     
    2728 * and threads means that... well I'm going to get it working ignoring those
    2829 * first, then get it working with concurrency.
     30 * Eventually there should be some global name that just gets you the right
     31 * data block.
    2932 */
    3033struct shared_stack_t {
    31         //struct lock lock;
    3234        struct __try_resume_node * top_resume;
    3335        struct __try_resume_node * current_resume;
  • doc/working/exception/impl/test-main.c

    r4e6fb8e rec35498  
    66#include <stdbool.h>
    77
    8 // Translation Helpers:
    9 #define CLEANUP(function) \
    10         struct __cleanup_hook __hidden_hook __attribute__((cleanup(function)))
    11 
    12 #define SET_UP_RESUME_NODE(handler_function) \
    13         struct __try_resume_node node \
    14                 __attribute__((cleanup(__try_resume_node_delete))); \
    15         __try_resume_node_new(&node, handler_function)
    16 
     8// Helps with manual translation. It may or may not get folded into the
     9// header, that depends on how it interacts with concurancy.
    1710void __try_resume_node_new(struct __try_resume_node * node,
    1811        _Bool (*handler)(exception except)) {
     
    2013    shared_stack.top_resume = node;
    2114    node->try_to_handle = handler;
    22 }
    23 
    24 void __try_resume_node_delete(struct __try_resume_node * node) {
    25     shared_stack.top_resume = node->next;
    2615}
    2716
     
    122111                }
    123112                struct __try_resume_node node
    124                         __attribute__((cleanup(__try_resume_node_delete)));
     113                        __attribute__((cleanup(__try_resume_cleanup)));
    125114                __try_resume_node_new(&node, beta_handle1);
    126115                {
     
    144133                }
    145134                struct __try_resume_node node
    146                         __attribute__((cleanup(__try_resume_node_delete)));
     135                        __attribute__((cleanup(__try_resume_cleanup)));
    147136                __try_resume_node_new(&node, alpha_handle1);
    148137                {
     
    153142
    154143// Finally Test:
    155 void farewell() {
     144void farewell(bool jump) {
    156145        {
    157146                void farewell_finally1() {
     
    161150                        __attribute__((cleanup(farewell_finally1)));
    162151                {
    163                         printf("walk out of farewell\n");
    164                 }
    165         }
     152                        if (jump) {
     153                                printf("jump out of farewell\n");
     154                                goto endoffunction;
     155                        } else {
     156                                printf("walk out of farewell\n");
     157                        }
     158                }
     159        }
     160        endoffunction:
     161        printf("leaving farewell\n");
    166162}
    167163
     
    260256                }
    261257                struct __try_resume_node node
    262                         __attribute__((cleanup(__try_resume_node_delete)));
     258                        __attribute__((cleanup(__try_resume_cleanup)));
    263259                __try_resume_node_new(&node, fn_handle1);
    264260                {
     
    279275                }
    280276                struct __try_resume_node node
    281                         __attribute__((cleanup(__try_resume_node_delete)));
     277                        __attribute__((cleanup(__try_resume_cleanup)));
    282278                __try_resume_node_new(&node, fn_handle1);
    283279                {
     
    349345                }
    350346                struct __try_resume_node node
    351                         __attribute__((cleanup(__try_resume_node_delete)));
     347                        __attribute__((cleanup(__try_resume_cleanup)));
    352348                __try_resume_node_new(&node, reresume_handle1);
    353349                {
     
    361357                        }
    362358                        struct __try_resume_node node
    363                                 __attribute__((cleanup(__try_resume_node_delete)));
     359                                __attribute__((cleanup(__try_resume_cleanup)));
    364360                        __try_resume_node_new(&node, reresume_handle2);
    365361                        {
     
    409405                }
    410406                struct __try_resume_node node
    411                         __attribute__((cleanup(__try_resume_node_delete)));
     407                        __attribute__((cleanup(__try_resume_cleanup)));
    412408                __try_resume_node_new(&node, foe_handle1);
    413409                {
     
    456452                }
    457453                struct __try_resume_node node
    458                         __attribute__((cleanup(__try_resume_node_delete)));
     454                        __attribute__((cleanup(__try_resume_cleanup)));
    459455                __try_resume_node_new(&node, fee_handle1);
    460456                {
     
    471467        foo(); printf("\n");
    472468        alpha(); printf("\n");
    473         farewell(); printf("\n");
     469        farewell(false); printf("\n");
     470        farewell(true); printf("\n");
    474471        fallback(); printf("\n");
    475472        terminate_swapped(); printf("\n");
  • doc/working/exception/translate.c

    r4e6fb8e rec35498  
    1717
    1818void __throw_terminate(exception except) __attribute__((noreturn));
     19void __rethrow_terminate() __attribute__((noreturn));
    1920void __throw_resume(exception except);
    2021
     
    2728        bool (*try_to_handle)(exception except);
    2829};
     30
     31void __try_resume_cleanup(struct __try_resume_node * node);
    2932
    3033struct __cleanup_hook {};
     
    147150void try_resume() {
    148151        {
    149                 bool catch1(exception except) {
     152                bool handle1(exception except) {
    150153                        OtherException inner_except;
    151154                        if (dynamic_cast__SomeException(except)) {
     
    161164                }
    162165                struct __try_resume_node data =
    163                         {.next = stack.except.top_resume, .try_to_handle = catch1};
     166                        {.next = stack.except.top_resume, .try_to_handle = handle1};
    164167                stack.except.top_resume = &data;
    165168
     
    204207
    205208
    206 // Combining the Above:
     209// Resume + Finally:
     210"Cforall"
     211
     212void try_resume_finally() {
     213        try {
     214                insideTry();
     215        }
     216        catch resume (SomeException) {
     217                fiddleThing();
     218        }
     219        finally {
     220                twiddleWidget();
     221        }
     222}
     223
     224"C"
     225
     226void try_resume_finally() {
     227        {
     228                void finally1() {
     229                        twiddleWidget();
     230                }
     231                bool handle1(exception except) {
     232                        if (dynamic_cast__SomeException(except)) {
     233                                fiddleThing();
     234                                return true;
     235                        } else {
     236                                return false;
     237                        }
     238                }
     239                struct __cleanup_hook generated_name
     240                        __attribute__((cleanup(finally1)));
     241
     242                struct __try_resume_node data =
     243                        {.next = stack.except.top_resume, .try_to_handle = handle1};
     244                stack.except.top_resume = &data;
     245
     246                struct __cleanup_hook generated_name
     247                        __attribute__((cleanup(__try_resume_cleanup)));
     248        }
     249}
     250
     251
     252// Terminate + Resume + Finally:
    207253"Cforall"
    208254
     
    226272void try_all() {
    227273        {
     274                bool handle1() {
     275                        if (dynamic_cast__OtherException(except)) {
     276                                twiddleWidget();
     277                                return true;
     278                        }
     279                        return false;
     280                }
    228281                void try1 () {
     282                        struct __try_resume_node generated_name =
     283                                {.next = stack.except.top_resume, .try_to_handle = handle1}
     284                                __attribute__((cleanup(__try_resume_cleanup)));
     285                        stack.except.top_resume = &data;
     286
    229287                        insideTry();
    230288                }
     
    244302                        return 0;
    245303                }
    246                 bool catch2() {
    247                         if (dynamic_cast__OtherException(except)) {
    248                                 twiddleWidget();
    249                                 return true;
    250                         }
    251                         return false;
    252                 }
    253304                void finally1() {
    254                         // Finally, because of timing, also works for resume.
    255                         // However this might not actually be better in any way.
    256                         __try_resume_cleanup();
    257305
    258306                        twiddleWidget();
    259307                }
    260 
    261                 struct __try_resume_node generated_name =
    262                         {.next = stack.except.top_resume, .try_to_handle = catch2};
    263                 stack.except.top_resume = &data;
    264308                struct __cleanup_hook generated_name
    265309                        __attribute__((cleanup(finally1)));
  • src/libcfa/concurrency/alarm.c

    r4e6fb8e rec35498  
    136136
    137137static inline void remove_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t it ) {
    138         assert( it );
    139         assert( (*it) == n );
     138        verify( it );
     139        verify( (*it) == n );
    140140
    141141        (*it) = n->next;
  • src/libcfa/concurrency/coroutine

    r4e6fb8e rec35498  
    7171// Suspend implementation inlined for performance
    7272static inline void suspend() {
    73       coroutine_desc * src = this_coroutine();          // optimization
     73        coroutine_desc * src = this_coroutine();                // optimization
    7474
    7575        assertf( src->last != 0,
     
    9191        coroutine_desc * dst = get_coroutine(cor);
    9292
    93       if( unlikely(!dst->stack.base) ) {
     93        if( unlikely(!dst->stack.base) ) {
    9494                create_stack(&dst->stack, dst->stack.size);
    9595                CtxStart(cor, CtxInvokeCoroutine);
    9696        }
    9797
    98       // not resuming self ?
     98        // not resuming self ?
    9999        if ( src != dst ) {
    100100                assertf( dst->state != Halted ,
     
    103103                        src->name, src, dst->name, dst );
    104104
    105             // set last resumer
     105                // set last resumer
    106106                dst->last = src;
    107107        } // if
    108108
    109       // always done for performance testing
     109        // always done for performance testing
    110110        CoroutineCtxSwitch( src, dst );
    111111}
     
    114114        coroutine_desc * src = this_coroutine();                // optimization
    115115
    116       // not resuming self ?
     116        // not resuming self ?
    117117        if ( src != dst ) {
    118118                assertf( dst->state != Halted ,
     
    121121                        src->name, src, dst->name, dst );
    122122
    123             // set last resumer
     123                // set last resumer
    124124                dst->last = src;
    125125        } // if
    126126
    127       // always done for performance testing
     127        // always done for performance testing
    128128        CoroutineCtxSwitch( src, dst );
    129129}
  • src/libcfa/concurrency/kernel.c

    r4e6fb8e rec35498  
    322322        // appropriate stack.
    323323        proc_cor_storage.__cor.state = Active;
    324       main( &proc_cor_storage );
    325       proc_cor_storage.__cor.state = Halted;
     324        main( &proc_cor_storage );
     325        proc_cor_storage.__cor.state = Halted;
    326326
    327327        // Main routine of the core returned, the core is now fully terminated
     
    371371        if( !thrd ) return;
    372372
    373         assertf( thrd->next == NULL, "Expected null got %p", thrd->next );
     373        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    374374       
    375375        lock( &systemProcessor->proc.cltr->lock );
     
    650650
    651651void append( __thread_queue_t * this, thread_desc * t ) {
    652         assert(this->tail != NULL);
     652        verify(this->tail != NULL);
    653653        *this->tail = t;
    654654        this->tail = &t->next;
     
    672672
    673673void push( __condition_stack_t * this, __condition_criterion_t * t ) {
    674         assert( !t->next );
     674        verify( !t->next );
    675675        t->next = this->top;
    676676        this->top = t;
  • src/libcfa/concurrency/kernel_private.h

    r4e6fb8e rec35498  
    2222
    2323#include "alarm.h"
     24
     25#include "libhdr.h"
    2426
    2527//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/monitor

    r4e6fb8e rec35498  
    2626static inline void ?{}(monitor_desc * this) {
    2727        this->owner = NULL;
    28       this->stack_owner = NULL;
     28        this->stack_owner = NULL;
    2929        this->recursion = 0;
    3030}
     
    3333        monitor_desc ** m;
    3434        int count;
    35       monitor_desc ** prev_mntrs;
    36       unsigned short  prev_count;
     35        monitor_desc ** prev_mntrs;
     36        unsigned short  prev_count;
    3737};
    3838
  • src/libcfa/concurrency/monitor.c

    r4e6fb8e rec35498  
    5656                else if( this->owner == thrd) {
    5757                        //We already have the monitor, just not how many times we took it
    58                         assert( this->recursion > 0 );
     58                        verify( this->recursion > 0 );
    5959                        this->recursion += 1;
    6060                }
     
    7878                lock( &this->lock );
    7979
    80                 thread_desc * thrd = this_thread();
    81 
    8280                LIB_DEBUG_PRINT_SAFE("%p Leaving %p (o: %p, r: %i)\n", thrd, this, this->owner, this->recursion);
    83                 assertf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i)", thrd, this->owner, this->recursion );
     81                verifyf( this_thread() == this->owner, "Expected owner to be %p, got %p (r: %i)", this_thread(), this->owner, this->recursion );
    8482
    8583                //Leaving a recursion level, decrement the counter
     
    167165        //Check that everything is as expected
    168166        assertf( this->monitors != NULL, "Waiting with no monitors (%p)", this->monitors );
    169         assertf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count );
    170         assertf( this->monitor_count < 32u, "Excessive monitor count (%i)", this->monitor_count );
     167        verifyf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count );
     168        verifyf( this->monitor_count < 32u, "Excessive monitor count (%i)", this->monitor_count );
    171169
    172170        unsigned short count = this->monitor_count;
     
    229227
    230228        //Check that everything is as expected
    231         assert( this->monitors );
    232         assert( this->monitor_count != 0 );
     229        verify( this->monitors );
     230        verify( this->monitor_count != 0 );
    233231
    234232        unsigned short count = this->monitor_count;
     
    278276
    279277        //Check that everything is as expected
    280         assertf( this->monitors != NULL, "Waiting with no monitors (%p)", this->monitors );
    281         assertf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count );
     278        verifyf( this->monitors != NULL, "Waiting with no monitors (%p)", this->monitors );
     279        verifyf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count );
    282280
    283281        unsigned short count = this->monitor_count;
     
    327325
    328326uintptr_t front( condition * this ) {
    329         LIB_DEBUG_DO(
    330                 if( is_empty(this) ) {
    331                         abortf( "Attempt to access user data on an empty condition.\n"
    332                     "Possible cause is not checking if the condition is empty before reading stored data." );
    333                 }
     327        verifyf( !is_empty(this),
     328                "Attempt to access user data on an empty condition.\n"
     329                "Possible cause is not checking if the condition is empty before reading stored data."
    334330        );
    335331        return this->blocked.head->user_info;
     
    491487
    492488void append( __condition_blocked_queue_t * this, __condition_node_t * c ) {
    493         assert(this->tail != NULL);
     489        verify(this->tail != NULL);
    494490        *this->tail = c;
    495491        this->tail = &c->next;
  • src/libcfa/libhdr/libdebug.h

    r4e6fb8e rec35498  
    1818
    1919#ifdef __CFA_DEBUG__
    20       #define LIB_DEBUG_DO(x) x
    21       #define LIB_NO_DEBUG_DO(x)
     20        #define LIB_DEBUG_DO(x) x
     21        #define LIB_NO_DEBUG_DO(x)
    2222#else
    23       #define LIB_DEBUG_DO(x)
    24       #define LIB_NO_DEBUG_DO(x) x     
     23        #define LIB_DEBUG_DO(x)
     24        #define LIB_NO_DEBUG_DO(x) x     
    2525#endif
     26
     27#if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__))
     28        #define verify(x) assert(x)
     29        #define verifyf(x, ...) assertf(x, __VA_ARGS__)
     30#else
     31        #define verify(x)
     32        #define verifyf(x, ...)
     33#endif
     34
    2635
    2736#ifdef __cforall
Note: See TracChangeset for help on using the changeset viewer.