
    tZh!                     8    d dl Z dZ G d d      Z G d d      Zy)    NzMateusz Kobosc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)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                         | _        y)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    i/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/ecdsa/_rwlock.py__init__zRWLock.__init__$   sE    
 *^*n%NN,%NN,(~~/    c                    | j                   j                          | j                  j                          | j                  j                  | j                         | j                  j                          | j                   j                          y N)r   acquirer   r   r   releaser   s    r   reader_acquirezRWLock.reader_acquire/   sd    $$&!!#""4#4#45!!#$$&r   c                 N    | j                   j                  | j                         y r   )r   r   r   r   s    r   reader_releasezRWLock.reader_release6   s    ""4#4#45r   c                     | j                   j                  | j                         | j                  j                          y r   )r   r   r   r   r   s    r   writer_acquirezRWLock.writer_acquire9   s.    ##D$5$56!!#r   c                     | j                   j                          | j                  j                  | j                         y r   )r   r   r   r   r   s    r   writer_releasezRWLock.writer_release=   s.    !!###D$5$56r   N)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      s     0	0'6$7r   r   c                   "    e Zd ZdZd Zd Zd Zy)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                         | _        y )Nr   )_LightSwitch__counterr	   r
   _LightSwitch__mutexr   s    r   r   z_LightSwitch.__init__F   s     ~~'r   c                     | j                   j                          | xj                  dz  c_        | j                  dk(  r|j                          | j                   j                          y )N   r&   r   r%   r   r   locks     r   r   z_LightSwitch.acquireJ   E    !>>QLLNr   c                     | j                   j                          | xj                  dz  c_        | j                  dk(  r|j                          | j                   j                          y )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   s    N(r   r   )r	   
__author__r   r   r"   r   r   <module>r/      s&   
  
47 47n r   