Пример #1
0
    def test_read_vs_downgrade_write(self) -> None:
        """
		# Given: Instance of RWLockWriteD.

		# When: A reader lock is acquired OR A writer lock is downgraded.

		# Then: The internal state should be the same.
		"""
        # ## Arrange
        c_rwlock_1 = rwlock.RWLockWriteD()
        c_rwlock_2 = rwlock.RWLockWriteD()

        def assert_internal_state():
            self.assertEqual(int(c_rwlock_1.v_read_count),
                             int(c_rwlock_2.v_read_count))
            self.assertEqual(int(c_rwlock_1.v_write_count),
                             int(c_rwlock_2.v_write_count))
            self.assertEqual(bool(c_rwlock_1.c_lock_read_count.locked()),
                             bool(c_rwlock_2.c_lock_read_count.locked()))
            self.assertEqual(bool(c_rwlock_1.c_lock_write_count.locked()),
                             bool(c_rwlock_2.c_lock_write_count.locked()))

            self.assertEqual(bool(c_rwlock_1.c_lock_read_entry.locked()),
                             bool(c_rwlock_2.c_lock_read_entry.locked()))
            self.assertEqual(bool(c_rwlock_1.c_lock_read_try.locked()),
                             bool(c_rwlock_2.c_lock_read_try.locked()))
            self.assertEqual(bool(c_rwlock_1.c_resource.locked()),
                             bool(c_rwlock_2.c_resource.locked()))

        # ## Assume
        assert_internal_state()

        # ## Act
        a_read_lock = c_rwlock_1.gen_rlock()
        a_read_lock.acquire()
        a_downgrade_lock: Union[rwlock.LockableD,
                                rwlock.Lockable] = c_rwlock_2.gen_wlock()
        a_downgrade_lock.acquire()
        assert isinstance(a_downgrade_lock, rwlock.LockableD)
        a_downgrade_lock = a_downgrade_lock.downgrade()
        # ## Assert
        assert_internal_state()

        a_read_lock.release()
        a_downgrade_lock.release()
        assert_internal_state()
Пример #2
0
    def __init__(self, initial_message=0, name="Unnamed Bus"):
        self.message = initial_message
        self.name = name

        # Set up the class so that functions can get a lock while working
        self.lock = rwlock.RWLockWriteD()
Пример #3
0
 def __init__(self, msg_type=None):
     self.type = msg_type
     self.message = None
     self.time = None
     self.lock = rwlock.RWLockWriteD()
Пример #4
0
 def __init__(self):
     self.message = None
     self.lock = rwlock.RWLockWriteD()