summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2018-02-26 15:42:15 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2018-02-26 15:42:15 +0100
commitd5db0c5ba71a0d6232867d2bc24d2cfcb2817a47 (patch)
tree3cbca3881b3485573ea6d577760fbd57e9e4b377
parentdd6c37c13dbafadd0d00c4c55e8e56e24829fa61 (diff)
downloadvdr-d5db0c5ba71a0d6232867d2bc24d2cfcb2817a47.tar.gz
vdr-d5db0c5ba71a0d6232867d2bc24d2cfcb2817a47.tar.bz2
Improved locking
-rw-r--r--svdrp.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/svdrp.c b/svdrp.c
index 6f8e9d2a..6e3a58a2 100644
--- a/svdrp.c
+++ b/svdrp.c
@@ -10,7 +10,7 @@
* and interact with the Video Disk Recorder - or write a full featured
* graphical interface that sits on top of an SVDRP connection.
*
- * $Id: svdrp.c 4.29 2018/02/25 13:44:54 kls Exp $
+ * $Id: svdrp.c 4.30 2018/02/26 15:42:15 kls Exp $
*/
#include "svdrp.h"
@@ -571,6 +571,8 @@ protected:
public:
cSVDRPClientHandler(int TcpPort, int UdpPort);
virtual ~cSVDRPClientHandler();
+ void Lock(void) { mutex.Lock(); }
+ void Unlock(void) { mutex.Unlock(); }
void AddClient(cSVDRPServerParams &ServerParams, const char *IpAddress);
bool Execute(const char *ServerName, const char *Command, cStringList *Response = NULL);
bool GetServerNames(cStringList *ServerNames, eSvdrpFetchFlags FetchFlags = sffNone);
@@ -2725,18 +2727,26 @@ void StopSVDRPHandler(void)
bool GetSVDRPServerNames(cStringList *ServerNames, eSvdrpFetchFlags FetchFlag)
{
+ bool Result = false;
cMutexLock MutexLock(&SVDRPHandlerMutex);
- if (SVDRPClientHandler)
- return SVDRPClientHandler->GetServerNames(ServerNames, FetchFlag);
- return false;
+ if (SVDRPClientHandler) {
+ SVDRPClientHandler->Lock();
+ Result = SVDRPClientHandler->GetServerNames(ServerNames, FetchFlag);
+ SVDRPClientHandler->Unlock();
+ }
+ return Result;
}
bool ExecSVDRPCommand(const char *ServerName, const char *Command, cStringList *Response)
{
+ bool Result = false;
cMutexLock MutexLock(&SVDRPHandlerMutex);
- if (SVDRPClientHandler)
- return SVDRPClientHandler->Execute(ServerName, Command, Response);
- return false;
+ if (SVDRPClientHandler) {
+ SVDRPClientHandler->Lock();
+ Result = SVDRPClientHandler->Execute(ServerName, Command, Response);
+ SVDRPClientHandler->Unlock();
+ }
+ return Result;
}
void BroadcastSVDRPCommand(const char *Command)
@@ -2744,9 +2754,11 @@ void BroadcastSVDRPCommand(const char *Command)
cMutexLock MutexLock(&SVDRPHandlerMutex);
cStringList ServerNames;
if (SVDRPClientHandler) {
+ SVDRPClientHandler->Lock();
if (SVDRPClientHandler->GetServerNames(&ServerNames)) {
for (int i = 0; i < ServerNames.Size(); i++)
ExecSVDRPCommand(ServerNames[i], Command);
}
+ SVDRPClientHandler->Unlock();
}
}