Ë
    "ïàjt(  ã                   ó<   — d Z ddlmZmZmZ ddlmZ  G d„ d«      Zy)zî
ReadWriteLock

Taken from http://code.activestate.com/recipes/502283/

locks.py - Read-Write lock thread lock implementation

See the class documentation for more info.

Copyright (C) 2007, Heiko Wundram.
Released under the BSD-license.
é    )Ú	ConditionÚLockÚcurrent_thread)Útimec                   ó4   — e Zd ZdZd„ Zddœd„Zddœd„Zd„ Zy)ÚReadWriteLocka[  Read-Write lock class. A read-write lock differs from a standard
    threading.RLock() by allowing multiple threads to simultaneously hold a
    read lock, while allowing only a single thread to hold a write lock at the
    same point of time.

    When a read lock is requested while a write lock is held, the reader
    is blocked; when a write lock is requested while another write lock is
    held or there are read locks, the writer is blocked.

    Writers are always preferred by this implementation: if there are blocked
    threads waiting for a write lock, current readers may request more read
    locks (which they eventually should free, as they starve the waiting
    writers otherwise), but a new thread requesting a read lock will not
    be granted one, and block. This might mean starvation for readers if
    two writer threads interweave their calls to acquire_write() without
    leaving a window only for readers.

    In case a current reader requests a write lock, this can and will be
    satisfied without giving up the read locks first, but, only one thread
    may perform this kind of lock upgrade, as a deadlock would otherwise
    occur. After the write lock has been granted, the thread will hold a
    full write lock, and not be downgraded after the upgrading call to
    acquire_write() has been match by a corresponding release().
    c                 ól   — t        t        «       «      | _        d| _        d| _        g | _        i | _        y)z Initialize this read-write lock.Nr   )r   r   Ú_ReadWriteLock__conditionÚ_ReadWriteLock__writerÚ"_ReadWriteLock__upgradewritercountÚ_ReadWriteLock__pendingwritersÚ_ReadWriteLock__readers)Úselfs    ú>/srv/dav/.venv/lib/python3.12/site-packages/wsgidav/rw_lock.pyÚ__init__zReadWriteLock.__init__2   s5   € ô
 %¤T£VÓ,ˆÔð ˆŒØ$%ˆÔ!Ø "ˆÔð ˆ�ó    N)Útimeoutc                ó0  — |�t        «       |z   }t        «       }| j                  j                  «        	 | j                  |u r1| xj
                  dz  c_        	 | j                  j                  «        y	 | j                  €¡| j                  s| j                  rA|| j                  v r{| j                  |xx   dz  cc<   	 | j                  j                  «        y| j                  j                  |d«      dz   | j                  |<   	 | j                  j                  «        y|�9t        «       z
  }|dk  rt        d«      ‚| j                  j                  |«       n| j                  j                  «        �Œ# | j                  j                  «        w xY w)af  Acquire a read lock for the current thread, waiting at most
        timeout seconds or doing a non-blocking check in case timeout is <= 0.

        In case timeout is None, the call to acquire_read blocks until the
        lock request can be serviced.

        In case the timeout expires before the lock could be serviced, a
        RuntimeError is thrown.Né   r   zAcquiring read lock timed out)r   r   r
   Úacquirer   Ú_ReadWriteLock__writercountÚreleaser   r   r   ÚgetÚRuntimeErrorÚwait)r   r   ÚendtimeÚmeÚ	remainings        r   Úacquire_readzReadWriteLock.acquire_readA   sg  € ð ÐÜ“f˜wÑ&ˆGÜÓˆØ×Ñ× Ñ Ô"ð	'Ø�}‰} Ñ"à×"Ò" aÑ'Õ"Øð6 ×Ñ×$Ñ$Õ&ð5 Ø—=‘=Ð(à×0Ò0°D×4IÒ4IØ §¡Ñ/ð
 !ŸN™N¨2Ó.°!Ñ3Ó.Ø"ð  ×Ñ×$Ñ$Õ&ð .2¯^©^×-?Ñ-?ÀÀAÓ-FÈÑ-J˜Ÿ™ rÑ*Øð ×Ñ×$Ñ$Õ&ð Ð&Ø '¬$«&Ñ 0�IØ  A’~ä*Ð+JÓKÐKØ×$Ñ$×)Ñ)¨)Õ4à×$Ñ$×)Ñ)Ô+ñ1 øð4 ×Ñ×$Ñ$Õ&ús   µ#E9 Á4A
E9 Ã,E9 Ä"AE9 Å9Fc                ó–  — |�t        «       |z   }t        «       d}}| j                  j                  «        	 | j                  |u r1| xj
                  dz  c_        	 | j                  j                  «        y|| j                  v r:| j                  rt        d«      ‚d}| j                  j                  |«      | _        n| j                  j                  |«       	 | j                  s§| j                  €›| j                  r@|r�|| _        | j                  dz   | _        d| _        	 | j                  j                  «        y| j                  d   |u r>|| _        d| _        | j                  dd | _        	 | j                  j                  «        y|��t        «       z
  }|dk  rS|r+| j                  | j                  |<   d| _        t        d«      ‚| j                  j                  |«       t        d«      ‚| j                  j                  |«       n| j                  j                  «        �ŒR# | j                  j                  «        w xY w)aê  Acquire a write lock for the current thread, waiting at most
        timeout seconds or doing a non-blocking check in case timeout is <= 0.

        In case the write lock cannot be serviced due to the deadlock
        condition mentioned above, a ValueError is raised.

        In case timeout is None, the call to acquire_write blocks until the
        lock request can be serviced.

        In case the timeout expires before the lock could be serviced, a
        RuntimeError is thrown.NFr   z(Inevitable dead lock, denying write lockTr   zAcquiring write lock timed out)r   r   r
   r   r   r   r   r   r   Ú
ValueErrorÚpopr   ÚappendÚremover   r   )r   r   r   r   Úupgradewriterr   s         r   Úacquire_writezReadWriteLock.acquire_writep   s%  € ð ÐÜ“f˜wÑ&ˆGÜ*Ó,¨eˆMˆØ×Ñ× Ñ Ô"ðB	'Ø�}‰} Ñ"à×"Ò" aÑ'Õ"Øð| ×Ñ×$Ñ$Õ&ð{ �t—~‘~Ñ%ð ×,Ò,ô
 %Ð%OÓPÐPØ $�Ø,0¯N©N×,>Ñ,>¸rÓ,B�Õ)ð ×%Ñ%×,Ñ,¨RÔ0ØØ—~’~¨$¯-©-Ð*?à×0Ò0Ù(ð -/˜DœMØ15×1JÑ1JÈQÑ1N˜DÔ.Ø89˜DÔ5Ø"ðH ×Ñ×$Ñ$Õ&ð? ×.Ñ.¨qÑ1°RÑ7ð
 )+˜œØ-.˜Ô*Ø04×0EÑ0EÀaÀbÐ0I˜Ô-Øð. ×Ñ×$Ñ$Õ&ð- Ð&Ø '¬$«&Ñ 0�IØ  A’~á(ð 26×1JÑ1J˜DŸN™N¨2Ñ.Ø89˜DÔ5ô
 +Ð+KÓLÐLð !×1Ñ1×8Ñ8¸Ô<Ü*Ð+KÓLÐLØ×$Ñ$×)Ñ)¨)Õ4à×$Ñ$×)Ñ)Ô+ñY øð\ ×Ñ×$Ñ$Õ&ús   ·#H, Á6B,H, Ä>3H, ÆBH, È,Ic                 óH  — t        «       }| j                  j                  «        	 | j                  |u rC| xj                  dz  c_        | j                  s•d| _        | j                  j                  «        ns|| j                  v rZ| j                  |xx   dz  cc<   | j                  |   s?| j                  |= | j                  s&| j                  j                  «        nt        d«      ‚| j                  j                  «        y# | j                  j                  «        w xY w)zkRelease the currently held lock.

        In case the current thread holds no lock, a ValueError is thrown.r   NzTrying to release unheld lock)	r   r
   r   r   r   Ú
notify_allr   r!   r   )r   r   s     r   r   zReadWriteLock.releaseÅ   sè   € ô
 ÓˆØ×Ñ× Ñ Ô"ð	'Ø�}‰} Ñ"à×"Ò" aÑ'Õ"Ø×)Ò)ð %)�D”MØ×$Ñ$×/Ñ/Õ1Ø�t—~‘~Ñ%à—‘˜rÓ" aÑ'Ó"Ø—~‘~ bÒ)àŸ™ rÐ*ØŸ>š>ð ×(Ñ(×3Ñ3Õ5ä Ð!@ÓAÐAà×Ñ×$Ñ$Õ&øˆD×Ñ×$Ñ$Õ&ús   ¦CD ÄD!)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r&   r   © r   r   r   r      s(   „ ñò2ð '+ô -'ð^ (,ô S'ój'r   r   N)r,   Ú	threadingr   r   r   r   r   r-   r   r   ú<module>r/      s!   ðñ÷  6Ñ 5Ý ÷J'ò J'r   