Alan W. Irwin
2017-02-05 10:18:28 UTC
1. Make the current one-semaphore approach work with unnamed
semaphores. The last commit put essentially all the infrastructure in
place to support this further change so this change should be a simple
matter of replacing (for this case) the calls to sem_open and
sem_close with sem_init and sem_destroy, and the rest of the current
one-semaphore code should work as is along with the mutex and sleep
API calls required by this method.
Hi Phil:semaphores. The last commit put essentially all the infrastructure in
place to support this further change so this change should be a simple
matter of replacing (for this case) the calls to sem_open and
sem_close with sem_init and sem_destroy, and the rest of the current
one-semaphore code should work as is along with the mutex and sleep
API calls required by this method.
I need some help on another C++ issue which should be simple to figure
out.
I got the first pass at the coding done for (1) (see the diff
below relative to current git master), and it builds without issues,
but it is not working properly at run time. The problem is (according
to gdb) that
m_mutex = m_unamed_semaphore_MemoryMap.getwsem();
assigns a NULL pointer to m_mutex which leads to an immediate segfault
for the subsequent sem_init(m_mutex, 1, 1);
Can you give me the C++ help to figure out why this simple getwsem method is returning
a NULL pointer rather than the address of wsem (an unnamed semaphore) within the shared
memory struct as intended?
Alan
diff --git a/drivers/wxwidgets_comms.cpp b/drivers/wxwidgets_comms.cpp
index 6b5c071..dfb607c 100644
--- a/drivers/wxwidgets_comms.cpp
+++ b/drivers/wxwidgets_comms.cpp
@@ -1,4 +1,5 @@
-// Copyright (C) 2015 Phil Rosenberg
+// Copyright (C) 2015-2017 Phil Rosenberg
+// Copyright (C) 2017 Alan W. Irwin
//
// This file is part of PLplot.
//
@@ -171,6 +172,12 @@ void PLNamedMutex::create( const char *name, bool aquireOnCreate )
{
#ifdef WIN32
m_mutex = CreateMutexA( NULL, aquireOnCreate ? TRUE : FALSE, name );
+#elif defined(PL_HAVE_UNNAMED_POSIX_SEMAPHORES)
+ if ( !isValid() )
+ {
+ m_mutex = m_unamed_semaphore_MemoryMap.getwsem();
+ sem_init(m_mutex, 1, 1);
+ }
#else
m_mutex = NULL;
char mutexName[251];
@@ -232,6 +239,8 @@ void PLNamedMutex::clear()
release();
#ifdef WIN32
CloseHandle( m_mutex );
+#elif defined(PL_HAVE_UNNAMED_POSIX_SEMAPHORES)
+ sem_destroy( m_mutex );
#else
sem_close( m_mutex );
#endif
diff --git a/drivers/wxwidgets_comms.h b/drivers/wxwidgets_comms.h
index a6798ee..90a9be8 100644
--- a/drivers/wxwidgets_comms.h
+++ b/drivers/wxwidgets_comms.h
@@ -100,6 +100,7 @@ public:
bool isValid() { return m_buffer != NULL; }
#ifdef PL_HAVE_UNNAMED_POSIX_SEMAPHORES
char *getBuffer() { return ( (shmbuf *) m_buffer )->buf; }
+ sem_t *getwsem() { return & ( ( (shmbuf *) m_buffer )->wsem); }
size_t getSize() { return PL_SHARED_ARRAY_SIZE; }
#else
char *getBuffer() { return (char *) m_buffer; }
@@ -134,6 +135,9 @@ private:
bool m_haveLock;
#ifdef WIN32
HANDLE m_mutex;
+#elif defined(PL_HAVE_UNNAMED_POSIX_SEMAPHORES)
+ PLMemoryMap m_unamed_semaphore_MemoryMap;
+ sem_t * m_mutex;
#else
sem_t * m_mutex;
#endif
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________
Linux-powered Science
__________________________