-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiltering_buffer.py
More file actions
36 lines (26 loc) · 1.06 KB
/
filtering_buffer.py
File metadata and controls
36 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# class that will create x number of buffers and will have gettter and setter for each buffer with locks so a single buffer can be accessed by a single thread at a time\
from filtering_manager import filtering_manager
import threading
import time
class filtering_buffer:
def __init__(self, buffers_num, fm: filtering_manager):
self.buffers = [None] * buffers_num
self.locks = [threading.Lock() for i in range(buffers_num)]
self.fm = fm
def get_buffer(self, index):
self.locks[index].acquire()
buffer = self.buffers[index]
self.locks[index].release()
return buffer
def set_buffer(self, index, buffer):
self.locks[index].acquire()
self.buffers[index] = buffer
self.locks[index].release()
def startSyncThread(self):
thread = threading.Thread(target=self.sync)
thread.start()
def sync(self):
while True:
for i in range(len(self.buffers)):
self.set_buffer(i, self.fm.read_state())
time.sleep(10)