Ignore:
Timestamp:
May 16, 2022, 12:04:23 PM (23 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
108345a
Parents:
d8454b9
Message:

Visibility of the core libcfa files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    rd8454b9 r032234bd  
    3636static bool traceHeap = false;
    3737
    38 inline bool traceHeap() { return traceHeap; }
    39 
    40 bool traceHeapOn() {
     38inline bool traceHeap() libcfa_public { return traceHeap; }
     39
     40bool traceHeapOn() libcfa_public {
    4141        bool temp = traceHeap;
    4242        traceHeap = true;
     
    4444} // traceHeapOn
    4545
    46 bool traceHeapOff() {
     46bool traceHeapOff() libcfa_public {
    4747        bool temp = traceHeap;
    4848        traceHeap = false;
     
    5050} // traceHeapOff
    5151
    52 bool traceHeapTerm() { return false; }
     52bool traceHeapTerm() libcfa_public { return false; }
    5353
    5454
    5555static bool prtFree = false;
    5656
    57 bool prtFree() {
     57static bool prtFree() {
    5858        return prtFree;
    5959} // prtFree
    6060
    61 bool prtFreeOn() {
     61static bool prtFreeOn() {
    6262        bool temp = prtFree;
    6363        prtFree = true;
     
    6565} // prtFreeOn
    6666
    67 bool prtFreeOff() {
     67static bool 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 size_t __page_size;                                                                             // architecture pagesize
    391 int __map_prot;                                                                                 // common mmap/mprotect protection
     390// would be cool to remove libcfa_public but it's needed for libcfathread
     391libcfa_public size_t __page_size;                                                       // architecture pagesize
     392libcfa_public int __map_prot;                                                           // common mmap/mprotect protection
    392393
    393394
     
    727728
    728729
    729 size_t prtFree( Heap & manager ) with( manager ) {
     730static size_t prtFree( Heap & manager ) with( manager ) {
    730731        size_t total = 0;
    731732        #ifdef __STATISTICS__
     
    879880        // Allocates size bytes and returns a pointer to the allocated memory.  The contents are undefined. If size is 0,
    880881        // then malloc() returns a unique pointer value that can later be successfully passed to free().
    881         void * malloc( size_t size ) {
     882        void * malloc( size_t size ) libcfa_public {
    882883                #ifdef __STATISTICS__
    883884                if ( likely( size > 0 ) ) {
     
    894895
    895896        // Same as malloc() except size bytes is an array of dim elements each of elemSize bytes.
    896         void * aalloc( size_t dim, size_t elemSize ) {
     897        void * aalloc( size_t dim, size_t elemSize ) libcfa_public {
    897898                size_t size = dim * elemSize;
    898899                #ifdef __STATISTICS__
     
    910911
    911912        // Same as aalloc() with memory set to zero.
    912         void * calloc( size_t dim, size_t elemSize ) {
     913        void * calloc( size_t dim, size_t elemSize ) libcfa_public {
    913914                size_t size = dim * elemSize;
    914915          if ( unlikely( size ) == 0 ) {                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
     
    951952        // not 0p, then the call is equivalent to free(oaddr). Unless oaddr is 0p, it must have been returned by an earlier
    952953        // call to malloc(), alloc(), calloc() or realloc(). If the area pointed to was moved, a free(oaddr) is done.
    953         void * resize( void * oaddr, size_t size ) {
     954        void * resize( void * oaddr, size_t size ) libcfa_public {
    954955                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    955956          if ( unlikely( size == 0 ) ) {                                        // special cases
     
    996997        // Same as resize() but the contents are unchanged in the range from the start of the region up to the minimum of
    997998        // the old and new sizes.
    998         void * realloc( void * oaddr, size_t size ) {
     999        void * realloc( void * oaddr, size_t size ) libcfa_public {
    9991000                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    10001001          if ( unlikely( size == 0 ) ) {                                        // special cases
     
    10601061
    10611062        // Same as realloc() except the new allocation size is large enough for an array of nelem elements of size elsize.
    1062         void * reallocarray( void * oaddr, size_t dim, size_t elemSize ) {
     1063        void * reallocarray( void * oaddr, size_t dim, size_t elemSize ) libcfa_public {
    10631064                return realloc( oaddr, dim * elemSize );
    10641065        } // reallocarray
     
    10661067
    10671068        // Same as malloc() except the memory address is a multiple of alignment, which must be a power of two. (obsolete)
    1068         void * memalign( size_t alignment, size_t size ) {
     1069        void * memalign( size_t alignment, size_t size ) libcfa_public {
    10691070                #ifdef __STATISTICS__
    10701071                if ( likely( size > 0 ) ) {
     
    10811082
    10821083        // Same as aalloc() with memory alignment.
    1083         void * amemalign( size_t alignment, size_t dim, size_t elemSize ) {
     1084        void * amemalign( size_t alignment, size_t dim, size_t elemSize ) libcfa_public {
    10841085                size_t size = dim * elemSize;
    10851086                #ifdef __STATISTICS__
     
    10971098
    10981099        // Same as calloc() with memory alignment.
    1099         void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) {
     1100        void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) libcfa_public {
    11001101                size_t size = dim * elemSize;
    11011102          if ( unlikely( size ) == 0 ) {                                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
     
    11361137        // Same as memalign(), but ISO/IEC 2011 C11 Section 7.22.2 states: the value of size shall be an integral multiple
    11371138        // of alignment. This requirement is universally ignored.
    1138         void * aligned_alloc( size_t alignment, size_t size ) {
     1139        void * aligned_alloc( size_t alignment, size_t size ) libcfa_public {
    11391140                return memalign( alignment, size );
    11401141        } // aligned_alloc
     
    11451146        // is 0, then posix_memalign() returns either 0p, or a unique pointer value that can later be successfully passed to
    11461147        // free(3).
    1147         int posix_memalign( void ** memptr, size_t alignment, size_t size ) {
     1148        int posix_memalign( void ** memptr, size_t alignment, size_t size ) libcfa_public {
    11481149          if ( unlikely( alignment < libAlign() || ! is_pow2( alignment ) ) ) return EINVAL; // check alignment
    11491150                *memptr = memalign( alignment, size );
     
    11541155        // Allocates size bytes and returns a pointer to the allocated memory. The memory address shall be a multiple of the
    11551156        // page size.  It is equivalent to memalign(sysconf(_SC_PAGESIZE),size).
    1156         void * valloc( size_t size ) {
     1157        void * valloc( size_t size ) libcfa_public {
    11571158                return memalign( __page_size, size );
    11581159        } // valloc
     
    11601161
    11611162        // Same as valloc but rounds size to multiple of page size.
    1162         void * pvalloc( size_t size ) {
     1163        void * pvalloc( size_t size ) libcfa_public {
    11631164                return memalign( __page_size, ceiling2( size, __page_size ) ); // round size to multiple of page size
    11641165        } // pvalloc
     
    11681169        // or realloc().  Otherwise, or if free(ptr) has already been called before, undefined behaviour occurs. If ptr is
    11691170        // 0p, no operation is performed.
    1170         void free( void * addr ) {
     1171        void free( void * addr ) libcfa_public {
    11711172          if ( unlikely( addr == 0p ) ) {                                       // special case
    11721173                        #ifdef __STATISTICS__
     
    11891190
    11901191        // Returns the alignment of an allocation.
    1191         size_t malloc_alignment( void * addr ) {
     1192        size_t malloc_alignment( void * addr ) libcfa_public {
    11921193          if ( unlikely( addr == 0p ) ) return libAlign();      // minimum alignment
    11931194                Heap.Storage.Header * header = HeaderAddr( addr );
     
    12011202
    12021203        // Returns true if the allocation is zero filled, e.g., allocated by calloc().
    1203         bool malloc_zero_fill( void * addr ) {
     1204        bool malloc_zero_fill( void * addr ) libcfa_public {
    12041205          if ( unlikely( addr == 0p ) ) return false;           // null allocation is not zero fill
    12051206                Heap.Storage.Header * header = HeaderAddr( addr );
     
    12121213
    12131214        // Returns original total allocation size (not bucket size) => array size is dimension * sizeof(T).
    1214         size_t malloc_size( void * addr ) {
     1215        size_t malloc_size( void * addr ) libcfa_public {
    12151216          if ( unlikely( addr == 0p ) ) return 0;                       // null allocation has zero size
    12161217                Heap.Storage.Header * header = HeaderAddr( addr );
     
    12241225        // Returns the number of usable bytes in the block pointed to by ptr, a pointer to a block of memory allocated by
    12251226        // malloc or a related function.
    1226         size_t malloc_usable_size( void * addr ) {
     1227        size_t malloc_usable_size( void * addr ) libcfa_public {
    12271228          if ( unlikely( addr == 0p ) ) return 0;                       // null allocation has 0 size
    12281229                Heap.Storage.Header * header;
     
    12361237
    12371238        // Prints (on default standard error) statistics about memory allocated by malloc and related functions.
    1238         void malloc_stats( void ) {
     1239        void malloc_stats( void ) libcfa_public {
    12391240                #ifdef __STATISTICS__
    12401241                printStats();
     
    12451246
    12461247        // Changes the file descriptor where malloc_stats() writes statistics.
    1247         int malloc_stats_fd( int fd __attribute__(( unused )) ) {
     1248        int malloc_stats_fd( int fd __attribute__(( unused )) ) libcfa_public {
    12481249                #ifdef __STATISTICS__
    12491250                int temp = stats_fd;
     
    12591260        // The string is printed on the file stream stream.  The exported string includes information about all arenas (see
    12601261        // malloc).
    1261         int malloc_info( int options, FILE * stream __attribute__(( unused )) ) {
     1262        int malloc_info( int options, FILE * stream __attribute__(( unused )) ) libcfa_public {
    12621263          if ( options != 0 ) { errno = EINVAL; return -1; }
    12631264                #ifdef __STATISTICS__
     
    12711272        // Adjusts parameters that control the behaviour of the memory-allocation functions (see malloc). The param argument
    12721273        // specifies the parameter to be modified, and value specifies the new value for that parameter.
    1273         int mallopt( int option, int value ) {
     1274        int mallopt( int option, int value ) libcfa_public {
    12741275          if ( value < 0 ) return 0;
    12751276                choose( option ) {
     
    12851286
    12861287        // Attempt to release free memory at the top of the heap (by calling sbrk with a suitable argument).
    1287         int malloc_trim( size_t ) {
     1288        int malloc_trim( size_t ) libcfa_public {
    12881289                return 0;                                                                               // => impossible to release memory
    12891290        } // malloc_trim
     
    12941295        // structure dynamically allocated via malloc, and a pointer to that data structure is returned as the function
    12951296        // result.  (The caller must free this memory.)
    1296         void * malloc_get_state( void ) {
     1297        void * malloc_get_state( void ) libcfa_public {
    12971298                return 0p;                                                                              // unsupported
    12981299        } // malloc_get_state
     
    13011302        // Restores the state of all malloc internal bookkeeping variables to the values recorded in the opaque data
    13021303        // structure pointed to by state.
    1303         int malloc_set_state( void * ) {
     1304        int malloc_set_state( void * ) libcfa_public {
    13041305                return 0;                                                                               // unsupported
    13051306        } // malloc_set_state
     
    13071308
    13081309        // Sets the amount (bytes) to extend the heap when there is insufficent free storage to service an allocation.
    1309         __attribute__((weak)) size_t malloc_expansion() { return __CFA_DEFAULT_HEAP_EXPANSION__; }
     1310        __attribute__((weak)) size_t malloc_expansion() libcfa_public { return __CFA_DEFAULT_HEAP_EXPANSION__; }
    13101311
    13111312        // Sets the crossover point between allocations occuring in the sbrk area or separately mmapped.
    1312         __attribute__((weak)) size_t malloc_mmap_start() { return __CFA_DEFAULT_MMAP_START__; }
     1313        __attribute__((weak)) size_t malloc_mmap_start() libcfa_public { return __CFA_DEFAULT_MMAP_START__; }
    13131314
    13141315        // Amount subtracted to adjust for unfreed program storage (debug only).
    1315         __attribute__((weak)) size_t malloc_unfreed() { return __CFA_DEFAULT_HEAP_UNFREED__; }
     1316        __attribute__((weak)) size_t malloc_unfreed() libcfa_public { return __CFA_DEFAULT_HEAP_UNFREED__; }
    13161317} // extern "C"
    13171318
    13181319
    13191320// Must have CFA linkage to overload with C linkage realloc.
    1320 void * resize( void * oaddr, size_t nalign, size_t size ) {
     1321void * resize( void * oaddr, size_t nalign, size_t size ) libcfa_public {
    13211322        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    13221323  if ( unlikely( size == 0 ) ) {                                                // special cases
     
    13801381
    13811382
    1382 void * realloc( void * oaddr, size_t nalign, size_t size ) {
     1383void * realloc( void * oaddr, size_t nalign, size_t size ) libcfa_public {
    13831384        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    13841385  if ( unlikely( size == 0 ) ) {                                                // special cases
Note: See TracChangeset for help on using the changeset viewer.