[sword-svn] r3598 - trunk/bindings/corba/omniorbcpp

scribe at crosswire.org scribe at crosswire.org
Sun Nov 4 16:55:38 MST 2018


Author: scribe
Date: 2018-11-04 16:55:38 -0700 (Sun, 04 Nov 2018)
New Revision: 3598

Modified:
   trunk/bindings/corba/omniorbcpp/Makefile
   trunk/bindings/corba/omniorbcpp/server.cpp
   trunk/bindings/corba/omniorbcpp/testclient.cpp
Log:
updated omniorb impl to handle terminate correctly


Modified: trunk/bindings/corba/omniorbcpp/Makefile
===================================================================
--- trunk/bindings/corba/omniorbcpp/Makefile	2018-11-04 23:50:24 UTC (rev 3597)
+++ trunk/bindings/corba/omniorbcpp/Makefile	2018-11-04 23:55:38 UTC (rev 3598)
@@ -19,7 +19,7 @@
 #CXXFLAGS += -g -O0
 #CFLAGS += -g -O0
 #LDFLAGS += -g -O0
-CXXFLAGS += -O3
+CXXFLAGS += -O3 -std=c++0x
 CFLAGS += -O3
 #-----------------------------------------------------------------------------
 

Modified: trunk/bindings/corba/omniorbcpp/server.cpp
===================================================================
--- trunk/bindings/corba/omniorbcpp/server.cpp	2018-11-04 23:50:24 UTC (rev 3597)
+++ trunk/bindings/corba/omniorbcpp/server.cpp	2018-11-04 23:55:38 UTC (rev 3598)
@@ -22,6 +22,7 @@
 
 
 #include <csignal>
+#include <thread>
 #include "swordorb-impl.hpp"
 #include <iostream>
 #include <swmgr.h>
@@ -43,10 +44,47 @@
 	}
 } cleanStatics;
 
+#include <mutex>
+#include <condition_variable>
 
-void term_handler(int signal) {
+class Semaphore {
+private:
+    std::mutex mtx;
+    std::condition_variable cv;
+    int count;
+
+public:
+    Semaphore (int count_ = 0) : count(count_) {}
+
+    inline void notify() {
+        std::unique_lock<std::mutex> lock(mtx);
+        count++;
+        cv.notify_one();
+    }
+
+    inline void wait() {
+        std::unique_lock<std::mutex> lock(mtx);
+
+        while(count == 0){
+            cv.wait(lock);
+        }
+        count--;
+    }
+};
+
+Semaphore waitingForTermSemaphore;
+
+void waitingForTermFunction() {
+	waitingForTermSemaphore.wait();
+std::cerr << "Semaphore passed shutting down orb...\n";
+	if (orb) orb->shutdown(true);
+std::cerr << "ORB shutdown returned...\n";
+}
+
+void termHandler(int signal) {
 	std::cerr << "SIGTERM received, exiting nicely...\n";
-	if (orb) orb->shutdown(!0);
+	std::cerr << "notifying semaphore...\n";
+	waitingForTermSemaphore.notify();
 }
 
 
@@ -104,13 +142,17 @@
     PortableServer::POAManager_var pman = poa->the_POAManager();
     pman->activate();
 
-	std::signal(SIGTERM, term_handler);
+	std::thread waitingForTermThread(waitingForTermFunction);
+	std::signal(SIGTERM, termHandler);
 
 
     orb->run();
 	std::cerr << "ORB has stopped running.\n";
     orb->destroy();
 	std::cerr << "ORB is destroyed.\n";
+	std::cerr << "joining terminate thread.\n";
+	waitingForTermThread.join();
+	std::cerr << "exiting...\n";
   }
   catch(CORBA::TRANSIENT&) {
     std::cerr << "Caught system exception TRANSIENT -- unable to contact the "

Modified: trunk/bindings/corba/omniorbcpp/testclient.cpp
===================================================================
--- trunk/bindings/corba/omniorbcpp/testclient.cpp	2018-11-04 23:50:24 UTC (rev 3597)
+++ trunk/bindings/corba/omniorbcpp/testclient.cpp	2018-11-04 23:55:38 UTC (rev 3598)
@@ -110,6 +110,10 @@
 		std::cout << "\nFiltered text: " << mgr->filterText("Greek Accents", "ὁ θεὸς") << "\n";
 */
 
+		std::cout << "Terminating ORB...\n";
+
+		mgr->terminate();
+
 		
 	} catch(const CORBA::Exception& ex) {
 		std::cout << "exception: " << ex._name() << std::endl;




More information about the sword-cvs mailing list