WorkQueue.h

Go to the documentation of this file.
00001 #ifndef WorkQueue_HEADER
00002 #define WorkQueue_HEADER
00003 
00004 #ifdef HAVE_CONFIG_H
00005 # include <config.h>
00006 #endif
00007 
00008 #include <deque>
00009 #include <boost/array.hpp>
00010 #include "MeshTypes.h"
00011 #include "WorkItem.h"
00012 #include <utilities/BucketPQ.h>
00013 
00014 #if 0
00015 #define dprintf(...) printf(__VA_ARGS__);
00016 #else
00017 #define dprintf(...)
00018 #endif
00019 
00020 
00024 template <size_t ambient>
00025 class WorkQueue {
00026   typedef ::WorkItem<ambient> WorkItem;
00027 
00033   struct WorkItemQueue {
00034     boost::array<hudson::BucketDoublePQ<WorkItem*>, ambient+1> queues_;
00035     // boost::array<hudson::FrontStack<WorkItem*>, ambient+1> queues_;
00036 
00037     void push(WorkItem* w) {
00038       assert(w); // no nulls
00039       queues_[w->topological()].push(w->size(), w);
00040       // queues_[w->topological()].push(w);
00041     }
00042 
00043     WorkItem *pop() {
00044       for(size_t i = 0; i <= ambient; ++i) {
00045         if (!queues_[i].empty()) {
00046           WorkItem *w = queues_[i].top();
00047           queues_[i].pop();
00048           return w;
00049         }
00050       }
00051       return NULL;
00052     }
00053   };
00054 
00055   public:
00059   void push(WorkItem *w) {
00060     assert(w);
00061     assert(w->getReason() < WorkItem::NONE);
00062     dprintf("  pushing %s\n", w->toString().c_str());
00063     queues_[w->getReason()].push(w);
00064   }
00065 
00068   WorkItem *pop() {
00069     for(size_t r = 0; r < WorkItem::NONE; ++r) {
00070       WorkItem *item = queues_[r].pop();
00071       if (item) return item;
00072     }
00073 
00074     // Nothing:  All queues are empty.
00075     return NULL;
00076   }
00077 
00078   private:
00079   boost::array<WorkItemQueue, WorkItem::NONE> queues_;
00080 };
00081 
00082 #undef dprintf
00083 
00084 #endif

Generated on Thu Mar 27 19:04:14 2008 by  doxygen 1.4.6