Text archives Help
- From: cgribble@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1149 - in trunk: Engine/Control scenes
- Date: Wed, 19 Jul 2006 18:50:36 -0600 (MDT)
Author: cgribble
Date: Wed Jul 19 18:50:34 2006
New Revision: 1149
Modified:
trunk/Engine/Control/DynPLTQueue.cc
trunk/Engine/Control/DynPLTQueue.h
trunk/scenes/dynplt.cc
Log:
Added simple LIFO queue
Modified: trunk/Engine/Control/DynPLTQueue.cc
==============================================================================
--- trunk/Engine/Control/DynPLTQueue.cc (original)
+++ trunk/Engine/Control/DynPLTQueue.cc Wed Jul 19 18:50:34 2006
@@ -7,10 +7,92 @@
using namespace Manta;
+DynPLTLifoQ::DynPLTLifoQ(int size) :
+ mutex("LifoQ lock"), empty("LifoQ empty condition"),
+ full("LifoQ full condition"), top(-1), max_size(size)
+{
+ cerr<<"max_size = "<<max_size<<'\n';
+
+ // Allocate dataspace
+ dataspace=new char[max_size*sizeof(DynPLTMessage)];
+ queue=reinterpret_cast<DynPLTMessage*>(dataspace);
+}
+
+DynPLTLifoQ::~DynPLTLifoQ(void)
+{
+ // Release all waiting threads
+ empty.conditionBroadcast();
+ full.conditionBroadcast();
+
+ // Free dataspace
+ delete [] dataspace;
+}
+
+bool DynPLTLifoQ::tryReceive(DynPLTMessage& msg)
+{
+ mutex.lock();
+
+ // Return false if queue is empty
+ if (top==-1) {
+ mutex.unlock();
+ return false;
+ }
+
+ // Pop top item from the queue
+ msg=pop();
+
+ mutex.unlock();
+
+ return true;
+}
+
+DynPLTMessage DynPLTLifoQ::receive(void)
+{
+ mutex.lock();
+
+ // Block calling thread while queue is empty
+ while (top==-1)
+ empty.wait(mutex);
+
+ // Pop top item from the queue
+ DynPLTMessage msg=pop();
+
+ mutex.unlock();
+
+ return msg;
+}
+
+bool DynPLTLifoQ::trySend(const DynPLTMessage& msg)
+{
+ mutex.lock();
+
+ // Return false if queue is full
+ if (top==max_size - 1) {
+ mutex.unlock();
+ return false;
+ }
+
+ push(msg);
+ mutex.unlock();
+
+ return true;
+}
+
+void DynPLTLifoQ::send(const DynPLTMessage& msg)
+{
+ mutex.lock();
+
+ // Block calling thread while queue is full
+ while (top==max_size - 1)
+ full.wait(mutex);
+
+ push(msg);
+ mutex.unlock();
+}
+
DynPLTPriorityQ::DynPLTPriorityQ(int size) :
mutex("PriorityQ lock"), empty("PriorityQ empty condition"),
- full("PriorityQ full condition"), nheap(0),
- max_size(size)
+ full("PriorityQ full condition"), nheap(0), max_size(size)
{
// Allocate dataspace
dataspace=new char[max_size*sizeof(DynPLTMessage)];
Modified: trunk/Engine/Control/DynPLTQueue.h
==============================================================================
--- trunk/Engine/Control/DynPLTQueue.h (original)
+++ trunk/Engine/Control/DynPLTQueue.h Wed Jul 19 18:50:34 2006
@@ -10,6 +10,10 @@
#include <float.h>
+// XXX: temporary
+#include <iostream>
+using std::cerr;
+
using namespace SCIRun;
namespace Manta
@@ -89,15 +93,41 @@
mailbox->send(msg);
}
- void updatePriority(int particle, Real t)
- {
- // Do nothing
- }
+ void updatePriority(int particle, Real t) { /* no-op */ }
private:
SCIRun::Mailbox<DynPLTMessage>* mailbox;
};
+ class DynPLTLifoQ : public DynPLTQueue
+ {
+ public:
+ DynPLTLifoQ(int size);
+ ~DynPLTLifoQ(void);
+
+ bool tryReceive(DynPLTMessage& msg);
+ DynPLTMessage receive(void);
+ bool trySend(const DynPLTMessage& msg);
+ void send(const DynPLTMessage& msg);
+
+ void updatePriority(int particle, Real t) { /* no-op */ }
+
+ private:
+ void push(DynPLTMessage const& msg) { queue[++top]=msg; }
+ DynPLTMessage pop(void) { return queue[top--]; }
+
+ // Thread control
+ Mutex mutex;
+ ConditionVariable empty;
+ ConditionVariable full;
+
+ // Data variables
+ DynPLTMessage* queue;
+ char* dataspace;
+ int max_size;
+ int top;
+ };
+
class DynPLTPriorityQ : public DynPLTQueue
{
public:
@@ -123,8 +153,8 @@
// Data variables
DynPLTMessage* heap;
char* dataspace;
- unsigned int max_size;
- unsigned int nheap;
+ int max_size;
+ int nheap;
};
}
Modified: trunk/scenes/dynplt.cc
==============================================================================
--- trunk/scenes/dynplt.cc (original)
+++ trunk/scenes/dynplt.cc Wed Jul 19 18:50:34 2006
@@ -42,6 +42,7 @@
int depth=1;
bool dilate=false;
bool fifo=false;
+ bool lifo=false;
int max_depth=3;
int ncells=2;
int ngroups=100;
@@ -75,6 +76,7 @@
dilate=true;
} else if (arg=="-fifo") {
fifo=true;
+ lifo=false;
} else if (arg=="-envmap") {
string s;
if (!getStringArg(i, args, s))
@@ -94,6 +96,9 @@
} else if (arg=="-i") {
if (!getStringArg(i, args, fname))
throw IllegalArgument("scene dynplt -i", i, args);
+ } else if (arg=="-lifo") {
+ fifo=false;
+ lifo=true;
} else if (arg=="-nbounces") {
if (!getIntArg(i, args, max_depth))
throw IllegalArgument("scene dynplt -nbounces", i, args);
@@ -164,6 +169,9 @@
DynPLTQueue* queue;
if (fifo) {
queue=new DynPLTFifoQ(nthreads*qsize);
+ cerr<<"Using FIFO Queue\n";
+ } else if (lifo) {
+ queue=new DynPLTLifoQ(nthreads*qsize);
cerr<<"Using FIFO Queue\n";
} else {
queue=new DynPLTPriorityQ(nthreads*qsize);
- [MANTA] r1149 - in trunk: Engine/Control scenes, cgribble, 07/19/2006
Archive powered by MHonArc 2.6.16.