Changeset 50f6afb


Ignore:
Timestamp:
Apr 24, 2021, 11:32:49 AM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
424dfc4, 986cb99
Parents:
fec63b2 (diff), 8edbe40 (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:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/protocol.cfa

    rfec63b2 r50f6afb  
    55        #include <fcntl.h>
    66}
     7
     8#define xstr(s) str(s)
     9#define str(s) #s
    710
    811#include <fstream.hfa>
     
    2124
    2225#define PLAINTEXT_1WRITE
     26#define PLAINTEXT_MEMCPY
    2327#define PLAINTEXT_NOCOPY
    2428
     
    8589#if defined(PLAINTEXT_NOCOPY)
    8690int answer_plaintext( int fd ) {
    87         return answer(fd, http_msgs[OK200_PlainText]->msg, http_msgs[OK200_PlainText]->len + 1); // +1 cause snprintf doesn't count nullterminator
     91        return answer(fd, http_msgs[OK200_PlainText]->msg, http_msgs[OK200_PlainText]->len); // +1 cause snprintf doesn't count nullterminator
     92}
     93#elif defined(PLAINTEXT_MEMCPY)
     94#define TEXTSIZE 15
     95int answer_plaintext( int fd ) {
     96        char text[] = "Hello, World!\n\n";
     97        char ts[] = xstr(TEXTSIZE) " \n\n";
     98        _Static_assert(sizeof(text) - 1 == TEXTSIZE);
     99        char buffer[512 + TEXTSIZE];
     100        char * it = buffer;
     101        memcpy(it, http_msgs[OK200]->msg, http_msgs[OK200]->len);
     102        it += http_msgs[OK200]->len;
     103        int len = http_msgs[OK200]->len;
     104        memcpy(it, ts, sizeof(ts) - 1);
     105        it += sizeof(ts) - 1;
     106        len += sizeof(ts) - 1;
     107        memcpy(it, text, TEXTSIZE);
     108        return answer(fd, buffer, len + TEXTSIZE);
    88109}
    89110#elif defined(PLAINTEXT_1WRITE)
    90111int answer_plaintext( int fd ) {
    91         char text[] = "Hello, World!\n";
     112        char text[] = "Hello, World!\n\n";
    92113        char buffer[512 + sizeof(text)];
    93114        char * it = buffer;
     
    103124#else
    104125int answer_plaintext( int fd ) {
    105         char text[] = "Hello, World!\n";
     126        char text[] = "Hello, World!\n\n";
    106127        int ret = answer_header(fd, sizeof(text));
    107128        if( ret < 0 ) return ret;
     
    194215const char * original_http_msgs[] = {
    195216        "HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: ",
    196         "HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 15\n\nHello, World!\n",
     217        "HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 15\n\nHello, World!\n\n",
    197218        "HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
    198219        "HTTP/1.1 404 Not Found\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
  • benchmark/io/http/worker.cfa

    rfec63b2 r50f6afb  
    1818void ?{}( Worker & this ) {
    1919        size_t cli = rand() % options.clopts.cltr_cnt;
    20         ((thread&)this){ "Server Worker Thread", *options.clopts.instance[cli] };
     20        ((thread&)this){ "Server Worker Thread", *options.clopts.instance[cli], 512000 };
    2121        options.clopts.thrd_cnt[cli]++;
    2222        this.pipe[0] = -1;
  • benchmark/readyQ/cycle.cpp

    rfec63b2 r50f6afb  
    33#include <libfibre/fibre.h>
    44
    5 class __attribute__((aligned(128))) bench_sem {
    6         Fibre * volatile ptr = nullptr;
    7 public:
    8         inline bool wait() {
    9                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    10                 for(;;) {
    11                         Fibre * expected = this->ptr;
    12                         if(expected == ready) {
    13                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    14                                         return false;
    15                                 }
    16                         }
    17                         else {
    18                                 /* paranoid */ assert( expected == nullptr );
    19                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    20                                         fibre_park();
    21                                         return true;
    22                                 }
    23                         }
    24 
    25                 }
    26         }
    27 
    28         inline bool post() {
    29                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    30                 for(;;) {
    31                         Fibre * expected = this->ptr;
    32                         if(expected == ready) return false;
    33                         if(expected == nullptr) {
    34                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    35                                         return false;
    36                                 }
    37                         }
    38                         else {
    39                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    40                                         fibre_unpark( expected );
    41                                         return true;
    42                                 }
    43                         }
    44                 }
    45         }
    46 };
    475struct Partner {
    486        unsigned long long count  = 0;
  • benchmark/readyQ/locality.cpp

    rfec63b2 r50f6afb  
    99        uint64_t dmigs = 0;
    1010        uint64_t gmigs = 0;
    11 };
    12 
    13 class __attribute__((aligned(128))) bench_sem {
    14         Fibre * volatile ptr = nullptr;
    15 public:
    16         inline bool wait() {
    17                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    18                 for(;;) {
    19                         Fibre * expected = this->ptr;
    20                         if(expected == ready) {
    21                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    22                                         return false;
    23                                 }
    24                         }
    25                         else {
    26                                 /* paranoid */ assert( expected == nullptr );
    27                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    28                                         fibre_park();
    29                                         return true;
    30                                 }
    31                         }
    32 
    33                 }
    34         }
    35 
    36         inline bool post() {
    37                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    38                 for(;;) {
    39                         Fibre * expected = this->ptr;
    40                         if(expected == ready) return false;
    41                         if(expected == nullptr) {
    42                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    43                                         return false;
    44                                 }
    45                         }
    46                         else {
    47                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    48                                         fibre_unpark( expected );
    49                                         return true;
    50                                 }
    51                         }
    52                 }
    53         }
    5411};
    5512
  • benchmark/readyQ/rq_bench.hfa

    rfec63b2 r50f6afb  
    44#include <stdio.h>
    55#include <stdlib.hfa>
     6#include <stats.hfa>
    67#include <thread.hfa>
    78#include <time.hfa>
     
    6364                (*p){ "Benchmark Processor", this.cl };
    6465        }
     66        #if !defined(__CFA_NO_STATISTICS__)
     67                print_stats_at_exit( this.cl, CFA_STATS_READY_Q );
     68        #endif
    6569}
    6670
  • benchmark/readyQ/rq_bench.hpp

    rfec63b2 r50f6afb  
    66#include <time.h>                                                                               // timespec
    77#include <sys/time.h>                                                                   // timeval
     8
     9typedef __uint128_t __lehmer64_state_t;
     10static inline uint64_t __lehmer64( __lehmer64_state_t & state ) {
     11        state *= 0xda942042e4dd58b5;
     12        return state >> 64;
     13}
    814
    915enum { TIMEGRAN = 1000000000LL };                                       // nanosecond granularity, except for timeval
     
    7581}
    7682
     83class Fibre;
     84int fibre_park();
     85int fibre_unpark( Fibre * );
     86Fibre * fibre_self();
     87
     88class __attribute__((aligned(128))) bench_sem {
     89        Fibre * volatile ptr = nullptr;
     90public:
     91        inline bool wait() {
     92                static Fibre * const ready  = reinterpret_cast<Fibre *>(1ull);
     93                for(;;) {
     94                        Fibre * expected = this->ptr;
     95                        if(expected == ready) {
     96                                if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     97                                        return false;
     98                                }
     99                        }
     100                        else {
     101                                /* paranoid */ assert( expected == nullptr );
     102                                if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     103                                        fibre_park();
     104                                        return true;
     105                                }
     106                        }
     107
     108                }
     109        }
     110
     111        inline bool post() {
     112                static Fibre * const ready  = reinterpret_cast<Fibre *>(1ull);
     113                for(;;) {
     114                        Fibre * expected = this->ptr;
     115                        if(expected == ready) return false;
     116                        if(expected == nullptr) {
     117                                if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     118                                        return false;
     119                                }
     120                        }
     121                        else {
     122                                if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     123                                        fibre_unpark( expected );
     124                                        return true;
     125                                }
     126                        }
     127                }
     128        }
     129};
     130
    77131// ==========================================================================================
    78132#include <cstdlib>
     
    188242                this->help       = help;
    189243                this->variable   = reinterpret_cast<void*>(&variable);
    190                 this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(static_cast<bool (*)(const char *, T & )>(parse));
     244                #pragma GCC diagnostic push
     245                #pragma GCC diagnostic ignored "-Wcast-function-type"
     246                                this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(static_cast<bool (*)(const char *, T & )>(parse));
     247                #pragma GCC diagnostic pop
    191248        }
    192249
     
    197254                this->help       = help;
    198255                this->variable   = reinterpret_cast<void*>(&variable);
    199                 this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(parse);
     256                #pragma GCC diagnostic push
     257                #pragma GCC diagnostic ignored "-Wcast-function-type"
     258                        this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(parse);
     259                #pragma GCC diagnostic pop
    200260        }
    201261};
  • libcfa/src/concurrency/clib/cfathread.cfa

    rfec63b2 r50f6afb  
    5050
    5151cfathread_vtable _cfathread_vtable_instance;
     52
     53cfathread_vtable & const _default_vtable = _cfathread_vtable_instance;
    5254
    5355cfathread_vtable const & get_exception_vtable(cfathread_exception *) {
  • libcfa/src/concurrency/coroutine.cfa

    rfec63b2 r50f6afb  
    4646
    4747//-----------------------------------------------------------------------------
    48 EHM_VIRTUAL_TABLE(SomeCoroutineCancelled, std_coroutine_cancelled);
    49 
    5048forall(T &)
    5149void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) {
     
    6260// This code should not be inlined. It is the error path on resume.
    6361forall(T & | is_coroutine(T))
    64 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) {
     62void __cfaehm_cancelled_coroutine(
     63                T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ) {
    6564        verify( desc->cancellation );
    6665        desc->state = Cancelled;
     
    6867
    6968        // TODO: Remove explitate vtable set once trac#186 is fixed.
    70         SomeCoroutineCancelled except;
    71         except.virtual_table = &std_coroutine_cancelled;
     69        CoroutineCancelled(T) except;
     70        except.virtual_table = &_default_vtable;
    7271        except.the_coroutine = &cor;
    7372        except.the_exception = except;
    7473        // Why does this need a cast?
    75         throwResume (SomeCoroutineCancelled &)except;
     74        throwResume (CoroutineCancelled(T) &)except;
    7675
    7776        except->virtual_table->free( except );
     
    146145// Part of the Public API
    147146// Not inline since only ever called once per coroutine
    148 forall(T & | is_coroutine(T))
     147forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    149148void prime(T& cor) {
    150149        $coroutine* this = get_coroutine(cor);
  • libcfa/src/concurrency/coroutine.hfa

    rfec63b2 r50f6afb  
    2222//-----------------------------------------------------------------------------
    2323// Exception thrown from resume when a coroutine stack is cancelled.
    24 EHM_EXCEPTION(SomeCoroutineCancelled)(
    25         void * the_coroutine;
    26         exception_t * the_exception;
    27 );
    28 
    29 EHM_EXTERN_VTABLE(SomeCoroutineCancelled, std_coroutine_cancelled);
    30 
    3124EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) (
    3225        coroutine_t * the_coroutine;
     
    4437// Anything that implements this trait can be resumed.
    4538// Anything that is resumed is a coroutine.
    46 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(SomeCoroutineCancelled)) {
     39trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) {
    4740        void main(T & this);
    4841        $coroutine * get_coroutine(T & this);
     
    6760//-----------------------------------------------------------------------------
    6861// Public coroutine API
    69 forall(T & | is_coroutine(T))
     62forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    7063void prime(T & cor);
    7164
     
    137130
    138131forall(T & | is_coroutine(T))
    139 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc );
     132void __cfaehm_cancelled_coroutine(
     133        T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable );
    140134
    141135// Resume implementation inlined for performance
    142 forall(T & | is_coroutine(T))
     136forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    143137static inline T & resume(T & cor) {
    144138        // optimization : read TLS once and reuse it
     
    170164        $ctx_switch( src, dst );
    171165        if ( unlikely(dst->cancellation) ) {
    172                 __cfaehm_cancelled_coroutine( cor, dst );
     166                __cfaehm_cancelled_coroutine( cor, dst, _default_vtable );
    173167        }
    174168
  • libcfa/src/concurrency/locks.hfa

    rfec63b2 r50f6afb  
    197197static inline $thread * unlock( fast_lock & this ) __attribute__((artificial));
    198198static inline $thread * unlock( fast_lock & this ) {
    199         $thread * thrd = active_thread();
    200         /* paranoid */ verify(thrd == this.owner);
     199        /* paranoid */ verify(active_thread() == this.owner);
    201200
    202201        // open 'owner' before unlocking anyone
  • libcfa/src/concurrency/ready_queue.cfa

    rfec63b2 r50f6afb  
    413413                        unsigned it2  = proc->rdq.itr + 1;
    414414                        unsigned idx1 = proc->rdq.id + (it1 % READYQ_SHARD_FACTOR);
    415                         unsigned idx2 = proc->rdq.id + (it1 % READYQ_SHARD_FACTOR);
     415                        unsigned idx2 = proc->rdq.id + (it2 % READYQ_SHARD_FACTOR);
    416416                        unsigned long long tsc1 = ts(lanes.data[idx1]);
    417417                        unsigned long long tsc2 = ts(lanes.data[idx2]);
    418418                        proc->rdq.cutoff = min(tsc1, tsc2);
    419                 }
    420                 else if(lanes.tscs[proc->rdq.target].tv < proc->rdq.cutoff) {
    421                         $thread * t = try_pop(cltr, proc->rdq.target __STATS(, __tls_stats()->ready.pop.help));
     419                        if(proc->rdq.cutoff == 0) proc->rdq.cutoff = -1ull;
     420                }
     421                else {
     422                        unsigned target = proc->rdq.target;
    422423                        proc->rdq.target = -1u;
    423                         if(t) return t;
     424                        if(lanes.tscs[target].tv < proc->rdq.cutoff) {
     425                                $thread * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
     426                                if(t) return t;
     427                        }
    424428                }
    425429
  • libcfa/src/concurrency/stats.cfa

    rfec63b2 r50f6afb  
    126126                        double sExt_len = ready.push.extrn.success ? ((double)ready.push.extrn.attempt) / ready.push.extrn.success : 0;
    127127
    128                         double rLcl_len  = ready.pop.local .success ? ((double)ready.pop.local .attempt) / ready.pop.local .success : 0;
    129                         double rHlp_len  = ready.pop.help  .success ? ((double)ready.pop.help  .attempt) / ready.pop.help  .success : 0;
    130                         double rStl_len  = ready.pop.steal .success ? ((double)ready.pop.steal .attempt) / ready.pop.steal .success : 0;
    131                         double rSch_len  = ready.pop.search.success ? ((double)ready.pop.search.attempt) / ready.pop.search.success : 0;
     128                        uint64_t total = ready.pop.local.success + ready.pop.help.success + ready.pop.steal.success + ready.pop.search.success;
     129                        double rLcl_pc = (100.0 * (double)ready.pop.local .success) / total;
     130                        double rHlp_pc = (100.0 * (double)ready.pop.help  .success) / total;
     131                        double rStl_pc = (100.0 * (double)ready.pop.steal .success) / total;
     132                        double rSch_pc = (100.0 * (double)ready.pop.search.success) / total;
    132133
    133134                        __cfaabi_bits_print_safe( STDOUT_FILENO,
    134135                                "----- %s \"%s\" (%p) - Ready Q Stats -----\n"
    135136                                "- totals   : %'3" PRIu64 " run, %'3" PRIu64 " schd (%'" PRIu64 "ext, %'" PRIu64 "mig, %'" PRId64 " )\n"
    136                                 "- push avg : %'3.2lf (l: %'3.2lf/%'" PRIu64 ", s: %'3.2lf/%'" PRIu64 ", e: %'3.2lf : %'" PRIu64 "e)\n"
    137                                 "- local    : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    138                                 "- help     : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    139                                 "- steal    : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    140                                 "- search   : %'3.2lf (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     137                                "- push avg : %'3.0lf (l: %'3.2lf/%'" PRIu64 ", s: %'3.2lf/%'" PRIu64 ", e: %'3.2lf : %'" PRIu64 "e)\n"
     138                                "- local    : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     139                                "- help     : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     140                                "- steal    : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
     141                                "- search   : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    141142                                "- Idle Slp : %'3" PRIu64 "h, %'3" PRIu64 "c, %'3" PRIu64 "w, %'3" PRIu64 "e\n"
    142143                                "\n"
    143144                                , type, name, id
    144                                 , ready.pop.local.success + ready.pop.help.success + ready.pop.steal.success + ready.pop.search.success
     145                                , total
    145146                                , ready.push.local.success + ready.push.share.success + ready.push.extrn.success
    146147                                , ready.push.extrn.success, ready.threads.migration, ready.threads.threads
    147148                                , push_len, sLcl_len, ready.push.local.attempt, sOth_len, ready.push.share.attempt, sExt_len, ready.push.extrn.attempt
    148                                 , rLcl_len, ready.pop.local .attempt, ready.pop.local .espec, ready.pop.local .elock, ready.pop.local .eempty
    149                                 , rHlp_len, ready.pop.help  .attempt, ready.pop.help  .espec, ready.pop.help  .elock, ready.pop.help  .eempty
    150                                 , rStl_len, ready.pop.steal .attempt, ready.pop.steal .espec, ready.pop.steal .elock, ready.pop.steal .eempty
    151                                 , rSch_len, ready.pop.search.attempt, ready.pop.search.espec, ready.pop.search.elock, ready.pop.search.eempty
     149                                , rLcl_pc, ready.pop.local .success, ready.pop.local .attempt, ready.pop.local .espec, ready.pop.local .elock, ready.pop.local .eempty
     150                                , rHlp_pc, ready.pop.help  .success, ready.pop.help  .attempt, ready.pop.help  .espec, ready.pop.help  .elock, ready.pop.help  .eempty
     151                                , rStl_pc, ready.pop.steal .success, ready.pop.steal .attempt, ready.pop.steal .espec, ready.pop.steal .elock, ready.pop.steal .eempty
     152                                , rSch_pc, ready.pop.search.success, ready.pop.search.attempt, ready.pop.search.espec, ready.pop.search.elock, ready.pop.search.eempty
    152153                                , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits
    153154                        );
  • libcfa/src/concurrency/thread.cfa

    rfec63b2 r50f6afb  
    6161}
    6262
    63 EHM_VIRTUAL_TABLE(SomeThreadCancelled, std_thread_cancelled);
    64 
    6563forall(T &)
    6664void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src) {
     
    8179}
    8280
    83 static void default_thread_cancel_handler(SomeThreadCancelled & ) {
    84         // Improve this error message, can I do formatting?
    85         abort( "Unhandled thread cancellation.\n" );
    86 }
    87 
    88 forall(T & | is_thread(T) | IS_EXCEPTION(SomeThreadCancelled))
     81forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))
     82    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })
    8983void ?{}( thread_dtor_guard_t & this,
    90                 T & thrd, void(*cancelHandler)(SomeThreadCancelled &)) {
     84                T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) {
    9185        $monitor * m = get_monitor(thrd);
    9286        $thread * desc = get_thread(thrd);
     
    9488        // Setup the monitor guard
    9589        void (*dtor)(T& mutex this) = ^?{};
    96         bool join = cancelHandler != (void(*)(SomeThreadCancelled&))0;
     90        bool join = cancelHandler != (void(*)(ThreadCancelled(T)&))0;
    9791        (this.mg){&m, (void(*)())dtor, join};
    9892
     
    108102        }
    109103        desc->state = Cancelled;
    110         void(*defaultResumptionHandler)(SomeThreadCancelled &) =
     104        void(*defaultResumptionHandler)(ThreadCancelled(T) &) =
    111105                join ? cancelHandler : default_thread_cancel_handler;
    112106
    113107        // TODO: Remove explitate vtable set once trac#186 is fixed.
    114         SomeThreadCancelled except;
    115         except.virtual_table = &std_thread_cancelled;
     108        ThreadCancelled(T) except;
     109        except.virtual_table = &_default_vtable;
    116110        except.the_thread = &thrd;
    117111        except.the_exception = __cfaehm_cancellation_exception( cancellation );
    118112        // Why is this cast required?
    119         throwResume (SomeThreadCancelled &)except;
     113        throwResume (ThreadCancelled(T) &)except;
    120114
    121115        except.the_exception->virtual_table->free( except.the_exception );
     
    164158
    165159//-----------------------------------------------------------------------------
    166 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled))
     160forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))
     161    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })
    167162T & join( T & this ) {
    168163        thread_dtor_guard_t guard = { this, defaultResumptionHandler };
  • libcfa/src/concurrency/thread.hfa

    rfec63b2 r50f6afb  
    3131        $thread* get_thread(T& this);
    3232};
    33 
    34 EHM_EXCEPTION(SomeThreadCancelled) (
    35         void * the_thread;
    36         exception_t * the_exception;
    37 );
    38 
    39 EHM_EXTERN_VTABLE(SomeThreadCancelled, std_thread_cancelled);
    4033
    4134EHM_FORALL_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) (
     
    8679};
    8780
    88 forall( T & | is_thread(T) | IS_EXCEPTION(SomeThreadCancelled) )
    89 void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(SomeThreadCancelled &) );
     81forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))
     82    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } )
     83void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) );
    9084void ^?{}( thread_dtor_guard_t & this );
    9185
     
    132126//----------
    133127// join
    134 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(SomeThreadCancelled) )
     128forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))
     129    | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } )
    135130T & join( T & this );
    136131
  • libcfa/src/exception.hfa

    rfec63b2 r50f6afb  
    142142                _EHM_VTABLE_TYPE(exception_name) parameters const &) {} \
    143143
    144 #define _EHM_TRAIT_FUNCTION2(exception_name, forall_clause, parameters) \
    145         forall_clause _EHM_VTABLE_TYPE(exception_name) parameters const & \
    146                         get_exception_vtable(exception_name parameters const & this)
    147 
    148144#define __EHM_TRAIT_FUNCTION(exception_name, forall_clause, parameters) \
    149145        forall_clause inline _EHM_VTABLE_TYPE(exception_name) parameters const & \
  • src/Concurrency/Keywords.cc

    rfec63b2 r50f6afb  
    414414                if ( type_decl && isDestructorFor( decl, type_decl ) )
    415415                        dtor_decl = decl;
    416                 else if ( vtable_name.empty() )
    417                         ;
    418                 else if( !decl->has_body() )
     416                else if ( vtable_name.empty() || !decl->has_body() )
    419417                        ;
    420418                else if ( auto param = isMainFor( decl, cast_target ) ) {
     
    428426                        std::list< Expression * > poly_args = { new TypeExpr( struct_type->clone() ) };
    429427                        ObjectDecl * vtable_object = Virtual::makeVtableInstance(
     428                                "_default_vtable_object_declaration",
    430429                                vtable_decl->makeInst( poly_args ), struct_type, nullptr );
    431430                        declsToAddAfter.push_back( vtable_object );
     431                        declsToAddAfter.push_back(
     432                                new ObjectDecl(
     433                                        Virtual::concurrentDefaultVTableName(),
     434                                        Type::Const,
     435                                        LinkageSpec::Cforall,
     436                                        /* bitfieldWidth */ nullptr,
     437                                        new ReferenceType( Type::Const, vtable_object->type->clone() ),
     438                                        new SingleInit( new VariableExpr( vtable_object ) )
     439                                )
     440                        );
    432441                        declsToAddAfter.push_back( Virtual::makeGetExceptionFunction(
    433442                                vtable_object, except_decl->makeInst( std::move( poly_args ) )
     
    488497                        except_decl->makeInst( poly_args )
    489498                ) );
    490                 declsToAddBefore.push_back( Virtual::makeVtableForward(
    491                         vtable_decl->makeInst( move( poly_args ) ) ) );
     499                ObjectDecl * vtable_object = Virtual::makeVtableForward(
     500                        "_default_vtable_object_declaration",
     501                        vtable_decl->makeInst( move( poly_args ) ) );
     502                declsToAddBefore.push_back( vtable_object );
     503                declsToAddBefore.push_back(
     504                        new ObjectDecl(
     505                                Virtual::concurrentDefaultVTableName(),
     506                                Type::Const,
     507                                LinkageSpec::Cforall,
     508                                /* bitfieldWidth */ nullptr,
     509                                new ReferenceType( Type::Const, vtable_object->type->clone() ),
     510                                /* init */ nullptr
     511                        )
     512                );
    492513        }
    493514
  • src/Virtual/Tables.cc

    rfec63b2 r50f6afb  
    1010// Created On       : Mon Aug 31 11:11:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Apr  8 15:51:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Wed Apr 21 15:36:00 2021
     13// Update Count     : 2
    1414//
    1515
     
    5050}
    5151
     52std::string concurrentDefaultVTableName() {
     53        return "_default_vtable";
     54}
     55
    5256bool isVTableInstanceName( std::string const & name ) {
    5357        // There are some delicate length calculations here.
     
    5761
    5862static ObjectDecl * makeVtableDeclaration(
     63                std::string const & name,
    5964                StructInstType * type, Initializer * init ) {
    60         std::string const & name = instanceName( type->name );
    6165        Type::StorageClasses storage = noStorageClasses;
    6266        if ( nullptr == init ) {
     
    7377}
    7478
    75 ObjectDecl * makeVtableForward( StructInstType * type ) {
     79ObjectDecl * makeVtableForward( std::string const & name, StructInstType * type ) {
    7680        assert( type );
    77         return makeVtableDeclaration( type, nullptr );
     81        return makeVtableDeclaration( name, type, nullptr );
    7882}
    7983
    8084ObjectDecl * makeVtableInstance(
    81                 StructInstType * vtableType, Type * objectType, Initializer * init ) {
     85                std::string const & name, StructInstType * vtableType,
     86                Type * objectType, Initializer * init ) {
    8287        assert( vtableType );
    8388        assert( objectType );
     
    115120                assert(false);
    116121        }
    117         return makeVtableDeclaration( vtableType, init );
     122        return makeVtableDeclaration( name, vtableType, init );
    118123}
    119124
     
    167172}
    168173
    169 ObjectDecl * makeTypeIdForward() {
    170         return nullptr;
    171 }
    172 
    173174Attribute * linkonce( const std::string & subsection ) {
    174175        const std::string section = ".gnu.linkonce." + subsection;
  • src/Virtual/Tables.h

    rfec63b2 r50f6afb  
    1010// Created On       : Mon Aug 31 11:07:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Apr  8 15:55:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Wed Apr 21 10:30:00 2021
     13// Update Count     : 2
    1414//
    1515
     
    2727std::string instanceName( std::string const & vtable_name );
    2828std::string vtableInstanceName( std::string const & type_name );
     29std::string concurrentDefaultVTableName();
    2930bool isVTableInstanceName( std::string const & name );
    3031
    31 ObjectDecl * makeVtableForward( StructInstType * vtableType );
     32ObjectDecl * makeVtableForward(
     33        std::string const & name, StructInstType * vtableType );
    3234/* Create a forward declaration of a vtable of the given type.
    3335 * vtableType node is consumed.
    3436 */
    3537
    36 ObjectDecl * makeVtableInstance( StructInstType * vtableType, Type * objectType,
     38ObjectDecl * makeVtableInstance(
     39        std::string const & name,
     40        StructInstType * vtableType, Type * objectType,
    3741        Initializer * init = nullptr );
    3842/* Create an initialized definition of a vtable.
  • tests/concurrent/coroutineYield.cfa

    rfec63b2 r50f6afb  
    3838
    3939
     40Coroutine c;
    4041int main(int argc, char* argv[]) {
    41         Coroutine c;
    4242        for(int i = 0; TEST(i < N); i++) {
    4343                #if !defined(TEST_FOREVER)
  • tests/exceptions/cancel/coroutine.cfa

    rfec63b2 r50f6afb  
    2525                resume(cancel);
    2626                printf("4");
    27         } catchResume (SomeCoroutineCancelled * error) {
     27        } catchResume (CoroutineCancelled(WillCancel) * error) {
    2828                printf("2");
    2929                if ((virtual internal_error *)error->the_exception) {
  • tests/exceptions/cancel/thread.cfa

    rfec63b2 r50f6afb  
    2626                join(cancel);
    2727                printf("4");
    28         } catchResume (SomeThreadCancelled * error) {
     28        } catchResume (ThreadCancelled(WillCancel) * error) {
    2929                printf("2");
    3030                if ((virtual internal_error *)error->the_exception) {
     
    4343                }
    4444                printf("4");
    45         } catchResume (SomeThreadCancelled * error) {
     45        } catchResume (ThreadCancelled(WillCancel) * error) {
    4646                printf("2");
    4747                if ((virtual internal_error *)error->the_exception) {
Note: See TracChangeset for help on using the changeset viewer.