Changeset 97392b69 for libcfa/src
- Timestamp:
- Jun 10, 2020, 4:19:30 PM (4 years ago)
- 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. - Location:
- libcfa/src
- Files:
-
- 4 added
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
ra5873bd r97392b69 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Sun May 17 21:10:26202014 ## Update Count : 24 313 ## Last Modified On : Mon Jun 1 13:35:33 2020 14 ## Update Count : 248 15 15 ############################################################################### 16 16 … … 39 39 #---------------------------------------------------------------------------------------------------------------- 40 40 if 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 41 headers_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 43 headers = 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 45 46 46 libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa${headers:.hfa=.cfa}47 libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c ${headers:.hfa=.cfa} 47 48 48 49 # not all platforms support concurrency, add option do disable it -
libcfa/src/Makefile.in
ra5873bd r97392b69 139 139 libcfa_la_LIBADD = 140 140 am__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 \ 145 145 containers/vector.cfa 146 146 am__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 \ 150 150 @BUILDLIB_TRUE@ containers/pair.lo containers/result.lo \ 151 151 @BUILDLIB_TRUE@ containers/vector.lo 152 152 @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 \ 154 154 @BUILDLIB_TRUE@ $(am__objects_1) 155 155 am_libcfa_la_OBJECTS = prelude.lo $(am__objects_2) … … 237 237 esac 238 238 am__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 \ 244 245 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 248 250 HEADERS = $(nobase_cfa_include_HEADERS) 249 251 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) … … 465 467 466 468 #---------------------------------------------------------------------------------------------------------------- 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 469 471 470 472 @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 \ 472 475 @BUILDLIB_TRUE@ containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa 473 476 474 477 @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} 476 479 @BUILDLIB_FALSE@thread_headers_nosrc = 477 480 -
libcfa/src/bitmanip.hfa
ra5873bd r97392b69 11 11 // Created On : Sat Mar 14 18:12:27 2020 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sun Apr 19 22:29:58202014 // Update Count : 12 113 // Last Modified On : Tue Jun 9 15:14:04 2020 14 // Update Count : 123 15 15 // 16 16 … … 48 48 49 49 // Count all 0 bits. 50 unsigned int all0s( unsigned char n ) { return __b itsizeof(n) - __builtin_popcount(n ); }51 unsigned int all0s( unsigned short int n ) { return __b itsizeof(n) - __builtin_popcount(n ); }52 unsigned int all0s( unsigned int n ) { return __b itsizeof(n) - __builtin_popcount(n ); }53 unsigned int all0s( unsigned long int n ) { return __b itsizeof(n) - __builtin_popcountl(n ); }54 unsigned int all0s( unsigned long long int n ) { return __b itsizeof(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 ); } 55 55 56 56 // Find least significiant zero bit. (ffs) -
libcfa/src/concurrency/coroutine.cfa
ra5873bd r97392b69 10 10 // Created On : Mon Nov 28 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 4 12:29:25202013 // Update Count : 1612 // Last Modified On : Tue May 26 22:06:09 2020 13 // Update Count : 21 14 14 // 15 15 … … 18 18 #include "coroutine.hfa" 19 19 20 extern "C" {21 20 #include <stddef.h> 22 21 #include <malloc.h> … … 24 23 #include <string.h> 25 24 #include <unistd.h> 26 // use this define to make unwind.h play nice, definetely a hack 25 #include <sys/mman.h> // mprotect 26 extern "C" { 27 // use this define to make unwind.h play nice, definitely a hack 27 28 #define HIDE_EXPORTS 28 29 #include <unwind.h> 29 30 #undef HIDE_EXPORTS 30 #include <sys/mman.h>31 31 } 32 32 -
libcfa/src/concurrency/kernel.cfa
ra5873bd r97392b69 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 4 13:03:15202013 // Update Count : 5 812 // Last Modified On : Tue May 26 22:05:19 2020 13 // Update Count : 59 14 14 // 15 15 … … 21 21 #include <errno.h> 22 22 #include <string.h> 23 extern "C" {24 23 #include <stdio.h> 25 24 #include <fenv.h> 26 #include <sys/resource.h>27 25 #include <signal.h> 28 26 #include <unistd.h> 29 27 #include <limits.h> // PTHREAD_STACK_MIN 30 28 #include <sys/mman.h> // mprotect 29 extern "C" { 30 #include <sys/resource.h> 31 31 } 32 32 -
libcfa/src/containers/list.hfa
ra5873bd r97392b69 118 118 Telem& $tempcv_n2e(Tnode &); 119 119 Tnode& $tempcv_e2n(Telem &); 120 121 Telem& ?`next(Tnode &); 122 Telem& ?`prev(Tnode &); 120 123 }; 121 124 -
libcfa/src/executor.cfa
ra5873bd r97392b69 4 4 // buffer. 5 5 6 #include <thread.hfa> 6 7 #include <containers/list.hfa> 7 #include <thread.hfa>8 #include <stdio.h>9 8 10 struct WRequest { // client request, no return 11 void (* action)( void ); 12 DLISTED_MGD_IMPL_IN(WRequest) 9 forall( 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 29 struct WRequest { // client request, no return 30 void (* action)( void ); 31 DLISTED_MGD_IMPL_IN(WRequest) 13 32 }; // WRequest 14 33 DLISTED_MGD_IMPL_OUT(WRequest) … … 19 38 void doit( WRequest & req ) { req.action(); } 20 39 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. 38 42 39 43 thread Worker { 40 WRBuffer * requests; 41 unsigned int start, range; 44 Buffer(WRequest) * requests; 45 WRequest * request; 46 unsigned int start, range; 42 47 }; // Worker 43 48 44 49 void main( Worker & w ) with(w) { 45 46 WRequest *request = remove( requests[i + start] );47 48 49 doit( *request );50 delete( request );51 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 52 57 } // Worker::main 53 58 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];59 void ?{}( 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]; 57 62 } // ?{} 58 63 64 WRequest * current_request( Worker & worker ) { return worker.request; } 65 59 66 struct 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 66 74 }; // Executor 67 75 68 static thread_local unsigned int next; // demultiplexed across worker buffers69 76 unsigned int tickets( Executor & ex ) with(ex) { 70 //return uFetchAdd( next, 1 ) % nmailboxes;71 return next++ % nmailboxes;// no locking, interference randomizes77 //return uFetchAdd( next, 1 ) % nrqueues; 78 return next++ % nrqueues; // no locking, interference randomizes 72 79 } // tickets 73 80 74 void ?{}( Executor & ex, unsigned int np, unsigned int nw, unsigned int n m, bool sc = false ) with(ex) {75 [nprocessors, nworkers, nmailboxes, sepClus] = [np, nw, nm, sc];76 assert( nmailboxes >= nworkers );77 78 processors = (processor **)anew( nprocessors );79 requests = (WRBuffer *)anew( nmailboxes );80 workers = (Worker **)anew( nworkers );81 void ?{}( 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 ); 81 88 82 83 processors[ i] = new( *cluster );84 89 for ( i; nprocessors ) { 90 processors[i] = new( *cluster ); 91 } // for 85 92 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 90 99 } // ?{} 91 100 92 101 void ?{}( Executor & ex, unsigned int nprocessors, unsigned int nworkers, bool sepClus = false ) { 93 102 ex{ nprocessors, nworkers, nworkers, sepClus }; 94 103 } 95 104 void ?{}( Executor & ex, unsigned int nprocessors, bool sepClus = false ) { 96 105 ex{ nprocessors, nprocessors, nprocessors, sepClus }; 97 106 } 98 void ?{}( Executor & ex ) { // special for current cluster99 107 void ?{}( Executor & ex ) { // special for current cluster, no processors added 108 ex{ 0, active_cluster()->nprocessors, false }; 100 109 } 101 110 void ^?{}( Executor & ex ) with(ex) { 102 // Add one sentinel per worker to stop them. Since in destructor, no new work should be queued. Cannot combine next103 // 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. 105 114 106 107 unsigned int reqPerWorker = nmailboxes / nworkers;108 109 insert( requests[step], &sentinel[i] );// force eventually termination110 111 112 delete( workers[ i] );113 114 115 delete( processors[ i] );116 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 117 126 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 ); } 122 133 } // ^?{} 123 134 124 135 void send( Executor & ex, void (* action)( void ) ) { // asynchronous call, no return value 125 126 136 WRequest * node = new( action ); 137 insert( ex.requests[tickets( ex )], node ); 127 138 } // send 139 128 140 129 141 int counter = 0; 130 142 131 void work ie( void ) {132 133 //fprintf( stderr, "workie\n" );143 void work( void ) { 144 __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST ); 145 // fprintf( stderr, "workie\n" ); 134 146 } 135 147 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 } // for146 147 148 int 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 ); 148 160 } 149 161 150 162 // Local Variables: // 163 // tab-width: 4" // 151 164 // compile-command: "cfa executor.cfa" // 152 165 // End: // -
libcfa/src/heap.cfa
ra5873bd r97392b69 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 20:58:17202013 // Update Count : 7 6212 // Last Modified On : Wed May 27 15:08:49 2020 13 // Update Count : 770 14 14 // 15 15 … … 20 20 #include <string.h> // memset, memcpy 21 21 #include <limits.h> // ULONG_MAX 22 extern "C" { 22 #include <malloc.h> // memalign, malloc_usable_size 23 23 #include <sys/mman.h> // mmap, munmap 24 } // extern "C"25 24 26 25 #include "bits/align.hfa" // libPow2 … … 29 28 #include "startup.hfa" // STARTUP_PRIORITY_MEMORY 30 29 //#include "stdlib.hfa" // bsearchl 31 #include "malloc.h"32 30 #include "bitmanip.hfa" // ceiling 33 31 -
libcfa/src/stdhdr/malloc.h
ra5873bd r97392b69 10 10 // Created On : Thu Jul 20 15:58:16 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 16 22:44:06202013 // Update Count : 1 312 // Last Modified On : Wed May 27 14:13:14 2020 13 // Update Count : 18 14 14 // 15 16 17 size_t default_mmap_start(); // CFA extras18 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"41 15 42 16 extern "C" { 43 17 #include_next <malloc.h> // has internal check for multiple expansion 44 18 } // extern "C" 19 20 #include <heap.hfa> 45 21 46 22 // Local Variables: // -
libcfa/src/stdlib.cfa
ra5873bd r97392b69 9 9 // Author : Peter A. Buhr 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Apr 16 22:43:33202013 // Update Count : 49811 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 2 16:46:00 2020 13 // Update Count : 500 14 14 // 15 15 … … 78 78 } // new 79 79 80 forall( dtype T | sized(T) |{ void ^?{}( T & ); } )80 forall( dtype T | { void ^?{}( T & ); } ) 81 81 void delete( T * ptr ) { 82 82 if ( ptr ) { // ignore null … … 86 86 } // delete 87 87 88 forall( dtype T, ttype Params | sized(T) |{ void ^?{}( T & ); void delete( Params ); } )88 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) 89 89 void delete( T * ptr, Params rest ) { 90 if ( ptr ) { // ignore null 91 ^(*ptr){}; // run destructor 92 free( ptr ); 93 } // if 90 delete( ptr ); 94 91 delete( rest ); 95 92 } // delete … … 277 274 extern "C" { // override C version 278 275 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 280 277 } // extern "C" 281 278 -
libcfa/src/stdlib.hfa
ra5873bd r97392b69 9 9 // Author : Peter A. Buhr 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed May 13 17:23:51202013 // Update Count : 4 3511 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 2 16:47:00 2020 13 // Update Count : 451 14 14 // 15 15 … … 20 20 21 21 #include <stdlib.h> // *alloc, strto*, ato* 22 #include <heap.hfa> 22 23 23 24 // Reduce includes by explicitly defining these routines. 24 25 extern "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 32 28 void * memset( void * dest, int fill, size_t size ); // string.h 33 29 void * memcpy( void * dest, const void * src, size_t size ); // string.h 34 30 } // extern "C" 35 36 void * resize( void * oaddr, size_t nalign, size_t size ); // CFA heap37 void * realloc( void * oaddr, size_t nalign, size_t size ); // CFA heap38 31 39 32 //--------------------------------------- … … 91 84 return posix_memalign( (void **)ptr, align, sizeof(T) ); // C posix_memalign 92 85 } // 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 93 94 } // distribution 94 95 … … 228 229 // Cforall allocation/deallocation and constructor/destructor, non-array types 229 230 forall( 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 );231 forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr ); 232 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest ); 232 233 233 234 // Cforall allocation/deallocation and constructor/destructor, array types … … 300 301 extern "C" { // override C version 301 302 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; 303 305 } // extern "C" 304 306 … … 307 309 long int random( long int u ) { if ( u < 0 ) return random( u, 0 ); else return random( 0, u ); } // [0,u) 308 310 unsigned long int random( void ) { return lrand48(); } 311 unsigned long int random( unsigned long int u ) { return lrand48() % u; } // [0,u) 309 312 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)311 313 312 314 char random( void ) { return (unsigned long int)random(); }
Note: See TracChangeset
for help on using the changeset viewer.