mirror of
https://github.com/panda3d/panda3d.git
synced 2026-02-20 14:19:25 -06:00
pipeline: give Mutex and ReMutex more Pythonic semantics
This allows using mutices in with-blocks and wraps up the functionality of acquire() and try_acquire() into a single acquire(blocking=True). Furthermore, the GIL is no longer released in cases of no contention.
This commit is contained in:
@@ -26,13 +26,12 @@ def test_cvar_notify_locked():
|
||||
m = Mutex()
|
||||
cv = ConditionVarFull(m)
|
||||
|
||||
m.acquire()
|
||||
cv.notify()
|
||||
m.release()
|
||||
with m:
|
||||
cv.notify()
|
||||
|
||||
with m:
|
||||
cv.notify_all()
|
||||
|
||||
m.acquire()
|
||||
cv.notify_all()
|
||||
m.release()
|
||||
del cv
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from panda3d.core import Mutex, ReMutex
|
||||
from panda3d import core
|
||||
from random import random
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
|
||||
def test_mutex_acquire_release():
|
||||
@@ -34,6 +35,19 @@ def test_mutex_try_acquire():
|
||||
m.release()
|
||||
|
||||
|
||||
def test_mutex_with():
|
||||
m = Mutex()
|
||||
|
||||
rc = sys.getrefcount(m)
|
||||
with m:
|
||||
assert m.debug_is_locked()
|
||||
|
||||
with m:
|
||||
assert m.debug_is_locked()
|
||||
|
||||
assert rc == sys.getrefcount(m)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not core.Thread.is_threading_supported(),
|
||||
reason="Threading support disabled")
|
||||
def test_mutex_contention():
|
||||
@@ -124,3 +138,15 @@ def test_remutex_try_acquire():
|
||||
m.release()
|
||||
m.release()
|
||||
|
||||
|
||||
def test_remutex_with():
|
||||
m = ReMutex()
|
||||
|
||||
rc = sys.getrefcount(m)
|
||||
with m:
|
||||
assert m.debug_is_locked()
|
||||
with m:
|
||||
assert m.debug_is_locked()
|
||||
assert m.debug_is_locked()
|
||||
|
||||
assert rc == sys.getrefcount(m)
|
||||
|
||||
Reference in New Issue
Block a user