| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 | 
							- /*
 
-  *   Copyright 2011 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.
 
-  *   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.
 
-  *
 
-  */
 
- /**
 
-  * \file 	block_header.h
 
-  * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
 
-  * \date 	September, 2011
 
-  *  
 
-  * \brief Block header structure and functions, and memory block functions.
 
-  */
 
- #ifndef BLOCK_HEADER_H
 
- #define BLOCK_HEADER_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 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 FUTURE_FEATURES
 
-     size_t requested_size; /**< The requested size of the data part */
 
- #endif /* FUTURE_FEATURES */
 
-     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)
 
- /**
 
-  * \brief Get the address of the block header of a memory block.
 
-  *
 
-  * \param ptr The data part of the memory block.
 
-  */
 
- 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.
 
-  *
 
-  * \return The size of the data part of the current memory block.
 
-  */
 
- size_t get_size(void *ptr);
 
- #ifdef FUTURE_FEATURES
 
- /**
 
-  * Get the requested size of the memory block's data
 
-  *
 
-  * \param ptr The pointer to the data part of the current memory block.
 
-  *
 
-  * \return The size of the data that was initialy requested for this memory
 
-  * block.
 
-  */
 
- size_t get_requested_size(void *ptr);
 
- #endif /* FUTURE_FEATURES */
 
- /**
 
-  * Get all information of the memory block header's size record
 
-  *
 
-  * \param ptr The pointer to the data part of the current memory block.
 
-  *
 
-  * \return The availability and the size of the data part of the current memory
 
-  * block.
 
-  */
 
- size_t get_size_availability(void *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 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);
 
- /**
 
-  * 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 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);
 
- #ifdef FUTURE_FEATURES
 
- /**
 
-  * Set the requested size of memory block's data
 
-  *
 
-  * \param ptr 	The pointer to the data part of the current memory block.
 
-  * \param size 	The requested size for the data part of the current memory
 
-  * block.
 
-  */
 
- void set_requested_size(void *ptr, size_t size);
 
- #endif /* FUTURE_FEATURES */
 
- /**
 
-  * 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 ptr 	The pointer to the data part of the memory block.
 
-  */
 
- void mark_used(allocator_t *allocator, void *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 ptr 	The pointer to the data part of the memory block.
 
-  */
 
- void mark_free(allocator_t *allocator, void *ptr);
 
- /**
 
-  * Set the availability and the size of the previous memory block
 
-  *
 
-  * \param ptr 		The pointer to the data part of the previous memory block.
 
-  * \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 */
 
- /**
 
-  * Check if a memory block is free
 
-  */
 
- bool is_free(void *ptr);
 
- /**
 
-  * Check if previous block (in the memory space) belongs to a free list
 
-  */
 
- bool is_previous_free(void *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);
 
- /**
 
-  * Get the size and the availability of the previous block (in the memory
 
-  * space) 
 
-  *
 
-  * \param ptr 	The pointer to the data part of the previous memory block.
 
-  */
 
- size_t get_previous_size_availability(void *ptr);
 
- /**
 
-  * Get the previous memory block on data layout level
 
-  *
 
-  * \param ptr 	The pointer to the data part of the current memory block.
 
-  *
 
-  * \return 	The pointer to the data part of the previous memory block on
 
-  * data layout level. 
 
-  */
 
- void * get_dlprevious(void *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 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);
 
- #endif /* BLOCK_HEADER_H */
 
 
  |