2
class for managing byte positions and associated time positions
3
Copyright (C) 1999 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
14
#include "timeStampArray.h"
18
TimeStampArray::TimeStampArray(char* aName,int entries) {
24
this->entries=entries;
26
cout << "TimeStampArray entries must be >= 1";
31
abs_thread_mutex_init(&writeInMut);
32
abs_thread_mutex_init(&changeMut);
38
tStampArray=new TimeStamp*[entries];
40
for(i=0;i<entries;i++) {
41
tStampArray[i]=new TimeStamp();
47
TimeStampArray::~TimeStampArray() {
50
for(i=0;i<entries;i++) {
51
delete tStampArray[i];
55
delete name; // allocated with strdup
57
abs_thread_mutex_destroy(&writeInMut);
58
abs_thread_mutex_destroy(&changeMut);
61
TimeStamp* TimeStampArray::getReadTimeStamp() {
62
return tStampArray[readPos];
66
int TimeStampArray::getFillgrade() {
70
int TimeStampArray::insertTimeStamp(TimeStamp* src,long key,int len) {
76
src->copyTo(tStampArray[writePos]);
77
tStampArray[writePos]->setKey(key,len);
80
if (tStampArray[lastWritePos]->getKey() == key) {
87
lastWritePos=writePos;
90
if (writePos == entries) {
93
if (fillgrade == entries) {
94
cout << name<<" TimeStampArray::array overfull forward"<<endl;
103
int TimeStampArray::bytesUntilNext(long key) {
105
TimeStamp* current=tStampArray[readPos];
106
int back=current->getKey()-key;
111
TimeStamp* TimeStampArray::getTimeStamp(long key) {
113
TimeStamp* back=tStampArray[readPos];
114
if (key > back->getKey()+back->getKeyLen()) {
118
return getTimeStamp(key);
123
if (back->getKey() > key) {
124
cout << "key "<<key<<" too big"<<back->getKey()-key<<endl;
125
back->print("key access");
129
/* maybe we should return NULL here to indicate
130
that there is no valid timestamp */
131
/* This would need a check for every getTimeStamp call
132
I think returning the last available stamp is ok
138
void TimeStampArray::forward() {
146
void TimeStampArray::clear() {
155
void TimeStampArray::lockStampArray() {
157
abs_thread_mutex_lock(&changeMut);
158
abs_thread_mutex_lock(&writeInMut);
159
abs_thread_mutex_unlock(&changeMut);
164
void TimeStampArray::unlockStampArray() {
165
abs_thread_mutex_unlock(&writeInMut);
169
void TimeStampArray::internalForward() {
172
if (readPos == entries) {