diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2018-02-26 15:42:15 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2018-02-26 15:42:15 +0100 |
commit | d5db0c5ba71a0d6232867d2bc24d2cfcb2817a47 (patch) | |
tree | 3cbca3881b3485573ea6d577760fbd57e9e4b377 /svdrp.c | |
parent | dd6c37c13dbafadd0d00c4c55e8e56e24829fa61 (diff) | |
download | vdr-d5db0c5ba71a0d6232867d2bc24d2cfcb2817a47.tar.gz vdr-d5db0c5ba71a0d6232867d2bc24d2cfcb2817a47.tar.bz2 |
Improved locking
Diffstat (limited to 'svdrp.c')
-rw-r--r-- | svdrp.c | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -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(); } } |