• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2020 IBM Corp. and others
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v2.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    https://www.eclipse.org/legal/epl-2.0/
10  * and the Eclipse Distribution License is available at
11  *   http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  *    Ian Craggs - initial API and implementation and/or initial documentation
15  *    Ian Craggs - use tree data structure instead of list
16  *******************************************************************************/
17 
18 
19 #if !defined(HEAP_H)
20 #define HEAP_H
21 
22 #if defined(HIGH_PERFORMANCE)
23 #define NO_HEAP_TRACKING 1
24 #endif
25 
26 #define PAHO_MEMORY_ERROR -99
27 
28 #include "MQTTExportDeclarations.h"
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 
33 #if !defined(NO_HEAP_TRACKING)
34 
35 #if !defined(TREE_C)
36 /**
37  * redefines malloc to use "mymalloc" so that heap allocation can be tracked
38  * @param x the size of the item to be allocated
39  * @return the pointer to the item allocated, or NULL
40  */
41 #define malloc(x) mymalloc(__FILE__, __LINE__, x)
42 
43 /**
44  * redefines realloc to use "myrealloc" so that heap allocation can be tracked
45  * @param a the heap item to be reallocated
46  * @param b the new size of the item
47  * @return the new pointer to the heap item
48  */
49 #define realloc(a, b) myrealloc(__FILE__, __LINE__, a, b)
50 
51 /**
52  * redefines free to use "myfree" so that heap allocation can be tracked
53  * @param x the pointer to the item to be freed
54  */
55 #define free(x) myfree(__FILE__, __LINE__, x)
56 
57 #endif
58 
59 /**
60  * Information about the state of the heap.
61  */
62 typedef struct
63 {
64 	size_t current_size;	/**< current size of the heap in bytes */
65 	size_t max_size;		/**< max size the heap has reached in bytes */
66 } heap_info;
67 
68 #if defined(__cplusplus)
69  extern "C" {
70 #endif
71 
72 void* mymalloc(char*, int, size_t size);
73 void* myrealloc(char*, int, void* p, size_t size);
74 void myfree(char*, int, void* p);
75 
76 void Heap_scan(FILE* file);
77 int Heap_initialize(void);
78 void Heap_terminate(void);
79 LIBMQTT_API heap_info* Heap_get_info(void);
80 int HeapDump(FILE* file);
81 int HeapDumpString(FILE* file, char* str);
82 void* Heap_findItem(void* p);
83 void Heap_unlink(char* file, int line, void* p);
84 #ifdef __cplusplus
85      }
86 #endif
87 
88 #endif
89 
90 #endif
91