RTI Connext DDS Micro  Version 2.4.8
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
osapi_heap_impl.h
Go to the documentation of this file.
1 /*
2  * FILE: osapi_heap_impl.h - Implementation of HEAP API
3  *
4  * (c) Copyright, Real-Time Innovations, 2008-2015
5  *
6  * All rights reserved.
7  *
8  * No duplications, whole or partial, manual or electronic, may be made
9  * without express written permission. Any such copies, or
10  * revisions thereof, must display this notice unaltered.
11  * This code contains trade secrets of Real-Time Innovations, Inc.
12  *
13  * Modification History
14  * --------------------
15  * 25feb2015,eh MICRO-356/PR#1496 Add OSAPI_Heap_allocate function for Cert
16  * 22sep2008,tk Created
17  */
18 /*ce \file
19  * \brief Macro implementing heap interface
20  */
21 #ifndef osapi_heap_impl_h
22 #define osapi_heap_impl_h
23 
24 #ifndef osapi_dll_h
25 #include "osapi/osapi_dll.h"
26 #endif
27 
28 #include "osapi/osapi_config.h"
29 
30 #ifdef HAVE_MALLOC_H
31 #include <malloc.h>
32 #else
33 #include <stdlib.h>
34 #endif
35 
36 #if (OSAPI_PLATFORM != OSAPI_PLATFORM_POSIX)
37 /* For OSAPI_PLATFORM_POSIX, this function has been moved to posixHeap.c
38  * #define OSAPI_Heap_allocate(a, b) OSAPI_Heap_allocate_func(a, b)
39  */
40 #if (!defined(RTI_VXWORKS) && !defined(RTI_CERT))
41 #define OSAPI_Heap_allocate(a, b) calloc(a, b);OSAPI_gv_AllocatedByteCount+=(a)*(b)
42 #endif /* !RTI_CERT */
43 #endif /* OSAPI_PLATFORM_POSIX */
44 
45 #ifdef RTI_CERT
46 #define OSAPI_Heap_free(a)
47 #define OSAPI_Heap_realloc(ptr_,size_)
48 #else
49 #define OSAPI_Heap_free(a) free(a)
50 #define OSAPI_Heap_realloc(ptr_,size_) realloc(ptr_,size_)
51 #endif
52 
53 /*--------------------------------------------------------------------------*/
54 /* This needs to stay a MACRO; not for performance reasons but because
55  it is the only way to pass a "type" into the "function"
56  */
57 #define OSAPI_Heap_allocate_struct(dest_, type_) \
58  *(dest_) = (type_ *)OSAPI_Heap_allocate(1, sizeof(type_))
59 /*--------------------------------------------------------------------------*/
60 #ifndef RTI_CERT
61 #define OSAPI_Heap_free_struct(dest_) \
62  if ((dest_) != NULL) OSAPI_Heap_free(dest_)
63 #else
64 #define OSAPI_Heap_free_struct(dest_)
65 #endif
66 /*--------------------------------------------------------------------------*/
67 /* This needs to stay a MACRO; not for performance reasons but because
68  it is the only way to pass a "type" into the "function"
69  */
70 #define OSAPI_Heap_allocate_array(dest_, count_, type_) \
71  *(dest_) = (type_ *)OSAPI_Heap_allocate(count_,sizeof(type_))
72 /*--------------------------------------------------------------------------*/
73 #ifndef RTI_CERT
74 #define OSAPI_Heap_free_array(dest_) \
75  if ((dest_) != NULL) OSAPI_Heap_free(dest_)
76 #else
77 #define OSAPI_Heap_free_array(dest_)
78 #endif
79 /*--------------------------------------------------------------------------*/
80 #define OSAPI_Heap_allocate_string(string_, size_) \
81  *(string_) = (char *)OSAPI_Heap_allocate((size_)+1, 1)
82 /*--------------------------------------------------------------------------*/
83 #ifndef RTI_CERT
84 #define OSAPI_Heap_free_string(string_) \
85  if ((string_) != NULL) OSAPI_Heap_free(string_)
86 #else
87 #define OSAPI_Heap_free_string(string_)
88 #endif
89 /*--------------------------------------------------------------------------*/
90 
91 #endif /* osapi_heap_impl_h */

RTI Connext DDS Micro Version 2.4.8 Copyright © Tue Apr 12 2016 Real-Time Innovations, Inc