door closed by defaul and vcg:: namespave

This commit is contained in:
Federico Ponchio 2012-05-29 12:14:27 +00:00
parent 75ebfa9d5a
commit 0d4a84f012
4 changed files with 204 additions and 191 deletions

View File

@ -21,6 +21,8 @@ using namespace std;
/** 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>
@ -116,6 +118,7 @@ public:
}
virtual void abort() {}
protected:
///return the space used in the cache by the loaded resource
virtual int size(Token *token) = 0;
@ -130,6 +133,7 @@ protected:
///called in as first thing in run()
virtual void begin() {}
virtual void middle() {}
///called in as last thing in run()
virtual void end() {}
@ -142,9 +146,11 @@ protected:
2) make room until eliminating an element would leave space. */
begin();
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;
middle();
if(unload() || load()) {
new_data.testAndSetOrdered(0, 1); //if not changed, set as changed
input->check_queue.open(); //we signal ourselves to check again
@ -165,7 +171,6 @@ protected:
//make room int the cache checking that:
//1 we need to make room (capacity < current)
if(size() > capacity()) {
mt::mutexlocker locker(&(this->heap_lock));
//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
remove = this->heap.popMin();
this->heap.push(remove);
cout << "Reordering stack something (what?)\n";
return true;
}
}
@ -201,6 +207,7 @@ protected:
s_curr -= size;
input->heap.push(remove);
}
cout << "Removing something (what?)\n";
return true;
}
return false;
@ -260,6 +267,7 @@ protected:
}
};
} //namespace
/* TODO use the following class to allow multiple cache transfers at the same time */
/*

View File

@ -5,6 +5,7 @@
/** Allows to insert tokens, update priorities and generally control the cache.
*/
namespace vcg {
template <class Token>
class Controller {
@ -66,7 +67,6 @@ class Controller {
///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...
void updatePriorities() {
if(tokens.size()) {
mt::mutexlocker l(&provider.heap_lock);
for(unsigned int i = 0; i < tokens.size(); i++)
@ -140,6 +140,7 @@ class Controller {
void resume() {
assert(!stopped);
assert(paused);
cout << "Resume" << endl;
//unlock and open all doors
for(unsigned int i = 0; i < caches.size(); i++) {
@ -177,5 +178,5 @@ class Controller {
}
};
} //namespace
#endif // CONTROLLER_H

View File

@ -17,6 +17,8 @@
You should never interact with this class.
*/
namespace vcg {
template <typename Token>
class Provider: public mt::thread {
public:
@ -76,5 +78,5 @@ class Provider: public mt::thread {
}
};
} //namespace
#endif

View File

@ -15,6 +15,7 @@
The Priority template argument can simply be a floating point number
or something more complex, (frame and error in pixel); the only
requirement is the existence of a < comparison operator */
namespace vcg {
template <typename Priority>
class Token {
@ -83,4 +84,5 @@ class Token {
}
};
} //namespace
#endif // GCACHE_H