o
    ¯bÿ  ã                   @   sÀ   d Z ddlmZ G dd„ dƒZdd„ Zde_dd	„ Zd
d„ Zdd„ Zdd„ Z	ddd„Z
eƒ Zdd„ Zdd„ Zdd„ ZdadadadazddlZW n eyS   dZY nw eZe
dƒ g d¢ZdS )zT
A module to provide some very basic threading primitives, such as
synchronization.
é    ©Úwrapsc                   @   s   e Zd ZdZdd„ ZdS )Ú	DummyLockzF
    Hack to allow locks to be unpickled on an unthreaded system.
    c                 C   ó   t dfS ©N© ©Úunpickle_lock©Úselfr   r   ú;/usr/lib/python3/dist-packages/twisted/python/threadable.pyÚ
__reduce__   ó   zDummyLock.__reduce__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   c                   C   s   t d urtƒ S tƒ S ©N)ÚthreadingmoduleÚXLockr   r   r   r   r   r	      s   r	   Tc                 C   s>   d| j vrt ¡  d| j vrtƒ | j d< t ¡  | j ¡  d S )NÚ_threadable_lock)Ú__dict__Ú_synchLockCreatorÚacquirer   Úreleaser   r
   r   r   r   Ú	_synchPre!   s   

r   c                 C   s   | j  ¡  d S r   )r   r   r
   r   r   r   Ú
_synchPost*   s   r   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )Nc                    s4   t | ƒ zˆ | g|¢R i |¤ŽW t| ƒ S t| ƒ w r   )r   r   )r   ÚargsÚkwargs©Úfunctionr   r   Úsync/   s   z_sync.<locals>.syncr   )Úklassr    r!   r   r   r   Ú_sync.   s   r#   c                  G   sB   t dur| D ]}|jD ]}t||j| ƒ}t|||ƒ qqdS dS )a&  
    Make all methods listed in each class' synchronized attribute synchronized.

    The synchronized attribute should be a list of strings, consisting of the
    names of methods that must be synchronized. If we are running in threaded
    mode these methods will be wrapped with a lock.
    N)r   Úsynchronizedr#   r   Úsetattr)Úklassesr"   Ú
methodNamer!   r   r   r   Úsynchronize:   s   
þþr(   é   c                 C   sN   | rt stdurda G dd„ dtjƒatƒ adS tdƒ‚dS t r$tdƒ‚	 dS )zbInitialize threading.

    Don't bother calling this.  If it needs to happen, it will happen.
    NTc                   @   s   e Zd Zdd„ ZdS )r   c                 S   r   r   r   r
   r   r   r   r   V   r   zXLock.__reduce__N)r   r   r   r   r   r   r   r   r   U   s    r   z:Cannot initialize threading, platform lacks thread supportzCannot uninitialize threads)Úthreadedr   Ú_RLockr   r   ÚRuntimeError)Úwith_threadsr   r   r   ÚinitI   s   
ÿör.   c                   C   s   t d u rtS t  ¡ jS r   )r   Ú_dummyIDÚcurrent_threadÚidentr   r   r   r   ÚgetThreadIDh   s   
r2   c                   C   s
   t tƒ kS )zCAre we in the thread responsible for I/O requests (the event loop)?)ÚioThreadr2   r   r   r   r   ÚisInIOThreadn   s   
r4   c                   C   s
   t ƒ adS )z8Mark the current thread as responsible for I/O requests.N)r2   r3   r   r   r   r   ÚregisterAsIOThreads   s   
r5   NF)r4   r5   r2   r   )r)   )r   Ú	functoolsr   r   r	   Ú__safe_for_unpickling__r   r   r#   r(   r.   Úobjectr/   r2   r4   r5   r3   r*   r   r   Ú	threadingÚ_threadingmoduleÚImportErrorr   Ú__all__r   r   r   r   Ú<module>   s4   		
ÿ