Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r606 - in branches/itanium2: Core/Shm StandAlone
- Date: Fri, 7 Oct 2005 17:30:23 -0600 (MDT)
Author: abe
Date: Fri Oct 7 17:30:16 2005
New Revision: 606
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/StandAlone/mf_stream_test.cc
Log:
Moved shm removal into overloaded delete operators. Since member destructors
are called after the destructor of the containing class, the Semaphore
destructor was being called after the shm segment had already been detached.
M Core/Shm/ShmSemaphore.cc
M Core/Shm/ShmSemaphore.h
M Core/Shm/MFStreamData.cc
M Core/Shm/MFStreamData.h
M StandAlone/mf_stream_test.cc
Modified: branches/itanium2/Core/Shm/MFStreamData.cc
==============================================================================
--- branches/itanium2/Core/Shm/MFStreamData.cc (original)
+++ branches/itanium2/Core/Shm/MFStreamData.cc Fri Oct 7 17:30:16 2005
@@ -76,7 +76,7 @@
// Attach pointer to the memory.
void *this_ptr;
- if ((int)(this_ptr = shmat( id, 0, 0 )) == -1) {
+ if ((long long)(this_ptr = shmat( id, 0, 0 )) == -1) {
throw new ErrnoException( "Cannot attach pointer to shm: ", errno,
__FILE__, __LINE__ );
}
@@ -90,9 +90,36 @@
stream_data->refCount++;
}
+ std::cerr << "Shared memory area: " << std::endl
+ << "size: " << sizeof(MFStreamData) << std::endl
+ << "id: " << stream_data->shmID << std::endl
+ << "key: " << stream_data->key << std::endl
+ << "address: " << this_ptr << std::endl;
+
return this_ptr;
}
+void MFStreamData::operator delete( void *this_ptr ) {
+
+ // Get a pointer to the stream data.
+ MFStreamData *stream_data = (MFStreamData *)this_ptr;
+
+ // Delete the semaphore.
+ delete &(stream_data->semaphore);
+
+ int id = stream_data->shmID;
+
+ // Detach shm
+ if (shmdt( stream_data ) == -1) {
+ throw new ErrnoException("Could not detach shm", errno, __FILE__,
__LINE__);
+ }
+
+ // Remove shm
+ if (shmctl( id, IPC_RMID, 0 ) == -1) {
+ throw new ErrnoException("Could not remove shm", errno, __FILE__,
__LINE__);
+ }
+}
+
MFStreamData::MFStreamData( int xres_, int yres_ ) :
xres( xres_ ),
yres( yres_ ),
@@ -104,18 +131,6 @@
}
MFStreamData::~MFStreamData() {
-
- int id = shmID;
-
- // Detach shm
- if (shmdt( this ) == -1) {
- throw new ErrnoException("Could not detach shm", errno, __FILE__,
__LINE__);
- }
-
- // Remove shm
- if (shmctl( id, IPC_RMID, 0 ) == -1) {
- throw new ErrnoException("Could not detach shm", errno, __FILE__,
__LINE__);
- }
}
void MFStreamData::swap_buffers() {
@@ -123,7 +138,7 @@
// Wait for the memory to be open for writting and then lock it.
int val = semaphore.get_value();
while (val != LOCK_OPEN) {
- SCIRun::Time::waitFor( 0.0001 );
+ SCIRun::Time::waitUntil( SCIRun::Time::currentSeconds()+0.0001 );
val = semaphore.get_value();
}
@@ -151,7 +166,7 @@
int total = copy_xres * copy_yres;
RGBA8Pixel *dest = (RGBA8Pixel *)pixelPool[backBuffer];
-
+
// Copy the pixels from the image on to the back buffer.
if (typeid(*image) == typeid(SimpleImage<RGBA8Pixel>)) {
@@ -159,7 +174,11 @@
// Naive copy
for (int i=0;i<total;++i) {
- dest[i] = src[i];
+ // dest[i] = src[i];
+ dest[i].r = 0;
+ dest[i].g = 255;
+ dest[i].b = 255;
+ dest[i].a = 255;
}
}
Modified: branches/itanium2/Core/Shm/MFStreamData.h
==============================================================================
--- branches/itanium2/Core/Shm/MFStreamData.h (original)
+++ branches/itanium2/Core/Shm/MFStreamData.h Fri Oct 7 17:30:16 2005
@@ -47,7 +47,7 @@
enum { TEXTURE_X_RES = 2560, // Maximum image size.
TEXTURE_Y_RES = 2048,
TEXTURE_Z_RES = 4,
- MAX_NUM_UPDATES = 16,
+ MAX_NUM_UPDATES = 1024,
MAX_NUM_SSCMD = 16, // Specific stream commands.
LOCK_WRITING = 0,
@@ -99,7 +99,8 @@
// Constructor for attaching to an existing shm segment.
MFStreamData() { };
-
+
+ void operator delete( void *this_ptr );
~MFStreamData();
// Swap buffers method.
Modified: branches/itanium2/Core/Shm/ShmSemaphore.cc
==============================================================================
--- branches/itanium2/Core/Shm/ShmSemaphore.cc (original)
+++ branches/itanium2/Core/Shm/ShmSemaphore.cc Fri Oct 7 17:30:16 2005
@@ -67,12 +67,18 @@
}
}
-ShmSemaphore::~ShmSemaphore() {
+void ShmSemaphore::operator delete( void *this_ptr ) {
+ ShmSemaphore *semaphore = (ShmSemaphore *)this_ptr;
+
// Destroy the semaphore.
- if (semctl( id, 0, IPC_RMID ) == -1) {
+ if (semctl( semaphore->id, 0, IPC_RMID ) == -1) {
throw new ErrnoException( "Cannot destroy shm semaphore ", errno,
__FILE__, __LINE__ );
}
+
+}
+
+ShmSemaphore::~ShmSemaphore() {
}
Modified: branches/itanium2/Core/Shm/ShmSemaphore.h
==============================================================================
--- branches/itanium2/Core/Shm/ShmSemaphore.h (original)
+++ branches/itanium2/Core/Shm/ShmSemaphore.h Fri Oct 7 17:30:16 2005
@@ -45,6 +45,8 @@
public:
ShmSemaphore( int key_, int init_val_ );
ShmSemaphore() { };
+
+ void operator delete( void *this_ptr );
~ShmSemaphore();
void post();
Modified: branches/itanium2/StandAlone/mf_stream_test.cc
==============================================================================
--- branches/itanium2/StandAlone/mf_stream_test.cc (original)
+++ branches/itanium2/StandAlone/mf_stream_test.cc Fri Oct 7 17:30:16
2005
@@ -32,15 +32,20 @@
try {
stream_data = new(key, false) MFStreamData;
std::cerr << "Acquired Successfully" << std::endl;
+
+ for (int i=0;i<10;++i) {
+ std::cerr << "front: " << stream_data->frontBuffer << " back: " <<
stream_data->backBuffer << std::endl;
+ SCIRun::Time::waitUntil( SCIRun::Time::currentSeconds()+0.5 );
+ }
+
+ delete stream_data;
}
catch (SCIRun::Exception *e) {
std::cerr << "Caught Exception: " << e->message() << std::endl;
}
- while (1) {
- std::cerr << "front: " << stream_data->frontBuffer << " back: " <<
stream_data->backBuffer << std::endl;
- SCIRun::Time::waitUntil( SCIRun::Time::currentSeconds()+0.5 );
- }
+
+
return 1;
};
- [MANTA] r606 - in branches/itanium2: Core/Shm StandAlone, abe, 10/07/2005
Archive powered by MHonArc 2.6.16.