lock on the spectrum thread to avoid double start
This commit is contained in:
parent
820ca16cd9
commit
32105538c5
@ -54,6 +54,7 @@ class SdrSource(ABC):
|
|||||||
self.clients = []
|
self.clients = []
|
||||||
self.spectrumClients = []
|
self.spectrumClients = []
|
||||||
self.spectrumThread = None
|
self.spectrumThread = None
|
||||||
|
self.spectrumLock = threading.Lock()
|
||||||
self.process = None
|
self.process = None
|
||||||
self.modificationLock = threading.Lock()
|
self.modificationLock = threading.Lock()
|
||||||
self.failed = False
|
self.failed = False
|
||||||
@ -263,22 +264,24 @@ class SdrSource(ABC):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
def addSpectrumClient(self, c):
|
def addSpectrumClient(self, c):
|
||||||
self.spectrumClients.append(c)
|
# local import due to circular depencency
|
||||||
if self.spectrumThread is None:
|
from owrx.fft import SpectrumThread
|
||||||
# local import due to circular depencency
|
|
||||||
from owrx.fft import SpectrumThread
|
|
||||||
|
|
||||||
self.spectrumThread = SpectrumThread(self)
|
self.spectrumClients.append(c)
|
||||||
self.spectrumThread.start()
|
with self.spectrumLock:
|
||||||
|
if self.spectrumThread is None:
|
||||||
|
self.spectrumThread = SpectrumThread(self)
|
||||||
|
self.spectrumThread.start()
|
||||||
|
|
||||||
def removeSpectrumClient(self, c):
|
def removeSpectrumClient(self, c):
|
||||||
try:
|
try:
|
||||||
self.spectrumClients.remove(c)
|
self.spectrumClients.remove(c)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if not self.spectrumClients and self.spectrumThread is not None:
|
with self.spectrumLock:
|
||||||
self.spectrumThread.stop()
|
if not self.spectrumClients and self.spectrumThread is not None:
|
||||||
self.spectrumThread = None
|
self.spectrumThread.stop()
|
||||||
|
self.spectrumThread = None
|
||||||
|
|
||||||
def writeSpectrumData(self, data):
|
def writeSpectrumData(self, data):
|
||||||
for c in self.spectrumClients:
|
for c in self.spectrumClients:
|
||||||
|
Loading…
Reference in New Issue
Block a user