Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r685 - in branches/itanium2: Core/Shm fox


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r685 - in branches/itanium2: Core/Shm fox
  • Date: Tue, 1 Nov 2005 00:40:14 -0700 (MST)

Author: abe
Date: Tue Nov  1 00:40:08 2005
New Revision: 685

Modified:
   branches/itanium2/Core/Shm/MFStreamData.cc
   branches/itanium2/Core/Shm/MFStreamData.h
   branches/itanium2/Core/Shm/ShmSemaphore.cc
   branches/itanium2/Core/Shm/ShmSemaphore.h
   branches/itanium2/fox/MediaFusionBridge.cc
Log:

Attempted to implement second semaphore for command locking but I think I 
broke pretty much everything although its hard to tell since I can't run 
anything worth while over vpn.

M    Core/Shm/ShmSemaphore.cc
M    Core/Shm/ShmSemaphore.h
M    Core/Shm/MFStreamData.cc
M    Core/Shm/MFStreamData.h
M    fox/MediaFusionBridge.cc


Modified: branches/itanium2/Core/Shm/MFStreamData.cc
==============================================================================
--- branches/itanium2/Core/Shm/MFStreamData.cc  (original)
+++ branches/itanium2/Core/Shm/MFStreamData.cc  Tue Nov  1 00:40:08 2005
@@ -44,6 +44,7 @@
 #include <time.h>
 
 #include <errno.h>
+#include <unistd.h>
 
 using namespace Manta;
 using namespace SCIRun;
@@ -129,7 +130,7 @@
   zres( 4 ),
   frontBuffer( 0 ),
   backBuffer ( 1 ), 
-  semaphore( key, LOCK_OPEN ),
+  semaphore( key, LOCK_OPEN, 2 ),
 
   counter( 0 ),  // Initialize with zero updates.
   numSSCMD( 0 )  // Initalize with zero commands.
@@ -150,14 +151,14 @@
 void MFStreamData::swap_buffers() {
 
   // Wait for the memory to be open for writting and then lock it.
-  int val = semaphore.get_value();
-  while (val != LOCK_OPEN) {
-    SCIRun::Time::waitUntil( SCIRun::Time::currentSeconds()+0.0001 );
-    val = semaphore.get_value();
+  int val = semaphore.get_value( SEMAPHORE_PIXEL );
+  while (val == 1) {
+    usleep( 1000 );
+    val = semaphore.get_value( SEMAPHORE_PIXEL );
   }
 
   // Decrement the semaphore to 0.
-  semaphore.try_wait();
+  semaphore.post( SEMAPHORE_PIXEL );
 
   // Switch the back and front buffers.
   backBuffer  = !backBuffer;
@@ -167,7 +168,7 @@
   counter++;
   
   // Increment the semaphore to 1, unlock the shm.
-  semaphore.post();  
+  semaphore.wait( SEMAPHORE_PIXEL );  
 }
 
 void MFStreamData::draw_pixels( const Image *image ) {
@@ -200,8 +201,15 @@
 
 void MFStreamData::read_commands( MFSPacket &packet ) {
 
-  semaphore.wait();
-  
+  // Wait until the semaphore is available
+  int val = semaphore.get_value( SEMAPHORE_CMD  );
+  while( val == 1 ) {
+      usleep( 1000 );
+      val = semaphore.get_value( SEMAPHORE_CMD  );
+  }
+
+  semaphore.post( SEMAPHORE_CMD );
+
   // Copy the current commands out of the shm segment.
   // Nigel: what locking is necessary.
   int i;
@@ -216,7 +224,7 @@
   // Set the internal counter back to zero.
   numSSCMD = 0;
 
-  semaphore.post();
+  semaphore.wait( SEMAPHORE_CMD );
 }
 
 

Modified: branches/itanium2/Core/Shm/MFStreamData.h
==============================================================================
--- branches/itanium2/Core/Shm/MFStreamData.h   (original)
+++ branches/itanium2/Core/Shm/MFStreamData.h   Tue Nov  1 00:40:08 2005
@@ -61,7 +61,9 @@
            
            LOCK_WRITING    = 0,
            LOCK_OPEN       = 1,
-           LOCK_READING    = 2
+
+           SEMAPHORE_PIXEL = 0,
+           SEMAPHORE_CMD   = 1
     };
 
     
/////////////////////////////////////////////////////////////////////////////

Modified: branches/itanium2/Core/Shm/ShmSemaphore.cc
==============================================================================
--- branches/itanium2/Core/Shm/ShmSemaphore.cc  (original)
+++ branches/itanium2/Core/Shm/ShmSemaphore.cc  Tue Nov  1 00:40:08 2005
@@ -45,7 +45,7 @@
 using namespace Manta;
 using namespace SCIRun;
 
-ShmSemaphore::ShmSemaphore( int key_, int init_val_ ) {
+ShmSemaphore::ShmSemaphore( int key_, int init_val_, int set_size_ ) {
 
   union semun {
     int val;
@@ -55,23 +55,26 @@
   arg;
 
   // Create the semaphore.
-  id = semget( key_, 1, PERM_FILE|IPC_CREAT );
+  id = semget( key_, set_size_, PERM_FILE|IPC_CREAT );
   if (id == -1) {
     throw new ErrnoException( "Cannot create shm semaphore ", errno, 
__FILE__, __LINE__ );     
   }
 
   // Set the semaphore value.
-  arg.val = init_val_;
-  if (semctl( id, 0, SETVAL, arg ) == -1) {
-    throw new ErrnoException( "Cannot set shm semaphore value ", errno, 
__FILE__, __LINE__ ); 
+  for (int i=0;i<set_size_;++i) {
+    arg.val = init_val_; 
+    if (semctl( id, 0, SETVAL, arg ) == -1) {
+      throw new ErrnoException( "Cannot set shm semaphore value ", errno, 
__FILE__, __LINE__ ); 
+    }
   }
+
 }
 
 void ShmSemaphore::operator delete( void *this_ptr ) {
 
   ShmSemaphore *semaphore = (ShmSemaphore *)this_ptr;
   
-  // Destroy the semaphore.
+  // Destroy the semaphore, semaphore number is ignored.
   if (semctl( semaphore->id, 0, IPC_RMID ) == -1) {
     throw new ErrnoException( "Cannot destroy shm semaphore ", errno, 
__FILE__, __LINE__ );
   }
@@ -82,27 +85,27 @@
 }
 
 
-void ShmSemaphore::post() {
+void ShmSemaphore::post( int index ) {
 
-  struct sembuf sbuf = { 0, 1, 0 };
+  struct sembuf sbuf = { index, 1, 0 };
 
   if (semop( id, &sbuf, 1 ) == -1) {
     throw new ErrnoException( "Cannot post shm semaphore ", errno, __FILE__, 
__LINE__ );     
   }
 }
 
-void ShmSemaphore::wait() {
+void ShmSemaphore::wait( int index ) {
 
-  struct sembuf sbuf = { 0, -1, 0 };
+  struct sembuf sbuf = { index, -1, 0 };
 
   if (semop( id, &sbuf, 1 ) == -1) {
     throw new ErrnoException( "Cannot wait on shm semaphore ", errno, 
__FILE__, __LINE__ );     
   }  
 }
 
-bool ShmSemaphore::try_wait() {
+bool ShmSemaphore::try_wait( int index ) {
 
-  struct sembuf sbuf = { 0, -1, IPC_NOWAIT };
+  struct sembuf sbuf = { index, -1, IPC_NOWAIT };
 
   if (semop( id, &sbuf, 1 ) == -1) {
     if (errno != EAGAIN)
@@ -113,9 +116,9 @@
   return true;
 }
 
-int  ShmSemaphore::get_value() {
+int  ShmSemaphore::get_value( int index ) {
   
-  return semctl( id, 0, GETVAL, 0 );
+  return semctl( id, index, GETVAL, 0 );
 }
 
 

Modified: branches/itanium2/Core/Shm/ShmSemaphore.h
==============================================================================
--- branches/itanium2/Core/Shm/ShmSemaphore.h   (original)
+++ branches/itanium2/Core/Shm/ShmSemaphore.h   Tue Nov  1 00:40:08 2005
@@ -43,16 +43,20 @@
     int id;
     
   public:
-    ShmSemaphore( int key_, int init_val_ );
+    ShmSemaphore( int key_, int init_val_, int set_size_ );
     ShmSemaphore() { };
 
     void operator delete( void *this_ptr );
     ~ShmSemaphore();
 
-    void post();
-    void wait();
-    bool try_wait();
-    int  get_value();
+    // Increment
+    void post( int index );
+
+    // Deincrement
+    void wait( int index );
+    bool try_wait( int index );
+
+    int  get_value( int index );
     
   };
   

Modified: branches/itanium2/fox/MediaFusionBridge.cc
==============================================================================
--- branches/itanium2/fox/MediaFusionBridge.cc  (original)
+++ branches/itanium2/fox/MediaFusionBridge.cc  Tue Nov  1 00:40:08 2005
@@ -67,7 +67,9 @@
 void MediaFusionBridge::run() {
 
   // Attach to the shm segment.
-  std::cerr << "Listening for MediaFusion commands..." << std::endl;
+  std::cerr << "Listening for MediaFusion commands using key "
+            << shm_key
+            << "..." << std::endl;
 
   try {
     stream_data = new( shm_key, false ) MFStreamData;
@@ -99,10 +101,21 @@
 
     // Read commands from the stream.
     stream_data->read_commands( packet );
+
+    // Find the next command that we have not processed in the packet.
+    int i = 0;
+    while ((packet.index[i] <= last_index) && (i < packet.size)) {
+
+      std::cerr << "Stale command in packet: " << packet.index[i]
+                << " last index: " << last_index
+                << std::endl;
+      
+      ++i;
+    }
     
     // Process the command.
     for (int i=0;i<packet.size;++i) {
-
+      
       // Check to see if we have missed any commands.
       if (packet.index[i] != (last_index+1)) {
         std::cerr << "Warning missed command: " << last_index
@@ -110,6 +123,8 @@
       }
       last_index = packet.index[i];
 
+      // std::cerr << "Received command from media fusion" << std::endl;
+      
       // Dispatch the command.
       switch (packet.command[i]) {
 




  • [MANTA] r685 - in branches/itanium2: Core/Shm fox, abe, 11/01/2005

Archive powered by MHonArc 2.6.16.

Top of page