Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r032234bd r433905a  
    3636static bool traceHeap = false;
    3737
    38 inline bool traceHeap() libcfa_public { return traceHeap; }
    39 
    40 bool traceHeapOn() libcfa_public {
     38inline bool traceHeap() { return traceHeap; }
     39
     40bool traceHeapOn() {
    4141        bool temp = traceHeap;
    4242        traceHeap = true;
     
    4444} // traceHeapOn
    4545
    46 bool traceHeapOff() libcfa_public {
     46bool traceHeapOff() {
    4747        bool temp = traceHeap;
    4848        traceHeap = false;
     
    5050} // traceHeapOff
    5151
    52 bool traceHeapTerm() libcfa_public { return false; }
     52bool traceHeapTerm() { return false; }
    5353
    5454
    5555static bool prtFree = false;
    5656
    57 static bool prtFree() {
     57bool prtFree() {
    5858        return prtFree;
    5959} // prtFree
    6060
    61 static bool prtFreeOn() {
     61bool prtFreeOn() {
    6262        bool temp = prtFree;
    6363        prtFree = true;
     
    6565} // prtFreeOn
    6666
    67 static bool prtFreeOff() {
     67bool prtFreeOff() {
    6868        bool temp = prtFree;
    6969        prtFree = false;
     
    388388static unsigned int maxBucketsUsed;                                             // maximum number of buckets in use
    389389// extern visibility, used by runtime kernel
    390 // would be cool to remove libcfa_public but it's needed for libcfathread
    391 libcfa_public size_t __page_size;                                                       // architecture pagesize
    392 libcfa_public int __map_prot;                                                           // common mmap/mprotect protection
     390size_t __page_size;                                                                             // architecture pagesize
     391int __map_prot;                                                                                 // common mmap/mprotect protection
    393392
    394393
     
    728727
    729728
    730 static size_t prtFree( Heap & manager ) with( manager ) {
     729size_t prtFree( Heap & manager ) with( manager ) {
    731730        size_t total = 0;
    732731        #ifdef __STATISTICS__
     
    880879        // Allocates size bytes and returns a pointer to the allocated memory.  The contents are undefined. If size is 0,
    881880        // then malloc() returns a unique pointer value that can later be successfully passed to free().
    882         void * malloc( size_t size ) libcfa_public {
     881        void * malloc( size_t size ) {
    883882                #ifdef __STATISTICS__
    884883                if ( likely( size > 0 ) ) {
     
    895894
    896895        // Same as malloc() except size bytes is an array of dim elements each of elemSize bytes.
    897         void * aalloc( size_t dim, size_t elemSize ) libcfa_public {
     896        void * aalloc( size_t dim, size_t elemSize ) {
    898897                size_t size = dim * elemSize;
    899898                #ifdef __STATISTICS__
     
    911910
    912911        // Same as aalloc() with memory set to zero.
    913         void * calloc( size_t dim, size_t elemSize ) libcfa_public {
     912        void * calloc( size_t dim, size_t elemSize ) {
    914913                size_t size = dim * elemSize;
    915914          if ( unlikely( size ) == 0 ) {                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
     
    952951        // not 0p, then the call is equivalent to free(oaddr). Unless oaddr is 0p, it must have been returned by an earlier
    953952        // call to malloc(), alloc(), calloc() or realloc(). If the area pointed to was moved, a free(oaddr) is done.
    954         void * resize( void * oaddr, size_t size ) libcfa_public {
     953        void * resize( void * oaddr, size_t size ) {
    955954                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    956955          if ( unlikely( size == 0 ) ) {                                        // special cases
     
    997996        // Same as resize() but the contents are unchanged in the range from the start of the region up to the minimum of
    998997        // the old and new sizes.
    999         void * realloc( void * oaddr, size_t size ) libcfa_public {
     998        void * realloc( void * oaddr, size_t size ) {
    1000999                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    10011000          if ( unlikely( size == 0 ) ) {                                        // special cases
     
    10611060
    10621061        // Same as realloc() except the new allocation size is large enough for an array of nelem elements of size elsize.
    1063         void * reallocarray( void * oaddr, size_t dim, size_t elemSize ) libcfa_public {
     1062        void * reallocarray( void * oaddr, size_t dim, size_t elemSize ) {
    10641063                return realloc( oaddr, dim * elemSize );
    10651064        } // reallocarray
     
    10671066
    10681067        // Same as malloc() except the memory address is a multiple of alignment, which must be a power of two. (obsolete)
    1069         void * memalign( size_t alignment, size_t size ) libcfa_public {
     1068        void * memalign( size_t alignment, size_t size ) {
    10701069                #ifdef __STATISTICS__
    10711070                if ( likely( size > 0 ) ) {
     
    10821081
    10831082        // Same as aalloc() with memory alignment.
    1084         void * amemalign( size_t alignment, size_t dim, size_t elemSize ) libcfa_public {
     1083        void * amemalign( size_t alignment, size_t dim, size_t elemSize ) {
    10851084                size_t size = dim * elemSize;
    10861085                #ifdef __STATISTICS__
     
    10981097
    10991098        // Same as calloc() with memory alignment.
    1100         void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) libcfa_public {
     1099        void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) {
    11011100                size_t size = dim * elemSize;
    11021101          if ( unlikely( size ) == 0 ) {                                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
     
    11371136        // Same as memalign(), but ISO/IEC 2011 C11 Section 7.22.2 states: the value of size shall be an integral multiple
    11381137        // of alignment. This requirement is universally ignored.
    1139         void * aligned_alloc( size_t alignment, size_t size ) libcfa_public {
     1138        void * aligned_alloc( size_t alignment, size_t size ) {
    11401139                return memalign( alignment, size );
    11411140        } // aligned_alloc
     
    11461145        // is 0, then posix_memalign() returns either 0p, or a unique pointer value that can later be successfully passed to
    11471146        // free(3).
    1148         int posix_memalign( void ** memptr, size_t alignment, size_t size ) libcfa_public {
     1147        int posix_memalign( void ** memptr, size_t alignment, size_t size ) {
    11491148          if ( unlikely( alignment < libAlign() || ! is_pow2( alignment ) ) ) return EINVAL; // check alignment
    11501149                *memptr = memalign( alignment, size );
     
    11551154        // Allocates size bytes and returns a pointer to the allocated memory. The memory address shall be a multiple of the
    11561155        // page size.  It is equivalent to memalign(sysconf(_SC_PAGESIZE),size).
    1157         void * valloc( size_t size ) libcfa_public {
     1156        void * valloc( size_t size ) {
    11581157                return memalign( __page_size, size );
    11591158        } // valloc
     
    11611160
    11621161        // Same as valloc but rounds size to multiple of page size.
    1163         void * pvalloc( size_t size ) libcfa_public {
     1162        void * pvalloc( size_t size ) {
    11641163                return memalign( __page_size, ceiling2( size, __page_size ) ); // round size to multiple of page size
    11651164        } // pvalloc
     
    11691168        // or realloc().  Otherwise, or if free(ptr) has already been called before, undefined behaviour occurs. If ptr is
    11701169        // 0p, no operation is performed.
    1171         void free( void * addr ) libcfa_public {
     1170        void free( void * addr ) {
    11721171          if ( unlikely( addr == 0p ) ) {                                       // special case
    11731172                        #ifdef __STATISTICS__
     
    11901189
    11911190        // Returns the alignment of an allocation.
    1192         size_t malloc_alignment( void * addr ) libcfa_public {
     1191        size_t malloc_alignment( void * addr ) {
    11931192          if ( unlikely( addr == 0p ) ) return libAlign();      // minimum alignment
    11941193                Heap.Storage.Header * header = HeaderAddr( addr );
     
    12021201
    12031202        // Returns true if the allocation is zero filled, e.g., allocated by calloc().
    1204         bool malloc_zero_fill( void * addr ) libcfa_public {
     1203        bool malloc_zero_fill( void * addr ) {
    12051204          if ( unlikely( addr == 0p ) ) return false;           // null allocation is not zero fill
    12061205                Heap.Storage.Header * header = HeaderAddr( addr );
     
    12131212
    12141213        // Returns original total allocation size (not bucket size) => array size is dimension * sizeof(T).
    1215         size_t malloc_size( void * addr ) libcfa_public {
     1214        size_t malloc_size( void * addr ) {
    12161215          if ( unlikely( addr == 0p ) ) return 0;                       // null allocation has zero size
    12171216                Heap.Storage.Header * header = HeaderAddr( addr );
     
    12251224        // Returns the number of usable bytes in the block pointed to by ptr, a pointer to a block of memory allocated by
    12261225        // malloc or a related function.
    1227         size_t malloc_usable_size( void * addr ) libcfa_public {
     1226        size_t malloc_usable_size( void * addr ) {
    12281227          if ( unlikely( addr == 0p ) ) return 0;                       // null allocation has 0 size
    12291228                Heap.Storage.Header * header;
     
    12371236
    12381237        // Prints (on default standard error) statistics about memory allocated by malloc and related functions.
    1239         void malloc_stats( void ) libcfa_public {
     1238        void malloc_stats( void ) {
    12401239                #ifdef __STATISTICS__
    12411240                printStats();
     
    12461245
    12471246        // Changes the file descriptor where malloc_stats() writes statistics.
    1248         int malloc_stats_fd( int fd __attribute__(( unused )) ) libcfa_public {
     1247        int malloc_stats_fd( int fd __attribute__(( unused )) ) {
    12491248                #ifdef __STATISTICS__
    12501249                int temp = stats_fd;
     
    12601259        // The string is printed on the file stream stream.  The exported string includes information about all arenas (see
    12611260        // malloc).
    1262         int malloc_info( int options, FILE * stream __attribute__(( unused )) ) libcfa_public {
     1261        int malloc_info( int options, FILE * stream __attribute__(( unused )) ) {
    12631262          if ( options != 0 ) { errno = EINVAL; return -1; }
    12641263                #ifdef __STATISTICS__
     
    12721271        // Adjusts parameters that control the behaviour of the memory-allocation functions (see malloc). The param argument
    12731272        // specifies the parameter to be modified, and value specifies the new value for that parameter.
    1274         int mallopt( int option, int value ) libcfa_public {
     1273        int mallopt( int option, int value ) {
    12751274          if ( value < 0 ) return 0;
    12761275                choose( option ) {
     
    12861285
    12871286        // Attempt to release free memory at the top of the heap (by calling sbrk with a suitable argument).
    1288         int malloc_trim( size_t ) libcfa_public {
     1287        int malloc_trim( size_t ) {
    12891288                return 0;                                                                               // => impossible to release memory
    12901289        } // malloc_trim
     
    12951294        // structure dynamically allocated via malloc, and a pointer to that data structure is returned as the function
    12961295        // result.  (The caller must free this memory.)
    1297         void * malloc_get_state( void ) libcfa_public {
     1296        void * malloc_get_state( void ) {
    12981297                return 0p;                                                                              // unsupported
    12991298        } // malloc_get_state
     
    13021301        // Restores the state of all malloc internal bookkeeping variables to the values recorded in the opaque data
    13031302        // structure pointed to by state.
    1304         int malloc_set_state( void * ) libcfa_public {
     1303        int malloc_set_state( void * ) {
    13051304                return 0;                                                                               // unsupported
    13061305        } // malloc_set_state
     
    13081307
    13091308        // Sets the amount (bytes) to extend the heap when there is insufficent free storage to service an allocation.
    1310         __attribute__((weak)) size_t malloc_expansion() libcfa_public { return __CFA_DEFAULT_HEAP_EXPANSION__; }
     1309        __attribute__((weak)) size_t malloc_expansion() { return __CFA_DEFAULT_HEAP_EXPANSION__; }
    13111310
    13121311        // Sets the crossover point between allocations occuring in the sbrk area or separately mmapped.
    1313         __attribute__((weak)) size_t malloc_mmap_start() libcfa_public { return __CFA_DEFAULT_MMAP_START__; }
     1312        __attribute__((weak)) size_t malloc_mmap_start() { return __CFA_DEFAULT_MMAP_START__; }
    13141313
    13151314        // Amount subtracted to adjust for unfreed program storage (debug only).
    1316         __attribute__((weak)) size_t malloc_unfreed() libcfa_public { return __CFA_DEFAULT_HEAP_UNFREED__; }
     1315        __attribute__((weak)) size_t malloc_unfreed() { return __CFA_DEFAULT_HEAP_UNFREED__; }
    13171316} // extern "C"
    13181317
    13191318
    13201319// Must have CFA linkage to overload with C linkage realloc.
    1321 void * resize( void * oaddr, size_t nalign, size_t size ) libcfa_public {
     1320void * resize( void * oaddr, size_t nalign, size_t size ) {
    13221321        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    13231322  if ( unlikely( size == 0 ) ) {                                                // special cases
     
    13811380
    13821381
    1383 void * realloc( void * oaddr, size_t nalign, size_t size ) libcfa_public {
     1382void * realloc( void * oaddr, size_t nalign, size_t size ) {
    13841383        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    13851384  if ( unlikely( size == 0 ) ) {                                                // special cases
Note: See TracChangeset for help on using the changeset viewer.