o
    ϋim                     @   s   zd dl ZW n ey   d dlZY nw d dlZd dlZd dlZddlmZ G dd dejZ	G dd dejZ
G dd	 d	ejZdS )
    N   RWLockc                   @      e Zd Zdd Zdd ZdS )Writerc                 C   s<   t j|  || _|| _|| _|| _|| _d| _	 d| _	dS )a  
        @param buffer_: common buffer_ shared by the readers and writers
        @type buffer_: list
        @type rw_lock: L{RWLock}
        @param init_sleep_time: sleep time before doing any action
        @type init_sleep_time: C{float}
        @param sleep_time: sleep time while in critical section
        @type sleep_time: C{float}
        @param to_write: data that will be appended to the buffer
        N)
	threadingThread__init___Writer__buffer_Writer__rw_lock_Writer__init_sleep_time_Writer__sleep_time_Writer__to_write
entry_time	exit_time)selfbuffer_rw_lockinit_sleep_time
sleep_timeto_write r   V/home/air/goalskill_sales/back/venv/lib/python3.10/site-packages/ecdsa/test_rw_lock.pyr	      s   zWriter.__init__c                 C   sR   t | j | j  t   | _t | j | j| j	 t   | _
| j  d S N)timesleepr   r   writer_acquirer   r   r
   appendr   r   writer_releaser   r   r   r   run(      


z
Writer.runN__name__
__module____qualname__r	   r    r   r   r   r   r      s    r   c                   @   r   )Readerc                 C   s>   t j|  || _|| _|| _|| _d| _	 d| _	 d| _	dS )a\  
        @param buffer_: common buffer shared by the readers and writers
        @type buffer_: list
        @type rw_lock: L{RWLock}
        @param init_sleep_time: sleep time before doing any action
        @type init_sleep_time: C{float}
        @param sleep_time: sleep time while in critical section
        @type sleep_time: C{float}
        N)
r   r   r	   _Reader__buffer_Reader__rw_lock_Reader__init_sleep_time_Reader__sleep_timebuffer_readr   r   )r   r   r   r   r   r   r   r   r	   3   s   
zReader.__init__c                 C   sR   t | j | j  t   | _t | j t| j	| _
t   | _| j  d S r   )r   r   r)   r(   reader_acquirer   r*   copydeepcopyr'   r+   r   reader_releaser   r   r   r   r    I   r!   z
Reader.runNr"   r   r   r   r   r&   2   s    r&   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zed	d
 Zedd Z	dS )RWLockTestCasec                 C   s   |   \}}}|t||dd |t||ddd |t||dd |t||dd | | | g |d j | dg|d j | dg|d j | |d j|d j	k | |d j	|d j	k | |d j|d jk  d S )	Nr   皙?皙?r   333333?      ?      )
_RWLockTestCase__init_variablesr   r&   r   '_RWLockTestCase__start_and_join_threadsassertEqualr+   
assertTruer   r   r   r   r   threadsr   r   r    test_readers_nonexclusive_accessT   s   
z/RWLockTestCase.test_readers_nonexclusive_accessc                 C   s   |   \}}}|t||ddd |t||ddd |t||dd | | | ddg|d j | |d j|d j	k | |d j|d jk d S )Nr   r2   r   皙?r5   r1   
r7   r   r   r&   r8   r9   r+   r:   r   r   r;   r   r   r   test_writers_exclusive_accessj   s   
z,RWLockTestCase.test_writers_exclusive_accessc                 C   s,  |   \}}}|t||ddd |t||dd |t||ddd |t||dd |t||dd | | | dg|d j | ddg|d j | ddg|d	 j | |d j|d j	k  | |d j|d j	k | |d j|d j	k | |d j|d	 j	k d S )
Nr   r   r>   r2   r1   r5   r3   r6      r?   r;   r   r   r   test_writer_priorityy   s   
z#RWLockTestCase.test_writer_priorityc                 C   s  |   \}}}|t||ddd |t||dd |t||ddd |t||dd |t||dd |t||d	dd
 | | | dg|d j | g d|d
 j | g d|d j | |d j|d j	k  | |d j|d j	k | |d j|d j	k | |d j|d
 j	k | |d j|d j	k | |d j|d
 j	k | |d j|d j	k d S )Nr   r   r>   g333333?r1   r5   r3   r2   r4   r6   )r   r5   r6   rA      r?   r;   r   r   r   test_many_writers_priority   s$   
z)RWLockTestCase.test_many_writers_priorityc                  C   s   g } t  }g }| ||fS r   r   )r   r   r<   r   r   r   __init_variables   s   
zRWLockTestCase.__init_variablesc                 C   s(   | D ]}|   q| D ]}|  qd S r   )startjoin)r<   tr   r   r   __start_and_join_threads   s
   

z'RWLockTestCase.__start_and_join_threadsN)
r#   r$   r%   r=   r@   rB   rD   staticmethodr7   r8   r   r   r   r   r0   S   s    
r0   )	unittest2unittestImportErrorr   r   r-   _rwlockr   r   r   r&   TestCaser0   r   r   r   r   <module>   s   #!