
    Tf!                     F    d dl Z dZ G d d          Z G d d          ZdS )    NzMateusz Kobosc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )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                     t                      | _        t                      | _        t          j                    | _        t          j                    | _        t          j                    | _        dS )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selfs    ?/var/www/html/env/lib/python3.11/site-packages/ecdsa/_rwlock.py__init__zRWLock.__init__$   sR    
 *^^*nn%N,,%N,,(~//    c                    | j                                          | j                                         | j                            | j                   | j                                         | j                                          d S N)r   acquirer   r   r   releaser   s    r   reader_acquirezRWLock.reader_acquire/   sv    $$&&&!!###""4#4555!!###$$&&&&&r   c                 D    | j                             | j                   d S r   )r   r   r   r   s    r   reader_releasezRWLock.reader_release6   s"    ""4#455555r   c                 v    | j                             | j                   | j                                         d S r   )r   r   r   r   r   s    r   writer_acquirezRWLock.writer_acquire9   s7    ##D$5666!!#####r   c                 v    | j                                          | j                            | j                   d S r   )r   r   r   r   r   s    r   writer_releasezRWLock.writer_release=   s7    !!#####D$566666r   N)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      si         0	0 	0 	0' ' '6 6 6$ $ $7 7 7 7 7r   r   c                   $    e Zd ZdZd Zd Zd ZdS )r   zAn 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                 D    d| _         t          j                    | _        d S )Nr   )_LightSwitch__counterr	   r
   _LightSwitch__mutexr   s    r   r   z_LightSwitch.__init__F   s     ~''r   c                     | j                                          | xj        dz  c_        | j        dk    r|                                 | j                                          d S )N   r&   r   r%   r   r   locks     r   r   z_LightSwitch.acquireJ   Z    !>QLLNNNr   c                     | j                                          | xj        dz  c_        | j        dk    r|                                 | j                                          d S )Nr(   r   r)   r*   s     r   r   z_LightSwitch.releaseQ   r,   r   N)r   r   r    r!   r   r   r   r"   r   r   r   r   B   sM        N N( ( (      r   r   )r	   
__author__r   r   r"   r   r   <module>r/      su   
     
47 47 47 47 47 47 47 47n         r   