Changes in / [7d6e01d:068a202]


Ignore:
Files:
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    r7d6e01d r068a202  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 13:26:26 2020
    13 // Update Count     : 424
     12// Last Modified On : Fri Jan 31 16:48:03 2020
     13// Update Count     : 421
    1414//
    1515
     
    301301        } // for
    302302
     303        #ifdef __x86_64__
     304        args[nargs++] = "-mcx16";                                                       // allow double-wide CAA
     305        #endif // __x86_64__
     306
    303307        #ifdef __DEBUG_H__
    304308        cerr << "args:";
     
    415419                args[nargs++] = "-lcfa";
    416420                args[nargs++] = "-Wl,--pop-state";
    417                 #ifdef __x86_64__
    418                 args[nargs++] = "-mcx16";                                               // allow double-wide CAS
    419                 args[nargs++] = "-latomic";
    420                 #endif // __x86_64__
    421421                args[nargs++] = "-pthread";
    422422                args[nargs++] = "-ldl";
  • libcfa/src/Makefile.am

    r7d6e01d r068a202  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Sun May 17 21:10:26 2020
    14 ## Update Count     : 243
     13## Last Modified On : Mon Mar 16 18:07:59 2020
     14## Update Count     : 242
    1515###############################################################################
    1616
     
    3939#----------------------------------------------------------------------------------------------------------------
    4040if BUILDLIB
    41 headers_nosrc = bitmanip.hfa math.hfa gmp.hfa time_t.hfa clock.hfa \
    42                 bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa containers/list.hfa
     41headers_nosrc = bitmanip.hfa math.hfa gmp.hfa time_t.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa containers/list.hfa
    4342headers = fstream.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \
    44                 containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/stackLockFree.hfa containers/vector.hfa
     43          containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa
    4544
    4645libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa ${headers:.hfa=.cfa}
  • libcfa/src/Makefile.in

    r7d6e01d r068a202  
    240240        containers/maybe.hfa containers/pair.hfa containers/result.hfa \
    241241        containers/vector.hfa bitmanip.hfa math.hfa gmp.hfa time_t.hfa \
    242         clock.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa \
     242        bits/align.hfa bits/containers.hfa bits/defs.hfa \
    243243        bits/debug.hfa bits/locks.hfa containers/list.hfa \
    244244        concurrency/coroutine.hfa concurrency/thread.hfa \
     
    464464
    465465#----------------------------------------------------------------------------------------------------------------
    466 @BUILDLIB_TRUE@headers_nosrc = bitmanip.hfa math.hfa gmp.hfa time_t.hfa clock.hfa \
    467 @BUILDLIB_TRUE@         bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa containers/list.hfa
    468 
     466@BUILDLIB_TRUE@headers_nosrc = bitmanip.hfa math.hfa gmp.hfa time_t.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa containers/list.hfa
    469467@BUILDLIB_FALSE@headers =
    470468@BUILDLIB_TRUE@headers = fstream.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \
    471 @BUILDLIB_TRUE@         containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa
     469@BUILDLIB_TRUE@   containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa
    472470
    473471@BUILDLIB_FALSE@libsrc =
  • libcfa/src/containers/list.hfa

    r7d6e01d r068a202  
    301301                $prev_link(list_pos) = (Telem*) 0p;
    302302        }
    303 
    304         static inline bool ?`is_empty(dlist(Tnode, Telem) &list) {
    305                 assert( &list != 0p );
    306                 $dlinks(Telem) *listLinks = & list.$links;
    307                 if (listLinks->next.is_terminator) {
    308                         assert(listLinks->prev.is_terminator);
    309                         assert(listLinks->next.terminator);
    310                         assert(listLinks->prev.terminator);
    311                         return true;
    312                 } else {
    313                         assert(!listLinks->prev.is_terminator);
    314                         assert(listLinks->next.elem);
    315                         assert(listLinks->prev.elem);
    316                         return false;
    317                 }
    318         }
    319 
    320         static inline Telem & pop_first(dlist(Tnode, Telem) &list) {
    321                 assert( &list != 0p );
    322                 assert( !list`is_empty );
    323                 $dlinks(Telem) *listLinks = & list.$links;
    324                 Telem & first = *listLinks->next.elem;
    325                 Tnode & list_pos_first  = $tempcv_e2n( first );
    326                 remove(list_pos_first);
    327                 return first;
    328         }
    329 
    330         static inline Telem & pop_last(dlist(Tnode, Telem) &list) {
    331                 assert( &list != 0p );
    332                 assert( !list`is_empty );
    333                 $dlinks(Telem) *listLinks = & list.$links;
    334                 Telem & last = *listLinks->prev.elem;
    335                 Tnode & list_pos_last  = $tempcv_e2n( last );
    336                 remove(list_pos_last);
    337                 return last;
    338         }
    339 
    340303}
    341304
  • libcfa/src/exception.c

    r7d6e01d r068a202  
    223223
    224224// Cancel the current stack, prefroming approprate clean-up and messaging.
    225 void __cfaehm_cancel_stack( exception_t * exception ) {
     225static __attribute__((noreturn)) void __cfaehm_cancel_stack(
     226                exception_t * exception ) {
    226227        // TODO: Detect current stack and pick a particular stop-function.
    227228        _Unwind_Reason_Code ret;
  • libcfa/src/exception.h

    r7d6e01d r068a202  
    3838
    3939
    40 void __cfaehm_cancel_stack(exception_t * except) __attribute__((noreturn));
    41 
    4240// Used in throw statement translation.
    4341void __cfaehm_throw_terminate(exception_t * except) __attribute__((noreturn));
  • libcfa/src/exception.hfa

    r7d6e01d r068a202  
    1010// Created On       : Thu Apr  7 10:25:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Apr 13 15:42:00 2020
    13 // Update Count     : 1
     12// Last Modified On : Thu Apr  7 10:25:00 2020
     13// Update Count     : 0
    1414//
    15 
    16 trait is_exception(dtype T) {
    17         // The trait system can't describe the actual constrants.
    18         // Unused, should always be a no-op.
    19         void mark_exception(T *);
    20 };
    21 
    22 forall(dtype T | is_exception(T))
    23 inline void cancel_stack(T & except) __attribute__((noreturn)) {
    24         __cfaehm_cancel_stack( (exception_t *)&except );
    25 }
    2615
    2716// Everything below this line should be considered a patch while the exception
     
    8069#define _VTABLE_DECLARATION(exception_name, parent_name, ...) \
    8170        struct exception_name; \
    82         void mark_exception(exception_name *); \
    8371        VTABLE_TYPE(exception_name); \
    8472        extern VTABLE_TYPE(exception_name) VTABLE_NAME(exception_name); \
     
    9785#define VTABLE_INSTANCE(...) _EXC_DISPATCH(_VTABLE_INSTANCE, __VA_ARGS__)
    9886#define _VTABLE_INSTANCE(exception_name, parent_name, ...) \
    99         void mark_exception(exception_name *) {} \
    10087        void _GLUE2(exception_name,_copy)(exception_name * this, exception_name * other) { \
    10188                *this = *other; \
  • libcfa/src/executor.cfa

    r7d6e01d r068a202  
    44// buffer.
    55
    6 #include <containers/list.hfa>
     6#include <bits/containers.hfa>
    77#include <thread.hfa>
    88#include <stdio.h>
    99
     10forall( dtype T )
     11monitor Buffer {                                        // unbounded buffer
     12    __queue_t( T ) queue;                               // unbounded list of work requests
     13    condition delay;
     14}; // Buffer
     15forall( dtype T | is_node(T) ) {
     16    void insert( Buffer( T ) & mutex buf, T * elem ) with(buf) {
     17        append( queue, elem );                          // insert element into buffer
     18        signal( delay );                                // restart
     19    } // insert
     20
     21    T * remove( Buffer( T ) & mutex buf ) with(buf) {
     22        if ( queue.head != 0 ) wait( delay );                   // no request to process ? => wait
     23//      return pop_head( queue );
     24    } // remove
     25} // distribution
     26
    1027struct WRequest {                                       // client request, no return
    1128    void (* action)( void );
    12     DLISTED_MGD_IMPL_IN(WRequest)
     29    WRequest * next;                                    // intrusive queue field
    1330}; // WRequest
    14 DLISTED_MGD_IMPL_OUT(WRequest)
    1531
    16 void ?{}( WRequest & req ) with(req) { action = 0; }
    17 void ?{}( WRequest & req, void (* action)( void ) ) with(req) { req.action = action; }
     32WRequest *& get_next( WRequest & this ) { return this.next; }
     33void ?{}( WRequest & req ) with(req) { action = 0; next = 0; }
     34void ?{}( WRequest & req, void (* action)( void ) ) with(req) { req.action = action; next = 0; }
    1835bool stop( WRequest & req ) { return req.action == 0; }
    1936void doit( WRequest & req ) { req.action(); }
    20 
    21 monitor WRBuffer {                                      // unbounded buffer
    22     dlist( WRequest, WRequest ) queue;                  // unbounded list of work requests
    23     condition delay;
    24 }; // WRBuffer
    25 
    26 void insert( WRBuffer & mutex buf, WRequest * elem ) with(buf) {
    27     insert_last( queue, *elem );                        // insert element into buffer
    28     signal( delay );                                    // restart
    29 } // insert
    30 
    31 WRequest * remove( WRBuffer & mutex buf ) with(buf) {
    32     if ( queue`is_empty ) wait( delay );                // no request to process ? => wait
    33     return & pop_first( queue );
    34 } // remove
    3537
    3638// Each worker has its own work buffer to reduce contention between client and server. Hence, work requests arrive and
     
    3840
    3941thread Worker {
    40     WRBuffer * requests;
     42    Buffer( WRequest ) * requests;
    4143    unsigned int start, range;
    4244}; // Worker
     
    5254} // Worker::main
    5355
    54 void ?{}( Worker & worker, cluster * wc, WRBuffer * requests, unsigned int start, unsigned int range ) {
     56void ?{}( Worker & worker, cluster * wc, Buffer( WRequest ) * requests, unsigned int start, unsigned int range ) {
    5557    (*get_thread(worker)){ *wc };                       // create on given cluster
    5658    worker.[requests, start, range] = [requests, start, range];
     
    6062    cluster * cluster;                                  // if workers execute on separate cluster
    6163    processor ** processors;                            // array of virtual processors adding parallelism for workers
    62     WRBuffer * requests;                                // list of work requests
     64    Buffer( WRequest ) * requests;                      // list of work requests
    6365    Worker ** workers;                                  // array of workers executing work requests
    6466    unsigned int nprocessors, nworkers, nmailboxes;     // number of mailboxes/workers/processor tasks
     
    7779    cluster = sepClus ? new( "Executor" ) : active_cluster();
    7880    processors = (processor **)anew( nprocessors );
    79     requests = (WRBuffer *)anew( nmailboxes );
     81    requests = anew( nmailboxes );
    8082    workers = (Worker **)anew( nworkers );
    8183
     
    139141        for ( i; 3000 ) {
    140142            send( exector, workie );
    141             if ( i % 100 == 0 ) {
    142 //              fprintf( stderr, "%d\n", i );
    143                 yield();
    144             }
     143            if ( i % 100 ) yield();
    145144        } // for
    146145    }
  • libcfa/src/heap.cfa

    r7d6e01d r068a202  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 20:58:17 2020
    13 // Update Count     : 762
     12// Last Modified On : Wed May  6 17:29:26 2020
     13// Update Count     : 727
    1414//
    1515
     
    128128#define LOCKFREE 1
    129129#define BUCKETLOCK SPINLOCK
    130 #if BUCKETLOCK == SPINLOCK
    131 #elif BUCKETLOCK == LOCKFREE
    132 #include <stackLockFree.hfa>
    133 #else
    134         #error undefined lock type for bucket lock
     130#if BUCKETLOCK == LOCKFREE
     131#include <uStackLF.h>
    135132#endif // LOCKFREE
    136133
     
    140137
    141138struct HeapManager {
     139//      struct FreeHeader;                                                                      // forward declaration
     140
    142141        struct Storage {
    143142                struct Header {                                                                 // header
     
    147146                                                struct {                                                // 4-byte word => 8-byte header, 8-byte word => 16-byte header
    148147                                                        #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_POINTER__ == 4
    149                                                         uint64_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
     148                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    150149                                                        #endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_POINTER__ == 4
    151150
    152151                                                        union {
    153                                                                 // FreeHeader * home;           // allocated block points back to home locations (must overlay alignment)
     152//                                                              FreeHeader * home;              // allocated block points back to home locations (must overlay alignment)
    154153                                                                // 2nd low-order bit => zero filled
    155154                                                                void * home;                    // allocated block points back to home locations (must overlay alignment)
    156155                                                                size_t blockSize;               // size for munmap (must overlay alignment)
    157                                                                 #if BUCKETLOCK == SPINLOCK
     156                                                                #if BUCKLOCK == SPINLOCK
    158157                                                                Storage * next;                 // freed block points next freed block of same size
    159158                                                                #endif // SPINLOCK
    160159                                                        };
    161                                                         size_t size;                            // allocation size in bytes
    162160
    163161                                                        #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_POINTER__ == 4
    164                                                         uint64_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
     162                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    165163                                                        #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_POINTER__ == 4
    166164                                                };
    167                                                 #if BUCKETLOCK == LOCKFREE
    168                                                 Link(Storage) next;                             // freed block points next freed block of same size (double-wide)
     165                                                // future code
     166                                                #if BUCKLOCK == LOCKFREE
     167                                                Stack<Storage>::Link next;              // freed block points next freed block of same size (double-wide)
    169168                                                #endif // LOCKFREE
    170169                                        };
    171170                                } real; // RealHeader
    172 
    173171                                struct FakeHeader {
    174172                                        #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
    175                                         uint32_t alignment;                                     // 1st low-order bit => fake header & alignment
     173                                        // 1st low-order bit => fake header & alignment
     174                                        uint32_t alignment;
    176175                                        #endif // __ORDER_LITTLE_ENDIAN__
    177176
     
    183182                                } fake; // FakeHeader
    184183                        } kind; // Kind
     184                        size_t size;                                                            // allocation size in bytes
    185185                } header; // Header
    186186                char pad[libAlign() - sizeof( Header )];
     
    191191
    192192        struct FreeHeader {
    193                 #if BUCKETLOCK == SPINLOCK
     193                #if BUCKLOCK == SPINLOCK
    194194                __spinlock_t lock;                                                              // must be first field for alignment
    195195                Storage * freeList;
     196                #elif BUCKLOCK == LOCKFREE
     197                // future code
     198                StackLF<Storage> freeList;
    196199                #else
    197                 StackLF(Storage) freeList;
    198                 #endif // BUCKETLOCK
     200                        #error undefined lock type for bucket lock
     201                #endif // SPINLOCK
    199202                size_t blockSize;                                                               // size of allocations on this list
    200203        }; // FreeHeader
     
    208211        size_t heapRemaining;                                                           // amount of storage not allocated in the current chunk
    209212}; // HeapManager
    210 
    211 #if BUCKETLOCK == LOCKFREE
    212 static inline Link(HeapManager.Storage) * getNext( HeapManager.Storage * this ) { return &this->header.kind.real.next; }
    213 static inline void ?{}( HeapManager.FreeHeader & ) {}
    214 static inline void ^?{}( HeapManager.FreeHeader & ) {}
    215 #endif // LOCKFREE
    216213
    217214static inline size_t getKey( const HeapManager.FreeHeader & freeheader ) { return freeheader.blockSize; }
     
    254251static bool heapBoot = 0;                                                               // detect recursion during boot
    255252#endif // __CFA_DEBUG__
    256 
    257 // The constructor for heapManager is called explicitly in memory_startup.
    258253static HeapManager heapManager __attribute__(( aligned (128) )) @= {}; // size of cache line to prevent false sharing
    259254
     
    359354
    360355
     356// static inline void noMemory() {
     357//      abort( "Heap memory exhausted at %zu bytes.\n"
     358//                 "Possible cause is very large memory allocation and/or large amount of unfreed storage allocated by the program or system/library routines.",
     359//                 ((char *)(sbrk( 0 )) - (char *)(heapManager.heapBegin)) );
     360// } // noMemory
     361
     362
    361363// thunk problem
    362364size_t Bsearchl( unsigned int key, const unsigned int * vals, size_t dim ) {
     
    404406
    405407
    406 // static inline void noMemory() {
    407 //      abort( "Heap memory exhausted at %zu bytes.\n"
    408 //                 "Possible cause is very large memory allocation and/or large amount of unfreed storage allocated by the program or system/library routines.",
    409 //                 ((char *)(sbrk( 0 )) - (char *)(heapManager.heapBegin)) );
    410 // } // noMemory
    411 
    412 
    413408static inline void checkAlign( size_t alignment ) {
    414409        if ( alignment < libAlign() || ! libPow2( alignment ) ) {
     
    438433
    439434
    440 static inline bool headers( const char name[] __attribute__(( unused )), void * addr, HeapManager.Storage.Header *& header, HeapManager.FreeHeader *& freeElem,
    441                                                         size_t & size, size_t & alignment ) with( heapManager ) {
     435static inline bool headers( const char name[] __attribute__(( unused )), void * addr, HeapManager.Storage.Header *& header, HeapManager.FreeHeader *& freeElem, size_t & size, size_t & alignment ) with ( heapManager ) {
    442436        header = headerAddr( addr );
    443437
     
    471465
    472466
    473 static inline void * extend( size_t size ) with( heapManager ) {
     467static inline void * extend( size_t size ) with ( heapManager ) {
    474468        lock( extlock __cfaabi_dbg_ctx2 );
    475469        ptrdiff_t rem = heapRemaining - size;
     
    502496
    503497
    504 static inline void * doMalloc( size_t size ) with( heapManager ) {
     498static inline void * doMalloc( size_t size ) with ( heapManager ) {
    505499        HeapManager.Storage * block;                                            // pointer to new block of storage
    506500
     
    535529                // Spin until the lock is acquired for this particular size of block.
    536530
    537                 #if BUCKETLOCK == SPINLOCK
     531                #if defined( SPINLOCK )
    538532                lock( freeElem->lock __cfaabi_dbg_ctx2 );
    539533                block = freeElem->freeList;                                             // remove node from stack
    540534                #else
    541                 block = pop( freeElem->freeList );
    542                 #endif // BUCKETLOCK
     535                block = freeElem->freeList.pop();
     536                #endif // SPINLOCK
    543537                if ( unlikely( block == 0p ) ) {                                // no free block ?
    544                         #if BUCKETLOCK == SPINLOCK
     538                        #if defined( SPINLOCK )
    545539                        unlock( freeElem->lock );
    546                         #endif // BUCKETLOCK
     540                        #endif // SPINLOCK
    547541
    548542                        // Freelist for that size was empty, so carve it out of the heap if there's enough left, or get some more
     
    550544
    551545                        block = (HeapManager.Storage *)extend( tsize ); // mutual exclusion on call
    552         if ( unlikely( block == 0p ) ) return 0p;
    553                 #if BUCKETLOCK == SPINLOCK
     546  if ( unlikely( block == 0p ) ) return 0p;
     547                #if defined( SPINLOCK )
    554548                } else {
    555549                        freeElem->freeList = block->header.kind.real.next;
    556550                        unlock( freeElem->lock );
    557                 #endif // BUCKETLOCK
     551                #endif // SPINLOCK
    558552                } // if
    559553
     
    578572        } // if
    579573
    580         block->header.kind.real.size = size;                            // store allocation size
     574        block->header.size = size;                                                      // store allocation size
    581575        void * addr = &(block->data);                                           // adjust off header to user bytes
    582576
     
    597591
    598592
    599 static inline void doFree( void * addr ) with( heapManager ) {
     593static inline void doFree( void * addr ) with ( heapManager ) {
    600594        #ifdef __CFA_DEBUG__
    601595        if ( unlikely( heapManager.heapBegin == 0p ) ) {
     
    629623                free_storage += size;
    630624                #endif // __STATISTICS__
    631                 #if BUCKETLOCK == SPINLOCK
     625                #if defined( SPINLOCK )
    632626                lock( freeElem->lock __cfaabi_dbg_ctx2 );               // acquire spin lock
    633627                header->kind.real.next = freeElem->freeList;    // push on stack
     
    635629                unlock( freeElem->lock );                                               // release spin lock
    636630                #else
    637                 push( freeElem->freeList, *(HeapManager.Storage *)header );
    638                 #endif // BUCKETLOCK
     631                freeElem->freeList.push( *(HeapManager.Storage *)header );
     632                #endif // SPINLOCK
    639633        } // if
    640634
     
    651645
    652646
    653 size_t prtFree( HeapManager & manager ) with( manager ) {
     647size_t prtFree( HeapManager & manager ) with ( manager ) {
    654648        size_t total = 0;
    655649        #ifdef __STATISTICS__
     
    663657                #endif // __STATISTICS__
    664658
    665                 #if BUCKETLOCK == SPINLOCK
     659                #if defined( SPINLOCK )
    666660                for ( HeapManager.Storage * p = freeLists[i].freeList; p != 0p; p = p->header.kind.real.next ) {
    667661                #else
    668                 for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; /* p = getNext( p )->top */) {
    669                         typeof(p) temp = getNext( p )->top;                     // FIX ME: direct assignent fails, initialization works
    670                         p = temp;
    671                 #endif // BUCKETLOCK
     662                for ( HeapManager.Storage * p = freeLists[i].freeList.top(); p != 0p; p = p->header.kind.real.next.top ) {
     663                #endif // SPINLOCK
    672664                        total += size;
    673665                        #ifdef __STATISTICS__
     
    689681
    690682
    691 static void ?{}( HeapManager & manager ) with( manager ) {
     683static void ?{}( HeapManager & manager ) with ( manager ) {
    692684        pageSize = sysconf( _SC_PAGESIZE );
    693685
     
    11031095                        header = realHeader( header );                          // backup from fake to real header
    11041096                } // if
    1105                 return header->kind.real.size;
     1097                return header->size;
    11061098        } // malloc_size
    11071099
     
    11131105                        header = realHeader( header );                          // backup from fake to real header
    11141106                } // if
    1115                 size_t ret = header->kind.real.size;
    1116                 header->kind.real.size = size;
     1107                size_t ret = header->size;
     1108                header->size = size;
    11171109                return ret;
    11181110        } // $malloc_size_set
  • libcfa/src/stdlib.hfa

    r7d6e01d r068a202  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 13 17:23:51 2020
    13 // Update Count     : 435
     12// Last Modified On : Thu Apr 16 22:44:05 2020
     13// Update Count     : 432
    1414//
    1515
     
    2323// Reduce includes by explicitly defining these routines.
    2424extern "C" {
    25         void * aalloc( size_t dim, size_t elemSize );           // CFA heap
    26         void * resize( void * oaddr, size_t size );                     // CFA heap
    2725        void * memalign( size_t align, size_t size );           // malloc.h
    28         void * amemalign( size_t align, size_t dim, size_t elemSize ); // CFA heap
    29         void * cmemalign( size_t align, size_t noOfElems, size_t elemSize ); // CFA heap
     26        size_t malloc_usable_size( void * ptr );                        // malloc.h
    3027        size_t malloc_size( void * addr );                                      // CFA heap
    31         size_t malloc_usable_size( void * ptr );                        // malloc.h
     28        void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA heap
    3229        void * memset( void * dest, int fill, size_t size ); // string.h
    3330        void * memcpy( void * dest, const void * src, size_t size ); // string.h
     31        void * resize( void * oaddr, size_t size );                     // CFA heap
    3432} // extern "C"
    3533
     
    5452        } // malloc
    5553
    56         T * aalloc( size_t dim ) {
    57                 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)aalloc( dim, (size_t)sizeof(T) ); // CFA aalloc
    58                 else return (T *)amemalign( _Alignof(T), dim, sizeof(T) );
    59         } // aalloc
    60 
    6154        T * calloc( size_t dim ) {
    6255                if ( _Alignof(T) <= libAlign() )return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc
     
    6457        } // calloc
    6558
    66         T * resize( T * ptr, size_t size ) {                            // CFA realloc, eliminate return-type cast
    67                 return (T *)(void *)resize( (void *)ptr, size ); // C realloc
    68         } // resize
    69 
    7059        T * realloc( T * ptr, size_t size ) {                           // CFA realloc, eliminate return-type cast
    7160                return (T *)(void *)realloc( (void *)ptr, size ); // C realloc
     
    7665        } // memalign
    7766
    78         T * amemalign( size_t align, size_t dim ) {
    79                 return (T *)amemalign( align, dim, sizeof(T) ); // CFA amemalign
    80         } // amemalign
    81 
    8267        T * cmemalign( size_t align, size_t dim  ) {
    8368                return (T *)cmemalign( align, dim, sizeof(T) ); // CFA cmemalign
     
    10186
    10287        T * alloc( size_t dim ) {
    103                 return aalloc( dim );
     88                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) );
     89                else return (T *)memalign( _Alignof(T), dim * sizeof(T) );
    10490        } // alloc
    10591
     
    120106                        return (T *)(void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
    121107                } else {
    122                         return resize( ptr, dim * sizeof(T) );          // resize
     108                        struct __Unknown {};
     109                        return alloc( (__Unknown *)ptr, dim );          // reuse, cheat making T/S different types
    123110                } // if
    124111        } // alloc
     
    161148        } // alloc_align
    162149
    163         T * alloc_align( T * ptr, size_t align ) {                      // aligned realloc array
     150        T * alloc_align( T ptr[], size_t align ) {                      // aligned realloc array
    164151                return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc
    165152        } // alloc_align
  • tests/list/.expect/dlist-insert-remove.txt

    r7d6e01d r068a202  
    146414640.7
    14651465-
    1466 
    1467 ~~~~~~~~~~ End removal tests on Headed List: First ~~~~~~~~~~
    1468 
    1469 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1470 Test 16-i.  Modifying Freds on MINE
    1471 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1472 ==== fred by MINE before
    1473 1.7
    1474 2.7
    1475 3.7
    1476 -
    1477 1.7
    1478 -
    1479 3.7
    1480 -
    1481 3.7
    1482 2.7
    1483 1.7
    1484 -
    1485 ==== fred by YOURS before
    1486 1.7
    1487 2.7
    1488 3.7
    1489 -
    1490 1.7
    1491 -
    1492 3.7
    1493 -
    1494 3.7
    1495 2.7
    1496 1.7
    1497 -
    1498 ==== fred by MINE after
    1499 2.7
    1500 3.7
    1501 -
    1502 2.7
    1503 -
    1504 3.7
    1505 -
    1506 3.7
    1507 2.7
    1508 -
    1509 ==== fred by YOURS after
    1510 1.7
    1511 2.7
    1512 3.7
    1513 -
    1514 1.7
    1515 -
    1516 3.7
    1517 -
    1518 3.7
    1519 2.7
    1520 1.7
    1521 -
    1522 ==== fred by MINE after
    1523 1.7
    1524 -
    1525 1.7
    1526 -
    1527 -
    1528 -
    1529 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1530 Test 16-ii.  Modifying Freds on YOURS
    1531 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1532 ==== fred by MINE before
    1533 1.7
    1534 2.7
    1535 3.7
    1536 -
    1537 1.7
    1538 -
    1539 3.7
    1540 -
    1541 3.7
    1542 2.7
    1543 1.7
    1544 -
    1545 ==== fred by YOURS before
    1546 1.7
    1547 2.7
    1548 3.7
    1549 -
    1550 1.7
    1551 -
    1552 3.7
    1553 -
    1554 3.7
    1555 2.7
    1556 1.7
    1557 -
    1558 ==== fred by MINE after
    1559 1.7
    1560 2.7
    1561 3.7
    1562 -
    1563 1.7
    1564 -
    1565 3.7
    1566 -
    1567 3.7
    1568 2.7
    1569 1.7
    1570 -
    1571 ==== fred by YOURS after
    1572 2.7
    1573 3.7
    1574 -
    1575 2.7
    1576 -
    1577 3.7
    1578 -
    1579 3.7
    1580 2.7
    1581 -
    1582 ==== fred by YOURS after
    1583 1.7
    1584 -
    1585 1.7
    1586 -
    1587 -
    1588 -
    1589 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1590 Test 16-iii.  Modifying Maries
    1591 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1592 ==== mary before
    1593 1.7
    1594 2.7
    1595 3.7
    1596 -
    1597 1.7
    1598 -
    1599 3.7
    1600 -
    1601 3.7
    1602 2.7
    1603 1.7
    1604 -
    1605 ==== mary after
    1606 2.7
    1607 3.7
    1608 -
    1609 2.7
    1610 -
    1611 3.7
    1612 -
    1613 3.7
    1614 2.7
    1615 -
    1616 ==== mary after
    1617 1.7
    1618 -
    1619 1.7
    1620 -
    1621 -
    1622 -
    1623 
    1624 ~~~~~~~~~~ End removal tests on Headed List: Last ~~~~~~~~~~
    1625 
    1626 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1627 Test 17-i.  Modifying Freds on MINE
    1628 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1629 ==== fred by MINE before
    1630 1.7
    1631 2.7
    1632 3.7
    1633 -
    1634 1.7
    1635 -
    1636 3.7
    1637 -
    1638 3.7
    1639 2.7
    1640 1.7
    1641 -
    1642 ==== fred by YOURS before
    1643 1.7
    1644 2.7
    1645 3.7
    1646 -
    1647 1.7
    1648 -
    1649 3.7
    1650 -
    1651 3.7
    1652 2.7
    1653 1.7
    1654 -
    1655 ==== fred by MINE after
    1656 1.7
    1657 2.7
    1658 -
    1659 1.7
    1660 -
    1661 2.7
    1662 -
    1663 2.7
    1664 1.7
    1665 -
    1666 ==== fred by YOURS after
    1667 1.7
    1668 2.7
    1669 3.7
    1670 -
    1671 1.7
    1672 -
    1673 3.7
    1674 -
    1675 3.7
    1676 2.7
    1677 1.7
    1678 -
    1679 ==== fred by MINE after
    1680 3.7
    1681 -
    1682 3.7
    1683 -
    1684 -
    1685 -
    1686 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1687 Test 17-ii.  Modifying Freds on YOURS
    1688 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1689 ==== fred by MINE before
    1690 1.7
    1691 2.7
    1692 3.7
    1693 -
    1694 1.7
    1695 -
    1696 3.7
    1697 -
    1698 3.7
    1699 2.7
    1700 1.7
    1701 -
    1702 ==== fred by YOURS before
    1703 1.7
    1704 2.7
    1705 3.7
    1706 -
    1707 1.7
    1708 -
    1709 3.7
    1710 -
    1711 3.7
    1712 2.7
    1713 1.7
    1714 -
    1715 ==== fred by MINE after
    1716 1.7
    1717 2.7
    1718 3.7
    1719 -
    1720 1.7
    1721 -
    1722 3.7
    1723 -
    1724 3.7
    1725 2.7
    1726 1.7
    1727 -
    1728 ==== fred by YOURS after
    1729 1.7
    1730 2.7
    1731 -
    1732 1.7
    1733 -
    1734 2.7
    1735 -
    1736 2.7
    1737 1.7
    1738 -
    1739 ==== fred by YOURS after
    1740 3.7
    1741 -
    1742 3.7
    1743 -
    1744 -
    1745 -
    1746 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1747 Test 17-iii.  Modifying Maries
    1748 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1749 ==== mary before
    1750 1.7
    1751 2.7
    1752 3.7
    1753 -
    1754 1.7
    1755 -
    1756 3.7
    1757 -
    1758 3.7
    1759 2.7
    1760 1.7
    1761 -
    1762 ==== mary after
    1763 1.7
    1764 2.7
    1765 -
    1766 1.7
    1767 -
    1768 2.7
    1769 -
    1770 2.7
    1771 1.7
    1772 -
    1773 ==== mary after
    1774 3.7
    1775 -
    1776 3.7
    1777 -
    1778 -
    1779 -
  • tests/list/dlist-insert-remove.cfa

    r7d6e01d r068a202  
    11871187////////////////////////////////////////////////////////////
    11881188//
    1189 // Section 4f
    1190 //
    1191 // Test cases of pop_first, pop_last
    1192 //
    1193 // Example of call-side user code
    1194 //
    1195 ////////////////////////////////////////////////////////////
    1196 
    1197 // These cases assume element removal at first-last is correct
    1198 
    1199 void test__pop_first__fred_mine() {
    1200 
    1201         fred f1 = {1.7};
    1202         fred f2 = {2.7};
    1203         fred f3 = {3.7};
    1204 
    1205         dlist(fred_in_mine, fred) flm;
    1206         insert_last(flm, f1);
    1207         insert_last(flm, f2);
    1208         insert_last(flm, f3);
    1209 
    1210         dlist(fred_in_yours, fred) fly;
    1211         insert_last(fly, f1);
    1212         insert_last(fly, f2);
    1213         insert_last(fly, f3);
    1214 
    1215         printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1216         printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1217 
    1218         verify(validate(fly));
    1219         verify(validate(flm));
    1220 
    1221         fred & popped = pop_first(flm);
    1222 
    1223         verify(validate(fly));
    1224         verify(validate(flm));
    1225 
    1226         printMyFreddies(flm`first, flm`last, 0);     // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
    1227         printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
    1228 
    1229         // observe f1 is now solo in mine; in yours, it was just traversed
    1230         printMyFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
    1231 
    1232         assert( &popped == & f1 );
    1233 }
    1234 
    1235 void test__pop_first__fred_yours() {
    1236 
    1237         fred f1 = {1.7};
    1238         fred f2 = {2.7};
    1239         fred f3 = {3.7};
    1240 
    1241         dlist(fred_in_mine, fred) flm;
    1242         insert_last(flm, f1);
    1243         insert_last(flm, f2);
    1244         insert_last(flm, f3);
    1245 
    1246         dlist(fred_in_yours, fred) fly;
    1247         insert_last(fly, f1);
    1248         insert_last(fly, f2);
    1249         insert_last(fly, f3);
    1250 
    1251         printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1252         printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1253 
    1254         verify(validate(fly));
    1255         verify(validate(flm));
    1256 
    1257         fred & popped = pop_first(fly);
    1258 
    1259         verify(validate(fly));
    1260         verify(validate(flm));
    1261 
    1262         printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
    1263         printYourFreddies(fly`first, fly`last, 0);   // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
    1264 
    1265         // observe f1 is now solo in yours; in mine, it was just traversed
    1266         printYourFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
    1267 
    1268         assert( &popped == &f1 );
    1269 }
    1270 
    1271 void test__pop_first__maries() {
    1272 
    1273         mary m1 = {1.7};
    1274         mary m2 = {2.7};
    1275         mary m3 = {3.7};
    1276 
    1277         dlist(mary, mary) ml;
    1278         insert_last(ml, m1);
    1279         insert_last(ml, m2);
    1280         insert_last(ml, m3);
    1281 
    1282         printMariatheotokos(ml`first, ml`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1283 
    1284         verify(validate(ml));
    1285 
    1286         mary & popped = pop_first(ml);
    1287 
    1288         verify(validate(ml));
    1289 
    1290         printMariatheotokos(ml`first, ml`last, 0);     // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
    1291 
    1292         // observe m1 is now solo
    1293         printMariatheotokos(m1, *0p, 0);               // 1.7; 1.7; ;
    1294 
    1295         assert( &popped == &m1 );
    1296 }
    1297 
    1298 void test__pop_last__fred_mine() {
    1299 
    1300         fred f1 = {1.7};
    1301         fred f2 = {2.7};
    1302         fred f3 = {3.7};
    1303 
    1304         dlist(fred_in_mine, fred) flm;
    1305         insert_last(flm, f1);
    1306         insert_last(flm, f2);
    1307         insert_last(flm, f3);
    1308 
    1309         dlist(fred_in_yours, fred) fly;
    1310         insert_last(fly, f1);
    1311         insert_last(fly, f2);
    1312         insert_last(fly, f3);
    1313 
    1314         printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1315         printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1316 
    1317         verify(validate(fly));
    1318         verify(validate(flm));
    1319 
    1320         fred & popped = pop_last(flm);
    1321 
    1322         verify(validate(fly));
    1323         verify(validate(flm));
    1324 
    1325         printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
    1326         printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
    1327 
    1328         // observe f3 is now solo in mine; in yours, it was just traversed
    1329         printMyFreddies(f3, *0p, 0);    // 3.7; 3.7; ;
    1330 
    1331         assert( &popped == & f3 );
    1332 }
    1333 
    1334 void test__pop_last__fred_yours() {
    1335 
    1336         fred f1 = {1.7};
    1337         fred f2 = {2.7};
    1338         fred f3 = {3.7};
    1339 
    1340         dlist(fred_in_mine, fred) flm;
    1341         insert_last(flm, f1);
    1342         insert_last(flm, f2);
    1343         insert_last(flm, f3);
    1344 
    1345         dlist(fred_in_yours, fred) fly;
    1346         insert_last(fly, f1);
    1347         insert_last(fly, f2);
    1348         insert_last(fly, f3);
    1349 
    1350         printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1351         printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1352 
    1353         verify(validate(fly));
    1354         verify(validate(flm));
    1355 
    1356         fred & popped = pop_last(fly);
    1357 
    1358         verify(validate(fly));
    1359         verify(validate(flm));
    1360 
    1361         printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
    1362         printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
    1363 
    1364         // observe f3 is now solo in yours; in mine, it was just traversed
    1365         printYourFreddies(f3, *0p, 0);    // 3.7; 3.7; ;
    1366 
    1367         assert( &popped == & f3 );
    1368 }
    1369 
    1370 void test__pop_last__maries() {
    1371 
    1372         mary m1 = {1.7};
    1373         mary m2 = {2.7};
    1374         mary m3 = {3.7};
    1375 
    1376         dlist(mary, mary) ml;
    1377         insert_last(ml, m1);
    1378         insert_last(ml, m2);
    1379         insert_last(ml, m3);
    1380 
    1381         printMariatheotokos(ml`first, ml`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
    1382 
    1383         verify(validate(ml));
    1384 
    1385         mary & popped = pop_last(ml);
    1386 
    1387         verify(validate(ml));
    1388 
    1389         printMariatheotokos(ml`first, ml`last, 0);     // 1.7, 1.7;       1.7;  2.7;  2.7, 1.7      (modified)
    1390 
    1391         // observe m1 is now solo
    1392         printMariatheotokos(m3, *0p, 0);               // 3.7; 3.7; ;
    1393 
    1394         assert( &popped == &m3 );
    1395 }
    1396 
    1397 ////////////////////////////////////////////////////////////
    1398 //
    13991189// Section 5
    14001190//
     
    16321422        test__remove_of_sole__mary();
    16331423
    1634         sout | "";
    1635         sout | "~~~~~~~~~~ End removal tests on Headed List: First ~~~~~~~~~~";
    1636         sout | "";
    1637 
    1638         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1639         sout | "Test 16-i.  Modifying Freds on MINE";
    1640         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1641         test__pop_first__fred_mine();
    1642 
    1643         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1644         sout | "Test 16-ii.  Modifying Freds on YOURS";
    1645         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1646         test__pop_first__fred_yours();
    1647 
    1648         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1649         sout | "Test 16-iii.  Modifying Maries";
    1650         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1651         test__pop_first__maries();
    1652 
    1653         sout | "";
    1654         sout | "~~~~~~~~~~ End removal tests on Headed List: Last ~~~~~~~~~~";
    1655         sout | "";
    1656 
    1657         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1658         sout | "Test 17-i.  Modifying Freds on MINE";
    1659         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1660         test__pop_last__fred_mine();
    1661 
    1662         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1663         sout | "Test 17-ii.  Modifying Freds on YOURS";
    1664         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1665         test__pop_last__fred_yours();
    1666 
    1667         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1668         sout | "Test 17-iii.  Modifying Maries";
    1669         sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    1670         test__pop_last__maries();
    1671 
    16721424        return 0;
    16731425}
Note: See TracChangeset for help on using the changeset viewer.