Skip to content

Commit

Permalink
Make requests share a common lock
Browse files Browse the repository at this point in the history
This is necessary because all requests access common DMA allocator
data structures.

Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman authored and will-v-pi committed Oct 9, 2023
1 parent 3d04990 commit 9e965c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def __init__(self, camera_num=0, verbose_console=None, tuning=None):
self.notifymeread = os.fdopen(self.notifyme_r, 'rb')
self._cm.add(camera_num, self)
self.camera_idx = camera_num
self.request_lock = threading.Lock() # global lock used by requests
self._requestslock = threading.Lock()
self._requests = []
if verbose_console is None:
Expand Down
11 changes: 6 additions & 5 deletions picamera2/request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import io
import logging
import threading
import time
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -102,15 +101,17 @@ class CompletedRequest:
def __init__(self, request, picam2):
self.request = request
self.ref_count = 1
self.lock = threading.Lock()
self.lock = picam2.request_lock
self.picam2 = picam2
self.stop_count = picam2.stop_count
self.configure_count = picam2.configure_count
self.config = self.picam2.camera_config.copy()
self.stream_map = self.picam2.stream_map.copy()
self.syncs = [picam2.allocator.sync(self.picam2.allocator, buffer, False) for buffer in self.request.buffers.values()]
self.picam2.allocator.acquire(self.request.buffers)
[sync.__enter__() for sync in self.syncs]
with self.lock:
self.syncs = [picam2.allocator.sync(self.picam2.allocator, buffer, False)
for buffer in self.request.buffers.values()]
self.picam2.allocator.acquire(self.request.buffers)
[sync.__enter__() for sync in self.syncs]

def acquire(self):
"""Acquire a reference to this completed request, which stops it being recycled back to the camera system."""
Expand Down

0 comments on commit 9e965c5

Please sign in to comment.