Files
jerryscript/jerry-core/jmem/jmem-heap.h
T
Tilmann Scheller 1e99be90c3 Remove redundant extern keywords from function declarations/definitions. (#1495)
Extern keywords on function declarations/definitions provide no additional value since function declarations/definitions default to external linkage in C99, e.g. removing them won't change the semantics of the program.

The extern keywords were essentially a legacy from the early days of the project. This commit cleans this up across the whole codebase in one go to minimize history disruption.

The bulk of the changes in this commit were produced by a custom clang-tidy checker.

Note that variables declarations carrying the extern keyword are untouched by this commit since there the presence of the keyword actually has an impact on the semantics of the program.

JerryScript-DCO-1.0-Signed-off-by: Tilmann Scheller t.scheller@samsung.com
2016-12-16 10:18:37 +01:00

122 lines
3.2 KiB
C

/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Heap allocator interface
*/
#ifndef JMEM_HEAP_H
#define JMEM_HEAP_H
#include "jrt.h"
/** \addtogroup mem Memory allocation
* @{
*
* \addtogroup heap Heap
* @{
*/
void jmem_heap_init (void);
void jmem_heap_finalize (void);
void *jmem_heap_alloc_block (const size_t);
void *jmem_heap_alloc_block_null_on_error (const size_t);
void jmem_heap_free_block (void *, const size_t);
bool jmem_is_heap_pointer (const void *);
#ifdef JMEM_STATS
/**
* Heap memory usage statistics
*/
typedef struct
{
size_t size; /**< size */
size_t allocated_bytes; /**< currently allocated bytes */
size_t peak_allocated_bytes; /**< peak allocated bytes */
size_t global_peak_allocated_bytes; /**< non-resettable peak allocated bytes */
size_t waste_bytes; /**< bytes waste due to blocks filled partially
and due to block headers */
size_t peak_waste_bytes; /**< peak bytes waste */
size_t global_peak_waste_bytes; /**< non-resettable peak bytes waste */
size_t skip_count;
size_t nonskip_count;
size_t alloc_count;
size_t alloc_iter_count;
size_t free_count;
size_t free_iter_count;
} jmem_heap_stats_t;
void jmem_heap_get_stats (jmem_heap_stats_t *);
void jmem_heap_stats_reset_peak (void);
void jmem_heap_stats_print (void);
#endif /* JMEM_STATS */
#ifdef JERRY_VALGRIND_FREYA
#ifdef JERRY_VALGRIND
#error Valgrind and valgrind-freya modes are not compatible.
#endif /* JERRY_VALGRIND */
void jmem_heap_valgrind_freya_mempool_request (void);
#define JMEM_HEAP_VALGRIND_FREYA_MEMPOOL_REQUEST() jmem_heap_valgrind_freya_mempool_request ()
#else /* !JERRY_VALGRIND_FREYA */
#define JMEM_HEAP_VALGRIND_FREYA_MEMPOOL_REQUEST()
#endif /* JERRY_VALGRIND_FREYA */
/**
* Define a local array variable and allocate memory for the array on the heap.
*
* If requested number of elements is zero, assign NULL to the variable.
*
* Warning:
* if there is not enough memory on the heap, shutdown engine with ERR_OUT_OF_MEMORY.
*/
#define JMEM_DEFINE_LOCAL_ARRAY(var_name, number, type) \
{ \
size_t var_name ## ___size = (size_t) (number) * sizeof (type); \
type *var_name = (type *) (jmem_heap_alloc_block (var_name ## ___size));
/**
* Free the previously defined local array variable, freeing corresponding block on the heap,
* if it was allocated (i.e. if the array's size was non-zero).
*/
#define JMEM_FINALIZE_LOCAL_ARRAY(var_name) \
if (var_name != NULL) \
{ \
JERRY_ASSERT (var_name ## ___size != 0); \
\
jmem_heap_free_block (var_name, var_name ## ___size); \
} \
else \
{ \
JERRY_ASSERT (var_name ## ___size == 0); \
} \
}
/**
* @}
* @}
*/
#endif /* !JMEM_HEAP_H */