|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2011 Institute of Communication and Computer Systems (ICCS)
|
|
|
+ * Copyright 2012 Institute of Communication and Computer Systems (ICCS)
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,46 +16,17 @@
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * \file block_header.h
|
|
|
+ * \file block_header_funcs.h
|
|
|
* \author Ioannis Koutras (joko@microlab.ntua.gr)
|
|
|
- * \date September, 2011
|
|
|
*
|
|
|
- * \brief Block header structure and functions, and memory block functions.
|
|
|
+ * \brief Memory block functions.
|
|
|
*/
|
|
|
|
|
|
-#ifndef BLOCK_HEADER_H
|
|
|
-#define BLOCK_HEADER_H
|
|
|
+#ifndef BLOCK_HEADER_FUNCS_H
|
|
|
+#define BLOCK_HEADER_FUNCS_H
|
|
|
|
|
|
-#include <stddef.h>
|
|
|
-#include <stdbool.h>
|
|
|
-#include <dmmlib/heap.h>
|
|
|
-
|
|
|
-/* TODO Add an ifndef guard in case we have other block organizations */
|
|
|
-#include "linked_lists/linked_lists.h"
|
|
|
-
|
|
|
-/** The header structure of every memory block inside a heap. */
|
|
|
-typedef struct __attribute__((__aligned__(32))) block_header_s {
|
|
|
- size_t size; /**< The LSB represents the availability of the block (1
|
|
|
- for used, 0 for free), the rest the size of the data
|
|
|
- part. */
|
|
|
-#ifdef REQUEST_SIZE_INFO
|
|
|
- size_t requested_size; /**< The requested size of the data part */
|
|
|
-#endif /* REQUEST_SIZE_INFO */
|
|
|
- size_t previous_size; /**< The LSB represents the availability of the
|
|
|
- previous block, the rest the size of the data
|
|
|
- part of the previous block in the memory space */
|
|
|
- /* TODO Add an ifndef guard in case we have other block organizations */
|
|
|
- list_node_header_t pointers; /**< The necessary pointers for block
|
|
|
- organization. */
|
|
|
-#ifdef WITH_OWNERSHIP
|
|
|
- heap_t *heap_owner; /** < A pointer to the heap the current block belongs to */
|
|
|
-#endif /* WITH_OWNERSHIP */
|
|
|
-} block_header_t;
|
|
|
-
|
|
|
-/**
|
|
|
- * The size of the header in number of bytes
|
|
|
- */
|
|
|
-#define HEADER_SIZE sizeof(block_header_t)
|
|
|
+#include <dmmlib/block_header.h>
|
|
|
+#include <dmmlib/raw_block.h>
|
|
|
|
|
|
/**
|
|
|
* \brief Get the address of the block header of a memory block.
|
|
@@ -67,11 +38,11 @@ block_header_t * get_header(void *ptr);
|
|
|
/**
|
|
|
* Get the size of the memory block's data
|
|
|
*
|
|
|
- * \param ptr The pointer to the data part of the current memory block.
|
|
|
+ * \param ptr The pointer to the current memory block.
|
|
|
*
|
|
|
* \return The size of the data part of the current memory block.
|
|
|
*/
|
|
|
-size_t get_size(void *ptr);
|
|
|
+size_t get_size(block_header_t *ptr);
|
|
|
|
|
|
#ifdef REQUEST_SIZE_INFO
|
|
|
|
|
@@ -82,7 +53,7 @@ size_t get_size(void *ptr);
|
|
|
* \param size The requested size for the data part of the current memory
|
|
|
* block.
|
|
|
*/
|
|
|
-void set_requested_size(void *ptr, size_t size);
|
|
|
+void set_requested_size(block_header_t *ptr, size_t size);
|
|
|
|
|
|
/**
|
|
|
* Get the requested size of the memory block's data
|
|
@@ -92,7 +63,7 @@ void set_requested_size(void *ptr, size_t size);
|
|
|
* \return The size of the data that was initialy requested for this memory
|
|
|
* block.
|
|
|
*/
|
|
|
-size_t get_requested_size(void *ptr);
|
|
|
+size_t get_requested_size(block_header_t *ptr);
|
|
|
#endif /* REQUEST_SIZE_INFO */
|
|
|
|
|
|
/**
|
|
@@ -103,43 +74,43 @@ size_t get_requested_size(void *ptr);
|
|
|
* \return The availability and the size of the data part of the current memory
|
|
|
* block.
|
|
|
*/
|
|
|
-size_t get_size_availability(void *ptr);
|
|
|
+size_t get_size_availability(block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Set the size of the memory block's data and mark it free
|
|
|
*
|
|
|
- * \param allocator The pointer to the allocator who manages the block.
|
|
|
+ * \param raw_block The pointer to the raw block which includes the block.
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
* \param size The size of the data part of the current memory block.
|
|
|
*/
|
|
|
-void set_size_and_free(allocator_t *allocator, void *ptr, size_t size);
|
|
|
+void set_size_and_free(raw_block_header_t *raw_block, block_header_t *ptr, size_t size);
|
|
|
|
|
|
/**
|
|
|
* Set the size of the memory block's data and mark it used
|
|
|
*
|
|
|
- * \param allocator The pointer to the allocator who manages the block.
|
|
|
+ * \param raw_block The pointer to the raw block which includes the block.
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
* \param size The size of the data part of the current memory block.
|
|
|
*/
|
|
|
-void set_size_and_used(allocator_t *allocator, void *ptr, size_t size);
|
|
|
+void set_size_and_used(raw_block_header_t *raw_block, block_header_t *ptr, size_t size);
|
|
|
|
|
|
/**
|
|
|
* Mark the memory block as used, as well as the previous_size element of the
|
|
|
* next block if there is one.
|
|
|
*
|
|
|
- * \param allocator The pointer to the allocator who manages the block.
|
|
|
+ * \param raw_block The pointer to the raw block which includes the block.
|
|
|
* \param ptr The pointer to the data part of the memory block.
|
|
|
*/
|
|
|
-void mark_used(allocator_t *allocator, void *ptr);
|
|
|
+void mark_used(raw_block_header_t *raw_block, block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Mark the memory block as free, as well as the previous_size element of the
|
|
|
* next block if there is one.
|
|
|
*
|
|
|
- * \param allocator The pointer to the allocator who manages the block.
|
|
|
+ * \param raw_block The pointer to the raw block which includes the block.
|
|
|
* \param ptr The pointer to the data part of the memory block.
|
|
|
*/
|
|
|
-void mark_free(allocator_t *allocator, void *ptr);
|
|
|
+void mark_free(raw_block_header_t *raw_block, block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Set the availability and the size of the previous memory block
|
|
@@ -148,44 +119,24 @@ void mark_free(allocator_t *allocator, void *ptr);
|
|
|
* \param previous_size_availability The size for the data part of the previous
|
|
|
* memory block on data layout level.
|
|
|
*/
|
|
|
-void set_previous_size_availability(void *ptr, size_t previous_size_availability);
|
|
|
-
|
|
|
-#ifdef WITH_OWNERSHIP
|
|
|
-
|
|
|
-/**
|
|
|
- * Set the heap owner of a memory block
|
|
|
- *
|
|
|
- * \param ptr The pointer to the data part of the memory block.
|
|
|
- * \param heap_owner The pointer to the heap owner.
|
|
|
- */
|
|
|
-void set_owner(void *ptr, heap_t *heap_owner);
|
|
|
-
|
|
|
-/**
|
|
|
- * Get the heap owner of a memory block
|
|
|
- *
|
|
|
- * \param ptr The pointer to the data part of the memory block.
|
|
|
- * \return The pointer to the heap owner.
|
|
|
- */
|
|
|
-heap_t * get_owner(void *ptr);
|
|
|
-
|
|
|
-#endif /* WITH_OWNERSHIP */
|
|
|
+void set_previous_size_availability(block_header_t *ptr, size_t previous_size_availability);
|
|
|
|
|
|
/**
|
|
|
* Check if a memory block is free
|
|
|
*/
|
|
|
-bool is_free(void *ptr);
|
|
|
+bool is_free(block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Check if previous block (in the memory space) belongs to a free list
|
|
|
*/
|
|
|
-bool is_previous_free(void *ptr);
|
|
|
+bool is_previous_free(block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Get the size of the previous block (in the memory space)
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
*/
|
|
|
-size_t get_previous_size(void *ptr);
|
|
|
+size_t get_previous_size(block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Get the size and the availability of the previous block (in the memory
|
|
@@ -193,7 +144,7 @@ size_t get_previous_size(void *ptr);
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the previous memory block.
|
|
|
*/
|
|
|
-size_t get_previous_size_availability(void *ptr);
|
|
|
+size_t get_previous_size_availability(block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Get the previous memory block on data layout level
|
|
@@ -203,17 +154,19 @@ size_t get_previous_size_availability(void *ptr);
|
|
|
* \return The pointer to the data part of the previous memory block on
|
|
|
* data layout level.
|
|
|
*/
|
|
|
-void * get_dlprevious(void *ptr);
|
|
|
+block_header_t * get_dlprevious(block_header_t *ptr);
|
|
|
|
|
|
/**
|
|
|
* Get the next memory block on data layout level if there is one
|
|
|
*
|
|
|
- * \param allocator The pointer to the allocator who manages the block.
|
|
|
+ * \param raw_block The pointer to the raw block which includes the block.
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
*
|
|
|
* \return The pointer to the data part of the next block.
|
|
|
* \retval NULL There is no next block.
|
|
|
*/
|
|
|
-void * get_dlnext(allocator_t *allocator, void *ptr);
|
|
|
+block_header_t * get_dlnext(raw_block_header_t *raw_block, block_header_t *ptr);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-#endif /* BLOCK_HEADER_H */
|
|
|
+#endif /* BLOCK_HEADER_FUNCS_H */
|