From df16c815c2ec61b1181bd9681818d36c0e66e784 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 3 May 2016 16:34:19 +0200 Subject: [PATCH] Semaphore fixes. --- src/controller/controller.cpp | 3 ++- src/controller/controller_api.cpp | 2 +- src/controller/controller_storage.cpp | 2 ++ src/controller/controller_storage.h | 1 + src/input/input_buffer.cpp | 30 +++++++++++++-------------- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 9c9db8ae..a79791ac 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -127,8 +127,9 @@ void statusMonitor(void * np){ changed = true; } configLock.post(); - if (changed){ + if (changed || Controller::configChanged){ Controller::writeConfig(); + Controller::configChanged = false; } } Util::wait(5000);//wait at least 5 seconds diff --git a/src/controller/controller_api.cpp b/src/controller/controller_api.cpp index 0bff7ec7..5869af16 100644 --- a/src/controller/controller_api.cpp +++ b/src/controller/controller_api.cpp @@ -572,7 +572,7 @@ int Controller::handleAPIConnection(Socket::Connection & conn){ Controller::fillActive(Request["stats_streams"], Response["stats_streams"]); } - Controller::writeConfig(); + Controller::configChanged = true; }else{//unauthorized Util::sleep(1000);//sleep a second to prevent bruteforcing diff --git a/src/controller/controller_storage.cpp b/src/controller/controller_storage.cpp index a2331066..e1099fb6 100644 --- a/src/controller/controller_storage.cpp +++ b/src/controller/controller_storage.cpp @@ -16,6 +16,8 @@ namespace Controller { JSON::Value Storage; ///< Global storage of data. tthread::mutex configMutex; tthread::mutex logMutex; + bool configChanged = false; + ///\brief Store and print a log message. ///\param kind The type of message. ///\param message The message to be logged. diff --git a/src/controller/controller_storage.h b/src/controller/controller_storage.h index 98820af0..bd65fff6 100644 --- a/src/controller/controller_storage.h +++ b/src/controller/controller_storage.h @@ -8,6 +8,7 @@ namespace Controller { extern JSON::Value Storage; ///< Global storage of data. extern tthread::mutex logMutex;///< Mutex for log thread. extern tthread::mutex configMutex;///< Mutex for server config access. + extern bool configChanged; ///< Bool that indicates config must be written to SHM. /// Store and print a log message. void Log(std::string kind, std::string message); diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index 4a72471f..c550e7a3 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -951,24 +951,24 @@ namespace Mist { { // @todo check if output is already running ? - if (recordingPid == -1 - && config != NULL - ) - { + if (recordingPid == -1 && config != NULL){ + configLock.post(); + configLock.close(); - INFO_MSG("The stream %s has a value specified for the recording. " - "We're goint to start an output and record into %s", - config->getString("streamname").c_str(), - streamCfg.getMember("record").asString().c_str()); + INFO_MSG("The stream %s has a value specified for the recording. " + "We're going to start an output and record into %s", + config->getString("streamname").c_str(), + streamCfg.getMember("record").asString().c_str()); - recordingPid = Util::startRecording(config->getString("streamname")); - if (recordingPid < 0) { - FAIL_MSG("Failed to start the recording for %s", config->getString("streamname").c_str()); - // @todo shouldn't we do configList.post(), configLock.close() and return false? - // @todo discuss with Jaron. 2015.09.26, remove this comment when discussed. - } - INFO_MSG("We started an output for recording with PID: %d", recordingPid); + recordingPid = Util::startRecording(config->getString("streamname")); + if (recordingPid < 0) { + FAIL_MSG("Failed to start the recording for %s", config->getString("streamname").c_str()); + // @todo shouldn't we do configList.post(), configLock.close() and return false? + // @todo discuss with Jaron. 2015.09.26, remove this comment when discussed. } + INFO_MSG("We started an output for recording with PID: %d", recordingPid); + return true; + } } /* roxlu-end */