-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainQnx.cpp
136 lines (103 loc) · 4.75 KB
/
MainQnx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/** <!------------------------------------------------------------------------->
*
* @file MainQnx.c
*
* @brief <Brief description here>
*
* @author
* GeraldR
*
* @description
* <Description here>
*
* @copyright
* Copyright 2012, dSPACE GmbH. All rights reserved.
*
* @version
* $RCSfile: MainQnx.c $ $Revision: 1.0 $ $Date: 10.12.2012 $
* $ProjectName: $
*
* <hr><br>
*<!-------------------------------------------------------------------------->*/
/******************************************************************************
* system include files
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/******************************************************************************
* dSPACE include files
******************************************************************************/
#include "Dstypes.h"
#include "DsSharedMemory.h"
#include "DsMappedBuddyHeap.h"
/******************************************************************************
* internal defines
******************************************************************************/
/******************************************************************************
* data types
******************************************************************************/
/******************************************************************************
* global variables
******************************************************************************/
/******************************************************************************
* local/static function declarations
******************************************************************************/
/******************************************************************************
* function definitions
******************************************************************************/
int main(int argc, char *argv[])
{
#ifdef DS_PLATFORM_HCN
{
void *block1, *block2, *block2b, *block3, *block4, *block5;
T_SHM_DESCRIPTOR *pHeapBlockList;
UInt32 numAllocatedBlocks, i, size;
int rc;
initSharedMemoryHeaps(true);
// Allocate a few blocks and show heap status in between
rc = openSharedMemory( &block1, &size, "block_555", 0xAAAAAA, 555, SHM_LOCATION_ON_HCN, 0, SHM_OPEN_CREATE_IF_MISSING );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
rc = openSharedMemory( &block2, &size, "block_1555", 0xBBBBBB, 1555, SHM_LOCATION_ON_HCN, 0, SHM_OPEN_CREATE_IF_MISSING );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
rc = openSharedMemory( &block3, &size, "block_666", 0xCCCCCC, 666, SHM_LOCATION_ON_HCN, 0, SHM_OPEN_CREATE_IF_MISSING );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
rc = openSharedMemory( &block4, &size, "block_120k", 0xDDDDDD, 120000, SHM_LOCATION_ON_HCN, 0, SHM_OPEN_CREATE_IF_MISSING );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
rc = openSharedMemory( &block5, &size, "block_120kb", 0xEEEEEE, 120000, SHM_LOCATION_ON_HCN, 0, SHM_OPEN_CREATE_IF_MISSING );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
rc = openSharedMemory( &block2b, &size, "block_555", 0xAAAAAA, 5555, SHM_LOCATION_ON_HCN, 0, SHM_OPEN_CREATE_IF_MISSING );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
// Get and display list of allocated blocks
rc = listSharedMemory( &pHeapBlockList, &numAllocatedBlocks, SHM_LOCATION_ON_HCN );
printf("Allocated blocks:\n");
for( i=0; i<numAllocatedBlocks; i++ )
{
T_SHM_DESCRIPTOR *pHeapBlockInfo;
pHeapBlockInfo = &pHeapBlockList[i];
printf("Address = 0x%09llx, Size = %d, Name = %s\n", pHeapBlockInfo->PhysAddress, pHeapBlockInfo->Size, pHeapBlockInfo->Name );
}
free( pHeapBlockList );
// Release blocks and show heap status in between
closeSharedMemory( block1, SHM_LOCATION_ON_HCN, 0 );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
closeSharedMemory( block2, SHM_LOCATION_ON_HCN, 0 );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
closeSharedMemory( block3, SHM_LOCATION_ON_HCN, 0 );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
closeSharedMemory( block4, SHM_LOCATION_ON_HCN, 0 );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
closeSharedMemory( block5, SHM_LOCATION_ON_HCN, 0 );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
closeSharedMemory( block2b, SHM_LOCATION_ON_HCN, 0 );
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
}
#else
{
initSharedMemoryHeaps(false);
// Just dump heap status
dumpSharedMemoryHeap(SHM_LOCATION_ON_HCN);
}
#endif
return 0;
}