-
Notifications
You must be signed in to change notification settings - Fork 30
/
TrackSpaceAlloc.cpp
64 lines (56 loc) · 1.47 KB
/
TrackSpaceAlloc.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
#include "TrackSpaceAlloc.h"
TrackSpaceAlloc::TrackSpaceAlloc(void):subTrackNO(1)
{
trackSet = new ObjTrack[MAX_OBJ_TACKSET_SIZE];
subTrackSet = new ObjSubTrack[MAX_OBJSUBTRACKSET_SIZE];
for(int i=0;i<MAX_OBJ_TACKSET_SIZE;i++)
{
objTrackQueue.push(trackSet+i);
}
for(int i=0;i<MAX_OBJSUBTRACKSET_SIZE;i++)
{
objSubTrackQueue.push(subTrackSet+i);
}
}
TrackSpaceAlloc::~TrackSpaceAlloc(void)
{
delete[] trackSet;
delete[] subTrackSet;
}
/*Add one free objTrack object*/
void TrackSpaceAlloc::push_free_objTrack(ObjTrack *objTrack)
{
assert(objTrack->isValidStorage);
objTrack->isValidStorage = false;
objTrackQueue.push(objTrack);
}
/*Pop one free objTrack for use*/
ObjTrack *TrackSpaceAlloc::pop_free_objTrack()
{
if(objTrackQueue.empty())
return NULL;
ObjTrack *objTrack=objTrackQueue.front();
assert(!objTrack->isValidStorage);//First false
objTrack->isValidStorage = true;
objTrackQueue.pop();
return objTrack;
}
/*Pop one free objsubtrack*/
ObjSubTrack *TrackSpaceAlloc::pop_free_objSubTrack()
{
if(objSubTrackQueue.empty())
return NULL;
ObjSubTrack *objSubTrack = objSubTrackQueue.front();
assert(!objSubTrack->isValid);
objSubTrack->isValid = true;
objSubTrack->subTrackNO = IncreaseSubTrackCount();
objSubTrackQueue.pop();
return objSubTrack;
}
/*Push one invalid objsubTrack*/
void TrackSpaceAlloc::push_free_objSubTrack(ObjSubTrack *subTrack)
{
assert(subTrack->isValid);//must be valid first
subTrack->isValid = false;
objSubTrackQueue.push(subTrack);
}