File: //usr/local/CyberCP/lib64/python3.10/site-packages/ecdsa/__pycache__/_rwlock.cpython-310.pyc
o
�h! � @ s, d dl Z dZG dd� d�ZG dd� d�ZdS )� Nz
Mateusz Kobosc @ s8 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� ZdS )
�RWLocka
Read-Write locking primitive
Synchronization object used in a solution of so-called second
readers-writers problem. In this problem, many readers can simultaneously
access a share, and a writer has an exclusive access to this share.
Additionally, the following constraints should be met:
1) no reader should be kept waiting if the share is currently opened for
reading unless a writer is also waiting for the share,
2) no writer should be kept waiting for the share longer than absolutely
necessary.
The implementation is based on [1, secs. 4.2.2, 4.2.6, 4.2.7]
with a modification -- adding an additional lock (C{self.__readers_queue})
-- in accordance with [2].
Sources:
[1] A.B. Downey: "The little book of semaphores", Version 2.1.5, 2008
[2] P.J. Courtois, F. Heymans, D.L. Parnas:
"Concurrent Control with 'Readers' and 'Writers'",
Communications of the ACM, 1971 (via [3])
[3] http://en.wikipedia.org/wiki/Readers-writers_problem
c C s2 t � | _t � | _t�� | _t�� | _t�� | _dS )zz
A lock giving an even higher priority to the writer in certain
cases (see [2] for a discussion).
N)�_LightSwitch�_RWLock__read_switch�_RWLock__write_switch� threading�Lock�_RWLock__no_readers�_RWLock__no_writers�_RWLock__readers_queue��self� r
�@/usr/local/CyberCP/lib/python3.10/site-packages/ecdsa/_rwlock.py�__init__$ s
zRWLock.__init__c C s: | j �� | j�� | j�| j� | j�� | j �� d S �N)r
�acquirer r r �releaser r
r
r �reader_acquire/ s
zRWLock.reader_acquirec C s | j �| j� d S r )r r r r r
r
r �reader_release6 s zRWLock.reader_releasec C s | j �| j� | j�� d S r )r r r r r r
r
r �writer_acquire9 s zRWLock.writer_acquirec C s | j �� | j�| j� d S r )r r r r r r
r
r �writer_release= s
zRWLock.writer_releaseN) �__name__�
__module__�__qualname__�__doc__r r r r r r
r
r
r r s r c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) r z�An auxiliary "light switch"-like object. The first thread turns on the
"switch", the last one turns it off (see [1, sec. 4.2.2] for details).c C s d| _ t�� | _d S )Nr )�_LightSwitch__counterr r �_LightSwitch__mutexr r
r
r r F s z_LightSwitch.__init__c C s8 | j �� | jd7 _| jdkr|�� | j �� d S )N� �r r r r �r �lockr
r
r r J �
z_LightSwitch.acquirec C s8 | j �� | jd8 _| jdkr|�� | j �� d S )Nr r r r r
r
r r Q r! z_LightSwitch.releaseN)r r r r r r r r
r
r
r r B s
r )r �
__author__r r r
r
r
r �<module> s 7