Changeset 97392b69 for libcfa


Ignore:
Timestamp:
Jun 10, 2020, 4:19:30 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
ab8a023
Parents:
a5873bd (diff), ee06db5c (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' into relaxed_ready

Location:
libcfa/src
Files:
4 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    ra5873bd r97392b69  
    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 Jun  1 13:35:33 2020
     14## Update Count     : 248
    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
    43 headers = 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
     41headers_nosrc = bitmanip.hfa exception.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 containers/stackLockFree.hfa
     43headers = common.hfa fstream.hfa heap.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa \
     44                time.hfa stdlib.hfa memory.hfa \
     45                containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa
    4546
    46 libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa ${headers:.hfa=.cfa}
     47libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c ${headers:.hfa=.cfa}
    4748
    4849# not all platforms support concurrency, add option do disable it
  • libcfa/src/Makefile.in

    ra5873bd r97392b69  
    139139libcfa_la_LIBADD =
    140140am__libcfa_la_SOURCES_DIST = prelude.cfa startup.cfa interpose.cfa \
    141         bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa \
    142         fstream.cfa iostream.cfa iterator.cfa limits.cfa rational.cfa \
    143         time.cfa stdlib.cfa common.cfa containers/maybe.cfa \
    144         containers/pair.cfa containers/result.cfa \
     141        bits/debug.cfa assert.cfa exception.c virtual.c common.cfa \
     142        fstream.cfa heap.cfa iostream.cfa iterator.cfa limits.cfa \
     143        rational.cfa time.cfa stdlib.cfa memory.cfa \
     144        containers/maybe.cfa containers/pair.cfa containers/result.cfa \
    145145        containers/vector.cfa
    146146am__dirstamp = $(am__leading_dot)dirstamp
    147 @BUILDLIB_TRUE@am__objects_1 = fstream.lo iostream.lo iterator.lo \
    148 @BUILDLIB_TRUE@ limits.lo rational.lo time.lo stdlib.lo \
    149 @BUILDLIB_TRUE@ common.lo containers/maybe.lo \
     147@BUILDLIB_TRUE@am__objects_1 = common.lo fstream.lo heap.lo \
     148@BUILDLIB_TRUE@ iostream.lo iterator.lo limits.lo rational.lo \
     149@BUILDLIB_TRUE@ time.lo stdlib.lo memory.lo containers/maybe.lo \
    150150@BUILDLIB_TRUE@ containers/pair.lo containers/result.lo \
    151151@BUILDLIB_TRUE@ containers/vector.lo
    152152@BUILDLIB_TRUE@am__objects_2 = startup.lo interpose.lo bits/debug.lo \
    153 @BUILDLIB_TRUE@ assert.lo exception.lo virtual.lo heap.lo \
     153@BUILDLIB_TRUE@ assert.lo exception.lo virtual.lo \
    154154@BUILDLIB_TRUE@ $(am__objects_1)
    155155am_libcfa_la_OBJECTS = prelude.lo $(am__objects_2)
     
    237237  esac
    238238am__nobase_cfa_include_HEADERS_DIST = $(shell find $(srcdir)/stdhdr \
    239         -type f -printf "%p ") fstream.hfa iostream.hfa iterator.hfa \
    240         limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \
    241         containers/maybe.hfa containers/pair.hfa containers/result.hfa \
    242         containers/vector.hfa bitmanip.hfa math.hfa gmp.hfa time_t.hfa \
    243         clock.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa \
     239        -type f -printf "%p ") common.hfa fstream.hfa heap.hfa \
     240        iostream.hfa iterator.hfa limits.hfa rational.hfa time.hfa \
     241        stdlib.hfa memory.hfa containers/maybe.hfa containers/pair.hfa \
     242        containers/result.hfa containers/vector.hfa bitmanip.hfa \
     243        exception.hfa math.hfa gmp.hfa time_t.hfa clock.hfa \
     244        bits/align.hfa bits/containers.hfa bits/defs.hfa \
    244245        bits/debug.hfa bits/locks.hfa containers/list.hfa \
    245         concurrency/coroutine.hfa concurrency/thread.hfa \
    246         concurrency/kernel.hfa concurrency/monitor.hfa \
    247         concurrency/mutex.hfa concurrency/invoke.h
     246        containers/stackLockFree.hfa concurrency/coroutine.hfa \
     247        concurrency/thread.hfa concurrency/kernel.hfa \
     248        concurrency/monitor.hfa concurrency/mutex.hfa \
     249        concurrency/invoke.h
    248250HEADERS = $(nobase_cfa_include_HEADERS)
    249251am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
     
    465467
    466468#----------------------------------------------------------------------------------------------------------------
    467 @BUILDLIB_TRUE@headers_nosrc = bitmanip.hfa math.hfa gmp.hfa time_t.hfa clock.hfa \
    468 @BUILDLIB_TRUE@         bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa containers/list.hfa
     469@BUILDLIB_TRUE@headers_nosrc = bitmanip.hfa exception.hfa math.hfa gmp.hfa time_t.hfa clock.hfa \
     470@BUILDLIB_TRUE@         bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa containers/list.hfa containers/stackLockFree.hfa
    469471
    470472@BUILDLIB_FALSE@headers =
    471 @BUILDLIB_TRUE@headers = fstream.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \
     473@BUILDLIB_TRUE@headers = common.hfa fstream.hfa heap.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa \
     474@BUILDLIB_TRUE@         time.hfa stdlib.hfa memory.hfa \
    472475@BUILDLIB_TRUE@         containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa
    473476
    474477@BUILDLIB_FALSE@libsrc =
    475 @BUILDLIB_TRUE@libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa ${headers:.hfa=.cfa}
     478@BUILDLIB_TRUE@libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c ${headers:.hfa=.cfa}
    476479@BUILDLIB_FALSE@thread_headers_nosrc =
    477480
  • libcfa/src/bitmanip.hfa

    ra5873bd r97392b69  
    1111// Created On       : Sat Mar 14 18:12:27 2020
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sun Apr 19 22:29:58 2020
    14 // Update Count     : 121
     13// Last Modified On : Tue Jun  9 15:14:04 2020
     14// Update Count     : 123
    1515//
    1616
     
    4848
    4949        // Count all 0 bits.
    50         unsigned int all0s( unsigned char n ) { return __bitsizeof(n) - __builtin_popcount( n ); }
    51         unsigned int all0s( unsigned short int n ) { return __bitsizeof(n) - __builtin_popcount( n ); }
    52         unsigned int all0s( unsigned int n ) { return __bitsizeof(n) - __builtin_popcount( n ); }
    53         unsigned int all0s( unsigned long int n ) { return __bitsizeof(n) - __builtin_popcountl( n ); }
    54         unsigned int all0s( unsigned long long int n ) { return __bitsizeof(n) - __builtin_popcountll( n ); }
     50        unsigned int all0s( unsigned char n ) { return __builtin_popcount( (typeof(n))~n ); }
     51        unsigned int all0s( unsigned short int n ) { return __builtin_popcount( (typeof(n))~n ); }
     52        unsigned int all0s( unsigned int n ) { return __builtin_popcount( ~n ); }
     53        unsigned int all0s( unsigned long int n ) { return __builtin_popcountl( ~n ); }
     54        unsigned int all0s( unsigned long long int n ) { return __builtin_popcountll( ~n ); }
    5555
    5656        // Find least significiant zero bit. (ffs)
  • libcfa/src/concurrency/coroutine.cfa

    ra5873bd r97392b69  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  4 12:29:25 2020
    13 // Update Count     : 16
     12// Last Modified On : Tue May 26 22:06:09 2020
     13// Update Count     : 21
    1414//
    1515
     
    1818#include "coroutine.hfa"
    1919
    20 extern "C" {
    2120#include <stddef.h>
    2221#include <malloc.h>
     
    2423#include <string.h>
    2524#include <unistd.h>
    26 // use this define to make unwind.h play nice, definetely a hack
     25#include <sys/mman.h>                                                                   // mprotect
     26extern "C" {
     27// use this define to make unwind.h play nice, definitely a hack
    2728#define HIDE_EXPORTS
    2829#include <unwind.h>
    2930#undef HIDE_EXPORTS
    30 #include <sys/mman.h>
    3131}
    3232
  • libcfa/src/concurrency/kernel.cfa

    ra5873bd r97392b69  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  4 13:03:15 2020
    13 // Update Count     : 58
     12// Last Modified On : Tue May 26 22:05:19 2020
     13// Update Count     : 59
    1414//
    1515
     
    2121#include <errno.h>
    2222#include <string.h>
    23 extern "C" {
    2423#include <stdio.h>
    2524#include <fenv.h>
    26 #include <sys/resource.h>
    2725#include <signal.h>
    2826#include <unistd.h>
    2927#include <limits.h>                                                                             // PTHREAD_STACK_MIN
    3028#include <sys/mman.h>                                                                   // mprotect
     29extern "C" {
     30#include <sys/resource.h>
    3131}
    3232
  • libcfa/src/containers/list.hfa

    ra5873bd r97392b69  
    118118        Telem& $tempcv_n2e(Tnode &);
    119119        Tnode& $tempcv_e2n(Telem &);
     120
     121        Telem& ?`next(Tnode &);
     122        Telem& ?`prev(Tnode &);
    120123};
    121124
  • libcfa/src/executor.cfa

    ra5873bd r97392b69  
    44// buffer.
    55
     6#include <thread.hfa>
    67#include <containers/list.hfa>
    7 #include <thread.hfa>
    8 #include <stdio.h>
    98
    10 struct WRequest {                                       // client request, no return
    11     void (* action)( void );
    12     DLISTED_MGD_IMPL_IN(WRequest)
     9forall( dtype T | $dlistable(T, T) ) {
     10        monitor Buffer {                                                                        // unbounded buffer
     11                dlist( T, T ) queue;                                                    // unbounded list of work requests
     12                condition delay;
     13        }; // Buffer
     14
     15        void insert( Buffer(T) & mutex buf, T * elem ) with(buf) {
     16                dlist( T, T ) * qptr = &queue;                                  // workaround https://cforall.uwaterloo.ca/trac/ticket/166
     17                insert_last( *qptr, *elem );                                    // insert element into buffer
     18                signal( delay );                                                                // restart
     19        } // insert
     20
     21        T * remove( Buffer(T) & mutex buf ) with(buf) {
     22                dlist( T, T ) * qptr = &queue;                                  // workaround https://cforall.uwaterloo.ca/trac/ticket/166
     23                // if ( (*qptr)`is_empty ) wait( delay );                       // no request to process ? => wait
     24          if ( (*qptr)`is_empty ) return 0p;                            // no request to process ? => wait
     25                return &pop_first( *qptr );
     26        } // remove
     27} // forall
     28
     29struct WRequest {                                                                               // client request, no return
     30        void (* action)( void );
     31        DLISTED_MGD_IMPL_IN(WRequest)
    1332}; // WRequest
    1433DLISTED_MGD_IMPL_OUT(WRequest)
     
    1938void doit( WRequest & req ) { req.action(); }
    2039
    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
    35 
    36 // Each worker has its own work buffer to reduce contention between client and server. Hence, work requests arrive and
    37 // are distributed into buffers in a roughly round-robin order.
     40// Each worker has its own set (when requests buffers > workers) of work buffers to reduce contention between client
     41// and server, where work requests arrive and are distributed into buffers in a roughly round-robin order.
    3842
    3943thread Worker {
    40     WRBuffer * requests;
    41     unsigned int start, range;
     44        Buffer(WRequest) * requests;
     45        WRequest * request;
     46        unsigned int start, range;
    4247}; // Worker
    4348
    4449void main( Worker & w ) with(w) {
    45     for ( int i = 0;; i = (i + 1) % range ) {
    46         WRequest * request = remove( requests[i + start] );
    47       if ( ! request ) { yield(); continue; }
    48       if ( stop( *request ) ) break;
    49         doit( *request );
    50         delete( request );
    51     } // for
     50        for ( int i = 0;; i = (i + 1) % range ) {
     51                request = remove( requests[i + start] );
     52          if ( ! request ) { yield(); continue; }
     53          if ( stop( *request ) ) break;
     54                doit( *request );
     55                delete( request );
     56        } // for
    5257} // Worker::main
    5358
    54 void ?{}( Worker & worker, cluster * wc, WRBuffer * requests, unsigned int start, unsigned int range ) {
    55     (*get_thread(worker)){ *wc };                       // create on given cluster
    56     worker.[requests, start, range] = [requests, start, range];
     59void ?{}( Worker & worker, cluster * wc, Buffer(WRequest) * requests, unsigned int start, unsigned int range ) {
     60        ((thread &)worker){ *wc };
     61        worker.[requests, request, start, range] = [requests, 0p, start, range];
    5762} // ?{}
    5863
     64WRequest * current_request( Worker & worker ) { return worker.request; }
     65
    5966struct Executor {
    60     cluster * cluster;                                  // if workers execute on separate cluster
    61     processor ** processors;                            // array of virtual processors adding parallelism for workers
    62     WRBuffer * requests;                                // list of work requests
    63     Worker ** workers;                                  // array of workers executing work requests
    64     unsigned int nprocessors, nworkers, nmailboxes;     // number of mailboxes/workers/processor tasks
    65     bool sepClus;                                       // use same or separate cluster for executor
     67        cluster * cluster;                                                                      // if workers execute on separate cluster
     68        processor ** processors;                                                        // array of virtual processors adding parallelism for workers
     69        Buffer(WRequest) * requests;                                            // list of work requests
     70        Worker ** workers;                                                                      // array of workers executing work requests
     71        unsigned int nprocessors, nworkers, nrqueues;           // number of processors/threads/request queues
     72        bool sepClus;                                                                           // use same or separate cluster for executor
     73        unsigned int next;                                                                      // demultiplexed across worker buffers
    6674}; // Executor
    6775
    68 static thread_local unsigned int next;                  // demultiplexed across worker buffers
    6976unsigned int tickets( Executor & ex ) with(ex) {
    70     //return uFetchAdd( next, 1 ) % nmailboxes;
    71     return next++ % nmailboxes;                         // no locking, interference randomizes
     77        //return uFetchAdd( next, 1 ) % nrqueues;
     78        return next++ % nrqueues;                                                       // no locking, interference randomizes
    7279} // tickets
    7380
    74 void ?{}( Executor & ex, unsigned int np, unsigned int nw, unsigned int nm, bool sc = false ) with(ex) {
    75     [nprocessors, nworkers, nmailboxes, sepClus] = [np, nw, nm, sc];
    76     assert( nmailboxes >= nworkers );
    77     cluster = sepClus ? new( "Executor" ) : active_cluster();
    78     processors = (processor **)anew( nprocessors );
    79     requests = (WRBuffer *)anew( nmailboxes );
    80     workers = (Worker **)anew( nworkers );
     81void ?{}( Executor & ex, unsigned int np, unsigned int nw, unsigned int nr, bool sc = false ) with(ex) {
     82        [nprocessors, nworkers, nrqueues, sepClus] = [np, nw, nr, sc];
     83        assert( nrqueues >= nworkers );
     84        cluster = sepClus ? new( "Executor" ) : active_cluster();
     85        processors = aalloc( nprocessors );
     86        requests = anew( nrqueues );
     87        workers = aalloc( nworkers );
    8188
    82     for ( i; nprocessors ) {
    83         processors[ i ] = new( *cluster );
    84     } // for
     89        for ( i; nprocessors ) {
     90                processors[i] = new( *cluster );
     91        } // for
    8592
    86     unsigned int reqPerWorker = nmailboxes / nworkers, extras = nmailboxes % nworkers;
    87     for ( unsigned int i = 0, step = 0; i < nworkers; i += 1, step += reqPerWorker + ( i < extras ? 1 : 0 ) ) {
    88         workers[ i ] = new( cluster, requests, step, reqPerWorker + ( i < extras ? 1 : 0 ) );
    89     } // for
     93        unsigned int reqPerWorker = nrqueues / nworkers, extras = nrqueues % nworkers;
     94//      for ( unsigned int i = 0, start = 0, range; i < nworkers; i += 1, start += range ) {
     95    for ( i; nworkers : start; 0u ~ @ ~ range : range; ) {
     96            range = reqPerWorker + ( i < extras ? 1 : 0 );
     97                workers[i] = new( cluster, requests, start, range );
     98        } // for
    9099} // ?{}
    91100
    92101void ?{}( Executor & ex, unsigned int nprocessors, unsigned int nworkers, bool sepClus = false ) {
    93     ex{ nprocessors, nworkers, nworkers, sepClus };
     102        ex{ nprocessors, nworkers, nworkers, sepClus };
    94103}
    95104void ?{}( Executor & ex, unsigned int nprocessors, bool sepClus = false ) {
    96     ex{ nprocessors, nprocessors, nprocessors, sepClus };
     105        ex{ nprocessors, nprocessors, nprocessors, sepClus };
    97106}
    98 void ?{}( Executor & ex ) {                             // special for current cluster
    99     ex{ 0, active_cluster()->nprocessors, false };
     107void ?{}( Executor & ex ) {                                                             // special for current cluster, no processors added
     108        ex{ 0, active_cluster()->nprocessors, false };
    100109}
    101110void ^?{}( Executor & ex ) with(ex) {
    102     // Add one sentinel per worker to stop them. Since in destructor, no new work should be queued.  Cannot combine next
    103     // two loops and only have a single sentinel because workers arrive in arbitrary order, so worker1 may take the
    104     // single sentinel while waiting for worker 0 to end.
     111        // Add one sentinel per worker to stop them. Since in destructor, no new external work should be queued.  Cannot
     112        // combine next two loops and only have a single sentinel because workers arrive in arbitrary order, so worker1 may
     113        // take the single sentinel while waiting for worker 0 to end.
    105114
    106     WRequest sentinel[nworkers];
    107     unsigned int reqPerWorker = nmailboxes / nworkers;
    108     for ( unsigned int i = 0, step = 0; i < nworkers; i += 1, step += reqPerWorker ) {
    109         insert( requests[step], &sentinel[i] );         // force eventually termination
    110     } // for
    111     for ( i; nworkers ) {
    112         delete( workers[ i ] );
    113     } // for
    114     for ( i; nprocessors ) {
    115         delete( processors[ i ] );
    116     } // for
     115        WRequest sentinel[nworkers];
     116        unsigned int reqPerWorker = nrqueues / nworkers;
     117        for ( unsigned int i = 0, step = 0; i < nworkers; i += 1, step += reqPerWorker ) {
     118                insert( requests[step], &sentinel[i] );                 // force eventually termination
     119        } // for
     120        for ( i; nworkers ) {
     121                delete( workers[i] );
     122        } // for
     123        for ( i; nprocessors ) {
     124                delete( processors[i] );
     125        } // for
    117126
    118     delete( workers );
    119     delete( requests );
    120     delete( processors );
    121     if ( sepClus ) { delete( cluster ); }
     127        free( workers );
     128//      adelete( nrqueues, requests );
     129        for ( i; nrqueues ) ^?{}( requests[i] );                        // FIX ME: problem with resolver
     130        free( requests );
     131        free( processors );
     132        if ( sepClus ) { delete( cluster ); }
    122133} // ^?{}
    123134
    124135void send( Executor & ex, void (* action)( void ) ) {   // asynchronous call, no return value
    125     WRequest * node = new( action );
    126     insert( ex.requests[tickets( ex )], node );
     136        WRequest * node = new( action );
     137        insert( ex.requests[tickets( ex )], node );
    127138} // send
     139
    128140
    129141int counter = 0;
    130142
    131 void workie( void ) {
    132     __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
    133 //    fprintf( stderr, "workie\n" );
     143void work( void ) {
     144        __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
     145        // fprintf( stderr, "workie\n" );
    134146}
    135147
    136 int main() {
    137     {
    138         Executor exector;
    139         for ( i; 3000 ) {
    140             send( exector, workie );
    141             if ( i % 100 == 0 ) {
    142 //              fprintf( stderr, "%d\n", i );
    143                 yield();
    144             }
    145         } // for
    146     }
    147     printf( "%d\n", counter );
     148int main( int argc, char * argv[] ) {
     149        int times = 1_000_000;
     150        if ( argc == 2 ) times = atoi( argv[1] );
     151        processor p[7];
     152        {
     153                Executor exector;
     154                for ( i; times ) {
     155                        send( exector, work );
     156                        if ( i % 100 == 0 ) yield();
     157                } // for
     158        }
     159        printf( "%d\n", counter );
    148160}
    149161
    150162// Local Variables: //
     163// tab-width: 4" //
    151164// compile-command: "cfa executor.cfa" //
    152165// End: //
  • libcfa/src/heap.cfa

    ra5873bd r97392b69  
    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 27 15:08:49 2020
     13// Update Count     : 770
    1414//
    1515
     
    2020#include <string.h>                                                                             // memset, memcpy
    2121#include <limits.h>                                                                             // ULONG_MAX
    22 extern "C" {
     22#include <malloc.h>                                                                             // memalign, malloc_usable_size
    2323#include <sys/mman.h>                                                                   // mmap, munmap
    24 } // extern "C"
    2524
    2625#include "bits/align.hfa"                                                               // libPow2
     
    2928#include "startup.hfa"                                                                  // STARTUP_PRIORITY_MEMORY
    3029//#include "stdlib.hfa"                                                                 // bsearchl
    31 #include "malloc.h"
    3230#include "bitmanip.hfa"                                                                 // ceiling
    3331
  • libcfa/src/stdhdr/malloc.h

    ra5873bd r97392b69  
    1010// Created On       : Thu Jul 20 15:58:16 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 16 22:44:06 2020
    13 // Update Count     : 13
     12// Last Modified On : Wed May 27 14:13:14 2020
     13// Update Count     : 18
    1414//
    15 
    16 
    17 size_t default_mmap_start();                                                    // CFA extras
    18 size_t default_heap_expansion();
    19 
    20 bool traceHeap();
    21 bool traceHeapOn();
    22 bool traceHeapOff();
    23 
    24 bool traceHeapTerm();
    25 bool traceHeapTermOn();
    26 bool traceHeapTermOff();
    27 
    28 bool checkFree();
    29 bool checkFreeOn();
    30 bool checkFreeOff();
    31 
    32 extern "C" {
    33 void * aalloc( size_t noOfElems, size_t elemSize );
    34 void * amemalign( size_t alignment, size_t noOfElems, size_t elemSize );
    35 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );
    36 size_t malloc_alignment( void * );
    37 bool malloc_zero_fill( void * );
    38 size_t malloc_size( void * );
    39 int malloc_stats_fd( int fd );
    40 } // extern "C"
    4115
    4216extern "C" {
    4317#include_next <malloc.h>                                                                // has internal check for multiple expansion
    4418} // extern "C"
     19
     20#include <heap.hfa>
    4521
    4622// Local Variables: //
  • libcfa/src/stdlib.cfa

    ra5873bd r97392b69  
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Jan 28 17:10:29 2016
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 16 22:43:33 2020
    13 // Update Count     : 498
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Jun  2 16:46:00 2020
     13// Update Count     : 500
    1414//
    1515
     
    7878} // new
    7979
    80 forall( dtype T | sized(T) | { void ^?{}( T & ); } )
     80forall( dtype T | { void ^?{}( T & ); } )
    8181void delete( T * ptr ) {
    8282        if ( ptr ) {                                                                            // ignore null
     
    8686} // delete
    8787
    88 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
     88forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } )
    8989void delete( T * ptr, Params rest ) {
    90         if ( ptr ) {                                                                            // ignore null
    91                 ^(*ptr){};                                                                              // run destructor
    92                 free( ptr );
    93         } // if
     90        delete( ptr );
    9491        delete( rest );
    9592} // delete
     
    277274extern "C" {                                                                                    // override C version
    278275        void srandom( unsigned int seed ) { srand48( (long int)seed ); }
    279         long int random( void ) { return mrand48(); }
     276        long int random( void ) { return mrand48(); }           // GENERATES POSITIVE AND NEGATIVE VALUES
    280277} // extern "C"
    281278
  • libcfa/src/stdlib.hfa

    ra5873bd r97392b69  
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Jan 28 17:12:35 2016
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 13 17:23:51 2020
    13 // Update Count     : 435
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Jun  2 16:47:00 2020
     13// Update Count     : 451
    1414//
    1515
     
    2020
    2121#include <stdlib.h>                                                                             // *alloc, strto*, ato*
     22#include <heap.hfa>
    2223
    2324// Reduce includes by explicitly defining these routines.
    2425extern "C" {
    25         void * aalloc( size_t dim, size_t elemSize );           // CFA heap
    26         void * resize( void * oaddr, size_t size );                     // CFA heap
    27         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
    30         size_t malloc_size( void * addr );                                      // CFA heap
    31         size_t malloc_usable_size( void * ptr );                        // malloc.h
     26        void * memalign( size_t alignment, size_t size );       // malloc.h
     27        void * pvalloc( size_t size );                                          // malloc.h
    3228        void * memset( void * dest, int fill, size_t size ); // string.h
    3329        void * memcpy( void * dest, const void * src, size_t size ); // string.h
    3430} // extern "C"
    35 
    36 void * resize( void * oaddr, size_t nalign, size_t size ); // CFA heap
    37 void * realloc( void * oaddr, size_t nalign, size_t size ); // CFA heap
    3831
    3932//---------------------------------------
     
    9184                return posix_memalign( (void **)ptr, align, sizeof(T) ); // C posix_memalign
    9285        } // posix_memalign
     86
     87        T * valloc( void ) {
     88                return (T *)valloc( sizeof(T) );                                // C valloc
     89        } // valloc
     90
     91        T * pvalloc( void ) {
     92                return (T *)pvalloc( sizeof(T) );                               // C pvalloc
     93        } // pvalloc
    9394} // distribution
    9495
     
    228229// Cforall allocation/deallocation and constructor/destructor, non-array types
    229230forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );
    230 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );
    231 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );
     231forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr );
     232forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );
    232233
    233234// Cforall allocation/deallocation and constructor/destructor, array types
     
    300301extern "C" {                                                                                    // override C version
    301302        void srandom( unsigned int seed );
    302         long int random( void );
     303        long int random( void );                                                        // GENERATES POSITIVE AND NEGATIVE VALUES
     304        // For positive values, use unsigned int, e.g., unsigned int r = random() % 100U;
    303305} // extern "C"
    304306
     
    307309        long int random( long int u ) { if ( u < 0 ) return random( u, 0 ); else return random( 0, u ); } // [0,u)
    308310        unsigned long int random( void ) { return lrand48(); }
     311        unsigned long int random( unsigned long int u ) { return lrand48() % u; } // [0,u)
    309312        unsigned long int random( unsigned long int l, unsigned long int u ) { if ( u < l ) [u, l] = [l, u]; return lrand48() % (u - l) + l; } // [l,u)
    310         unsigned long int random( unsigned long int u ) { return lrand48() % u; } // [0,u)
    311313
    312314        char random( void ) { return (unsigned long int)random(); }
Note: See TracChangeset for help on using the changeset viewer.