Skip to content

Commit

Permalink
Put source to sleep when there is no data to send
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Forencich <[email protected]>
  • Loading branch information
alexforencich committed Jan 20, 2023
1 parent cd1a8b4 commit ede6270
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cocotbext/axi/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ async def send(self, frame):
frame = AxiStreamFrame(frame)
await self.queue.put(frame)
self.idle_event.clear()
self.active_event.set()
self.queue_occupancy_bytes += len(frame)
self.queue_occupancy_frames += 1

Expand All @@ -434,6 +435,7 @@ def send_nowait(self, frame):
frame = AxiStreamFrame(frame)
self.queue.put_nowait(frame)
self.idle_event.clear()
self.active_event.set()
self.queue_occupancy_bytes += len(frame)
self.queue_occupancy_frames += 1

Expand Down Expand Up @@ -561,6 +563,9 @@ async def _run(self):
self.active = bool(frame)
if not frame and self.queue.empty():
self.idle_event.set()
self.active_event.clear()

await self.active_event.wait()


class AxiStreamMonitor(AxiStreamBase):
Expand Down
5 changes: 5 additions & 0 deletions cocotbext/axi/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ async def send(self, obj):
await self.dequeue_event.wait()
await self.queue.put(obj)
self.idle_event.clear()
self.active_event.set()

def send_nowait(self, obj):
if self.full():
raise QueueFull()
self.queue.put_nowait(obj)
self.idle_event.clear()
self.active_event.set()

def full(self):
if self.queue_occupancy_limit > 0 and self.count() >= self.queue_occupancy_limit:
Expand Down Expand Up @@ -255,6 +257,9 @@ async def _run(self):
self.active = not self.queue.empty()
if self.queue.empty():
self.idle_event.set()
self.active_event.clear()

await self.active_event.wait()


class StreamMonitor(StreamBase):
Expand Down

0 comments on commit ede6270

Please sign in to comment.