door closed by defaul and vcg:: namespave
This commit is contained in:
parent
75ebfa9d5a
commit
0d4a84f012
|
@ -21,6 +21,8 @@ using namespace std;
|
||||||
/** Cache virtual base class. You are required to implement the pure virtual functions get, drop and size.
|
/** Cache virtual base class. You are required to implement the pure virtual functions get, drop and size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
|
||||||
template <typename Token> class Transfer;
|
template <typename Token> class Transfer;
|
||||||
|
|
||||||
template <typename Token>
|
template <typename Token>
|
||||||
|
@ -116,6 +118,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void abort() {}
|
virtual void abort() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///return the space used in the cache by the loaded resource
|
///return the space used in the cache by the loaded resource
|
||||||
virtual int size(Token *token) = 0;
|
virtual int size(Token *token) = 0;
|
||||||
|
@ -130,6 +133,7 @@ protected:
|
||||||
|
|
||||||
///called in as first thing in run()
|
///called in as first thing in run()
|
||||||
virtual void begin() {}
|
virtual void begin() {}
|
||||||
|
virtual void middle() {}
|
||||||
///called in as last thing in run()
|
///called in as last thing in run()
|
||||||
virtual void end() {}
|
virtual void end() {}
|
||||||
|
|
||||||
|
@ -142,9 +146,11 @@ protected:
|
||||||
2) make room until eliminating an element would leave space. */
|
2) make room until eliminating an element would leave space. */
|
||||||
begin();
|
begin();
|
||||||
while(!this->quit) {
|
while(!this->quit) {
|
||||||
input->check_queue.enter(); //wait for cache below to load something or priorities to change
|
input->check_queue.enter(true); //wait for cache below to load something or priorities to change
|
||||||
if(this->quit) break;
|
if(this->quit) break;
|
||||||
|
|
||||||
|
middle();
|
||||||
|
|
||||||
if(unload() || load()) {
|
if(unload() || load()) {
|
||||||
new_data.testAndSetOrdered(0, 1); //if not changed, set as changed
|
new_data.testAndSetOrdered(0, 1); //if not changed, set as changed
|
||||||
input->check_queue.open(); //we signal ourselves to check again
|
input->check_queue.open(); //we signal ourselves to check again
|
||||||
|
@ -165,7 +171,6 @@ protected:
|
||||||
//make room int the cache checking that:
|
//make room int the cache checking that:
|
||||||
//1 we need to make room (capacity < current)
|
//1 we need to make room (capacity < current)
|
||||||
if(size() > capacity()) {
|
if(size() > capacity()) {
|
||||||
|
|
||||||
mt::mutexlocker locker(&(this->heap_lock));
|
mt::mutexlocker locker(&(this->heap_lock));
|
||||||
|
|
||||||
//2 we have some element not in the upper caches (heap.size() > 0
|
//2 we have some element not in the upper caches (heap.size() > 0
|
||||||
|
@ -186,6 +191,7 @@ protected:
|
||||||
} else { //last item is locked need to reorder stack
|
} else { //last item is locked need to reorder stack
|
||||||
remove = this->heap.popMin();
|
remove = this->heap.popMin();
|
||||||
this->heap.push(remove);
|
this->heap.push(remove);
|
||||||
|
cout << "Reordering stack something (what?)\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +207,7 @@ protected:
|
||||||
s_curr -= size;
|
s_curr -= size;
|
||||||
input->heap.push(remove);
|
input->heap.push(remove);
|
||||||
}
|
}
|
||||||
|
cout << "Removing something (what?)\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -260,6 +267,7 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} //namespace
|
||||||
/* TODO use the following class to allow multiple cache transfers at the same time */
|
/* TODO use the following class to allow multiple cache transfers at the same time */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
/** Allows to insert tokens, update priorities and generally control the cache.
|
/** Allows to insert tokens, update priorities and generally control the cache.
|
||||||
*/
|
*/
|
||||||
|
namespace vcg {
|
||||||
|
|
||||||
template <class Token>
|
template <class Token>
|
||||||
class Controller {
|
class Controller {
|
||||||
|
@ -66,7 +67,6 @@ class Controller {
|
||||||
///ensure that added tokens are processed and existing ones have their priority updated.
|
///ensure that added tokens are processed and existing ones have their priority updated.
|
||||||
///potential bug! update is done on the heaps, if something is in transit...
|
///potential bug! update is done on the heaps, if something is in transit...
|
||||||
void updatePriorities() {
|
void updatePriorities() {
|
||||||
|
|
||||||
if(tokens.size()) {
|
if(tokens.size()) {
|
||||||
mt::mutexlocker l(&provider.heap_lock);
|
mt::mutexlocker l(&provider.heap_lock);
|
||||||
for(unsigned int i = 0; i < tokens.size(); i++)
|
for(unsigned int i = 0; i < tokens.size(); i++)
|
||||||
|
@ -140,6 +140,7 @@ class Controller {
|
||||||
void resume() {
|
void resume() {
|
||||||
assert(!stopped);
|
assert(!stopped);
|
||||||
assert(paused);
|
assert(paused);
|
||||||
|
cout << "Resume" << endl;
|
||||||
|
|
||||||
//unlock and open all doors
|
//unlock and open all doors
|
||||||
for(unsigned int i = 0; i < caches.size(); i++) {
|
for(unsigned int i = 0; i < caches.size(); i++) {
|
||||||
|
@ -177,5 +178,5 @@ class Controller {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} //namespace
|
||||||
#endif // CONTROLLER_H
|
#endif // CONTROLLER_H
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
You should never interact with this class.
|
You should never interact with this class.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
|
||||||
template <typename Token>
|
template <typename Token>
|
||||||
class Provider: public mt::thread {
|
class Provider: public mt::thread {
|
||||||
public:
|
public:
|
||||||
|
@ -76,5 +78,5 @@ class Provider: public mt::thread {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} //namespace
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
The Priority template argument can simply be a floating point number
|
The Priority template argument can simply be a floating point number
|
||||||
or something more complex, (frame and error in pixel); the only
|
or something more complex, (frame and error in pixel); the only
|
||||||
requirement is the existence of a < comparison operator */
|
requirement is the existence of a < comparison operator */
|
||||||
|
namespace vcg {
|
||||||
|
|
||||||
template <typename Priority>
|
template <typename Priority>
|
||||||
class Token {
|
class Token {
|
||||||
|
@ -83,4 +84,5 @@ class Token {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} //namespace
|
||||||
#endif // GCACHE_H
|
#endif // GCACHE_H
|
||||||
|
|
Loading…
Reference in New Issue