Skip to content

Commit d0ed294

Browse files
committed
Add some more extra thread safety to the network events module
1 parent 2cf6509 commit d0ed294

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Source/Plugins/NetworkEvents/NetworkEvents.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ bool NetworkEvents::closesocket()
212212
#ifdef ZEROMQ
213213
if (threadRunning)
214214
{
215+
lock.enter();
215216
zmq_close (responder);
216217
zmq_ctx_destroy (zmqcontext); // this will cause the thread to exit
217218
zmqcontext = nullptr;
219+
lock.exit();
218220

219221
if (!stopThread(500))
220222
{
@@ -572,7 +574,9 @@ void NetworkEvents::run()
572574

573575
while (threadRunning)
574576
{
577+
lock.enter();
575578
result = zmq_recv (responder, buffer, MAX_MESSAGE_LENGTH - 1, 0); // blocking
579+
lock.exit();
576580

577581
juce::int64 timestamp_software = timer.getHighResolutionTicks();
578582

@@ -664,8 +668,10 @@ void NetworkEvents::loadCustomParametersFromXml()
664668
void NetworkEvents::createZmqContext()
665669
{
666670
#ifdef ZEROMQ
671+
lock.enter();
667672
if (zmqcontext == nullptr)
668673
zmqcontext = zmq_ctx_new(); //<-- this is only available in version 3+
674+
lock.exit();
669675
#endif
670676
}
671677

0 commit comments

Comments
 (0)