no more use of LinkedList in BaseDisplay

This commit is contained in:
Dana Jansens 2002-05-12 22:40:32 +00:00
parent eb8a11a5a7
commit d58f7b569e
2 changed files with 26 additions and 21 deletions

View file

@ -338,8 +338,6 @@ BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) {
XSetErrorHandler((XErrorHandler) handleXErrors); XSetErrorHandler((XErrorHandler) handleXErrors);
timerList = new LinkedList<BTimer>;
screenInfoList.reserve(ScreenCount(display)); screenInfoList.reserve(ScreenCount(display));
for (int i = 0; i < number_of_screens; i++) for (int i = 0; i < number_of_screens; i++)
screenInfoList.push_back(new ScreenInfo(*this, i)); screenInfoList.push_back(new ScreenInfo(*this, i));
@ -392,12 +390,7 @@ BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) {
BaseDisplay::~BaseDisplay(void) { BaseDisplay::~BaseDisplay(void) {
std::for_each(screenInfoList.begin(), screenInfoList.end(), std::for_each(screenInfoList.begin(), screenInfoList.end(),
PointerAssassin()); PointerAssassin());
// we don't create the BTimers, we don't delete them // we don't create the BTimers, we don't delete them
while (timerList->count())
timerList->remove(0);
delete timerList;
if (application_name != NULL) if (application_name != NULL)
delete [] application_name; delete [] application_name;
@ -434,12 +427,13 @@ void BaseDisplay::eventLoop(void) {
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(xfd, &rfds); FD_SET(xfd, &rfds);
if (timerList->count()) { if (!timerList.empty()) {
gettimeofday(&now, 0); gettimeofday(&now, 0);
tm.tv_sec = tm.tv_usec = 0l; tm.tv_sec = tm.tv_usec = 0l;
BTimer *timer = timerList->first(); BTimer *timer = timerList.front();
ASSERT(timer != NULL);
tm.tv_sec = timer->getStartTime().tv_sec + tm.tv_sec = timer->getStartTime().tv_sec +
timer->getTimeout().tv_sec - now.tv_sec; timer->getTimeout().tv_sec - now.tv_sec;
@ -469,8 +463,11 @@ void BaseDisplay::eventLoop(void) {
// check for timer timeout // check for timer timeout
gettimeofday(&now, 0); gettimeofday(&now, 0);
LinkedListIterator<BTimer> it(timerList); TimerList::iterator it;
for(BTimer *timer = it.current(); timer; it++, timer = it.current()) { for (it = timerList.begin(); it != timerList.end(); ) {
BTimer *timer = *it;
++it; // the timer may be removed from the list, so move ahead now
ASSERT(timer != NULL);
tm.tv_sec = timer->getStartTime().tv_sec + tm.tv_sec = timer->getStartTime().tv_sec +
timer->getTimeout().tv_sec; timer->getTimeout().tv_sec;
tm.tv_usec = timer->getStartTime().tv_usec + tm.tv_usec = timer->getStartTime().tv_usec +
@ -483,8 +480,12 @@ void BaseDisplay::eventLoop(void) {
timer->fireTimeout(); timer->fireTimeout();
// restart the current timer so that the start time is updated // restart the current timer so that the start time is updated
if (! timer->doOnce()) timer->start(); if (! timer->doOnce())
else timer->stop(); timer->start();
else {
timer->stop();
// delete timer; // USE THIS?
}
} }
} }
} }
@ -518,22 +519,25 @@ void BaseDisplay::ungrab(void) {
void BaseDisplay::addTimer(BTimer *timer) { void BaseDisplay::addTimer(BTimer *timer) {
if (! timer) return; ASSERT(timer != (BTimer *) 0);
printf("ADDING TIMER\n");
LinkedListIterator<BTimer> it(timerList); TimerList::iterator it;
int index = 0; for (it = timerList.begin(); it != timerList.end(); ++it) {
for (BTimer *tmp = it.current(); tmp; it++, index++, tmp = it.current()) BTimer *tmp = *it;
if ((tmp->getTimeout().tv_sec > timer->getTimeout().tv_sec) || if ((tmp->getTimeout().tv_sec > timer->getTimeout().tv_sec) ||
((tmp->getTimeout().tv_sec == timer->getTimeout().tv_sec) && ((tmp->getTimeout().tv_sec == timer->getTimeout().tv_sec) &&
(tmp->getTimeout().tv_usec >= timer->getTimeout().tv_usec))) (tmp->getTimeout().tv_usec >= timer->getTimeout().tv_usec)))
break; break;
}
timerList->insert(timer, index); timerList.insert(it, timer);
} }
void BaseDisplay::removeTimer(BTimer *timer) { void BaseDisplay::removeTimer(BTimer *timer) {
timerList->remove(timer); printf("REMOVING TIMER\n");
timerList.remove(timer);
} }

View file

@ -30,11 +30,11 @@
class BaseDisplay; class BaseDisplay;
class ScreenInfo; class ScreenInfo;
#include "LinkedList.h"
#include "Timer.h" #include "Timer.h"
#include "Geometry.h" #include "Geometry.h"
#include "Util.h" #include "Util.h"
#include <vector> #include <vector>
#include <list>
#define AttribShaded (1l << 0) #define AttribShaded (1l << 0)
#define AttribMaxHoriz (1l << 1) #define AttribMaxHoriz (1l << 1)
@ -133,7 +133,8 @@ private:
typedef std::vector<ScreenInfo*> ScreenInfoList; typedef std::vector<ScreenInfo*> ScreenInfoList;
ScreenInfoList screenInfoList; ScreenInfoList screenInfoList;
LinkedList<BTimer> *timerList; typedef std::list<BTimer*> TimerList;
TimerList timerList;
char *display_name, *application_name; char *display_name, *application_name;
int number_of_screens, server_grabs, colors_per_channel; int number_of_screens, server_grabs, colors_per_channel;