1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
#include <ndb_global.h>
21
typedef unsigned int Uint32;
22
typedef unsigned short Uint16;
23
typedef unsigned long long Uint64;
26
const int UNDEFINED_CHUNK = -2; // XXX Set to hex
29
const int END_OF_CHUNK_LIST = -1; // XXX Set to hex
31
// A timeout (no of seconds) for the memory segments in the TransporterRegistry
32
// memory pool. If a segment has been occupied (free=false) for a longer period
33
// than this timeout, it will be released.
34
const int ALLOCATION_TIMEOUT = 10000;
36
// Free segments should always be as large as possible
37
// and are only allowed to be in any of these sizes
38
enum FreeSegmentSize {
58
// Return true if there is at least 8 kB memory available
59
bool memoryAvailable();
62
bool allocate(int nChunksToAllocate);
64
// Remove the segment from the freeSegment list
65
void removeFromFreeSegmentList(int sz, int index);
67
// Release the segment of size
68
void release(int releaseId, int size);
70
// Add a segment to the freeSegment list
71
void addToFreeSegmentList(int sz, int index);
73
bool getSegment(Uint32 size, Segment * dst);
75
void refreshTime(Uint32 time);
77
//Calculate log2(arg) + 1
78
Uint32 logTwoPlus(Uint32 arg);
83
// Pointer to the first free segment of size FreeSegmentSize
84
Uint32 freeSegment[sz_MAX];
86
// Start address of the memory block allocated
87
Uint32* startOfMemoryBlock;
89
// Total number of 256 byte chunks.
90
Uint32 totalNoOfChunks;
92
// Array of 256-byte chunks
93
struct Chunk256* chunk;
97
Uint32 segmentSize; // Size of the segment in no of words
98
Uint16 index; // Index in the array of SegmentListElements
99
Uint16 releaseId; // Unique no used when releasing the segment
100
// Undefined if Long_signal.deallocIndicator==0
102
Uint32* segmentAddress; // Address to the memory segment
103
Uint64 _padding_NOT_TO_BE_USED_;
108
Uint32 allocationTimeStamp; // Bit 0 represents if the segment is free or not
109
// Bit 1-31 is the allocation time for the segment
110
// Bit 1-31 are undefined if the segment is free
111
Uint32 nextSegmentOfSameSize; // Undefined if allocated.
112
// The first chunk in a free segment has a valid
113
// next-pointer. In the rest of the chunks
114
// belonging to the segment it is UNDEFINED_CHUNK.
115
Uint32 prevSegmentOfSameSize; // Undefined if allocated
116
// The first chunk in a free segment has a valid
117
// prev-pointer. In the rest of the chunks
118
// belonging to the segment it is UNDEFINED_CHUNK.
120
void setFree(bool free);
124
void setAllocationTimeStamp(Uint32 cTime);
126
Uint32 getAllocationTimeStamp();
129
// inline void Chunk256::setFree(bool free){
130
// // Bit 0 of allocationTimeStamp represents if the segment is free or not
131
// allocationTimeStamp = 0x0;
133
// printf("\nSet free segment");
134
// Uint32 offMask = 0x0; // A mask to set the 0 bit to 0
136
// // Set this bit to 0, if segment should be free
137
// allocationTimeStamp = allocationTimeStamp & offMask;
140
// inline bool Chunk256::getFree(){
141
// // Get free segment
143
// allocationTimeStamp = 0x0;
144
// Uint32 offMask = 0x0;
146
// printf("\nGet free segment");
147
// return ((allocationTimeStamp | offMask) == offMask ? true : false);
150
// inline void Chunk256::setAllocationTimeStamp(Uint32 cTime){
151
// // Bits 1-31 of allocationTimeStamp represent the allocation time for segment
153
// Uint32 onMask = 0x80000000; // A mask to set the 0 bit to 1
154
// allocationTimeStamp = 0x0;
156
// printf("\nSet allocation time");
158
// allocationTimeStamp = onMask | cTime;
161
// inline Uint32 Chunk256::getAllocationTimeStamp(){
163
// Uint32 onMask = 0x80000000; // A mask to set the 0 bit to 1
164
// allocationTimeStamp = 0x0;
166
// printf("\nGet allocation time");
167
// allocationTimeStamp = allocationTimeStamp ^ onMask;
168
// return allocationTimeStamp;