[Swift-commit] cog r3984

swift at ci.uchicago.edu swift at ci.uchicago.edu
Thu Jun 26 10:55:03 CDT 2014


------------------------------------------------------------------------
r3984 | timgarmstrong | 2014-06-26 10:50:05 -0500 (Thu, 26 Jun 2014) | 1 line

Start loop before starting client.  Add checks, warning and documentation for correct loop start/stop.
------------------------------------------------------------------------
Index: modules/provider-coaster-c-client/src/CoasterLoop.h
===================================================================
--- modules/provider-coaster-c-client/src/CoasterLoop.h	(revision 3983)
+++ modules/provider-coaster-c-client/src/CoasterLoop.h	(working copy)
@@ -65,6 +65,7 @@
 		 * Add a channel for the loop to monitor.
 		 * Ownership of the channel is shared between caller and the loop.
 		 * Must be removed later by a call to removeChannel().
+		 * Loop must be started before adding channel
 		 */
 		void addChannel(CoasterChannel* channel);
 
Index: modules/provider-coaster-c-client/src/coasters.cpp
===================================================================
--- modules/provider-coaster-c-client/src/coasters.cpp	(revision 3983)
+++ modules/provider-coaster-c-client/src/coasters.cpp	(working copy)
@@ -88,6 +88,7 @@
     *client = new coaster_client(string(service_url, service_url_len));
     COASTER_CHECK_MALLOC(*client);
 
+    (*client)->loop.start();
     (*client)->client.start();
     return COASTER_SUCCESS;
   } catch (const CoasterError& err) {
Index: modules/provider-coaster-c-client/src/CoasterLoop.cpp
===================================================================
--- modules/provider-coaster-c-client/src/CoasterLoop.cpp	(revision 3983)
+++ modules/provider-coaster-c-client/src/CoasterLoop.cpp	(working copy)
@@ -79,6 +79,8 @@
 	if (pthread_join(thread, NULL) != 0) {
 		throw CoasterError(string("Could not join thread: ") + strerror(errno));
 	}
+
+	// TODO: close pipe?
 	LogInfo << "Coaster loop stopped" << endl;
 }
 
@@ -214,15 +216,24 @@
 }
 
 void CoasterLoop::addChannel(CoasterChannel* channel) { Lock::Scoped l(lock);
+	if (!started || done) {
+		LogWarn << "Add channel to non-running loop" << endl;
+	}
 	addList.push_back(channel);
 }
 
 void CoasterLoop::removeChannel(CoasterChannel* channel, bool deleteChan) {
 	Lock::Scoped l(lock);
+	if (!started || done) {
+		LogWarn << "Remove channel to non-running loop" << endl;
+	}
 	removeList.push_back(pair<CoasterChannel*, bool>(channel, deleteChan));
 }
 
 void CoasterLoop::requestWrite(int count) {
+	if (!started) {
+		throw new CoasterError("requestWrite() on non-started loop");
+	}
 	writesPending += count;
 	LogDebug << "request " << count <<  " writes; writesPending: " << writesPending << endl;
 	char tmp[count];



More information about the Swift-commit mailing list