
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3

  \/  ã               @   s,  d dddddgZ ddlZddlZddlZddlZddlZdd	lmZ dd
lmZ ddlm	Z	 yddlm
Z
mZ W n ek
rŒ   edƒ‚Y nX eedƒƒ\ZZej
jZG dd„ deƒZ
G dd„ de
ƒZG dd„ deƒZG dd „ d e
ƒZG dd„ de
ƒZG dd„ deƒZG dd„ deƒZG dd„ dejƒZdS )ÚLockÚRLockÚ	SemaphoreÚBoundedSemaphoreÚ	ConditionÚEventé    Né   )Úcontext)Úprocess)Úutil)ÚSemLockÚ
sem_unlinkz*This platform lacks a functioning sem_openz( implementation, therefore, the requiredz+ synchronization primitives needed will notz function, see issue 3770.é   c               @   s\   e Zd Zejƒ Zdd„ Zedd„ ƒZdd„ Z	dd„ Z
d	d
„ Zdd„ Zdd„ Zedd„ ƒZdS )r   c            C   sö   |d krt jjƒ }|jƒ }tjdkp*|dk}xPtdƒD ]<}y tj|||| j	ƒ |ƒ }| _
W n tk
rn   Y q6X P q6W tdƒ‚tjd|j ƒ | jƒ  tjdkr´dd„ }	tj| |	ƒ | j
jd k	ròdd	lm}
 |
| j
jƒ tj| tj| j
jfd
d� d S )NÚwin32Úforkéd   zcannot find name for semaphorezcreated semlock with handle %sc             S   s   | j jƒ  d S )N)Ú_semlockÚ_after_fork)Úobj© r   ú3/usr/lib64/python3.6/multiprocessing/synchronize.pyr   G   s    z%SemLock.__init__.<locals>._after_forkr   )Úregisterr   )Zexitpriority)r	   Z_default_contextZget_contextZget_start_methodÚsysÚplatformÚrangeÚ_multiprocessingr   Ú
_make_namer   ÚFileExistsErrorr   ÚdebugÚhandleÚ_make_methodsZregister_after_forkÚnameÚsemaphore_trackerr   ZFinalizeÚ_cleanup)ÚselfÚkindÚvalueÚmaxvalueÚctxr!   Z
unlink_nowÚiÚslr   r   r   r   r   Ú__init__2   s.    

zSemLock.__init__c             C   s    ddl m} t| ƒ || ƒ d S )Nr   )Ú
unregister)r"   r,   r   )r!   r,   r   r   r   r#   T   s    zSemLock._cleanupc             C   s   | j j| _| j j| _d S )N)r   ÚacquireÚrelease)r$   r   r   r   r    Z   s    
zSemLock._make_methodsc             C   s
   | j jƒ S )N)r   Ú	__enter__)r$   r   r   r   r/   ^   s    zSemLock.__enter__c             G   s   | j j|Ž S )N)r   Ú__exit__)r$   Úargsr   r   r   r0   a   s    zSemLock.__exit__c             C   sD   t j| ƒ | j}tjdkr,t jƒ j|jƒ}n|j}||j|j	|j
fS )Nr   )r	   Úassert_spawningr   r   r   Zget_spawning_popenZduplicate_for_childr   r%   r'   r!   )r$   r*   Úhr   r   r   Ú__getstate__d   s    

zSemLock.__getstate__c             C   s,   t jj|Ž | _tjd|d  ƒ | jƒ  d S )Nz recreated blocker with handle %rr   )r   r   Z_rebuildr   r   r   r    )r$   Ústater   r   r   Ú__setstate__m   s    zSemLock.__setstate__c               C   s   dt jƒ jd ttjƒf S )Nz%s-%sZ	semprefix)r
   Úcurrent_processZ_configÚnextr   Ú_randr   r   r   r   r   r   s    zSemLock._make_nameN)Ú__name__Ú
__module__Ú__qualname__ÚtempfileZ_RandomNameSequencer9   r+   Ústaticmethodr#   r    r/   r0   r4   r6   r   r   r   r   r   r   .   s   "	r   c               @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
r   r   c            C   s   t j| t|t|d� d S )N)r(   )r   r+   Ú	SEMAPHOREÚSEM_VALUE_MAX)r$   r&   r(   r   r   r   r+   }   s    zSemaphore.__init__c             C   s
   | j jƒ S )N)r   Ú
_get_value)r$   r   r   r   Ú	get_value€   s    zSemaphore.get_valuec             C   s8   y| j jƒ }W n tk
r&   d}Y nX d| jj|f S )NÚunknownz<%s(value=%s)>)r   rA   Ú	ExceptionÚ	__class__r:   )r$   r&   r   r   r   Ú__repr__ƒ   s
    
zSemaphore.__repr__N)r   )r:   r;   r<   r+   rB   rF   r   r   r   r   r   {   s   
c               @   s   e Zd Zddd„Zdd„ ZdS )r   r   c            C   s   t j| t|||d� d S )N)r(   )r   r+   r?   )r$   r&   r(   r   r   r   r+   �   s    zBoundedSemaphore.__init__c             C   s>   y| j jƒ }W n tk
r&   d}Y nX d| jj|| j jf S )NrC   z<%s(value=%s, maxvalue=%s)>)r   rA   rD   rE   r:   r'   )r$   r&   r   r   r   rF   “   s    
zBoundedSemaphore.__repr__N)r   )r:   r;   r<   r+   rF   r   r   r   r   r   Ž   s   
c               @   s   e Zd Zdd„ Zdd„ ZdS )r   c            C   s   t j| tdd|d� d S )Nr   )r(   )r   r+   r?   )r$   r(   r   r   r   r+   ¡   s    zLock.__init__c             C   s�   yf| j jƒ r8tjƒ j}tjƒ jdkrd|dtjƒ j 7 }n,| j jƒ dkrLd}n| j jƒ dkr`d}nd}W n t	k
r~   d}Y nX d	| j
j|f S )
NÚ
MainThreadú|r   ÚNoner   ÚSomeOtherThreadÚSomeOtherProcessrC   z<%s(owner=%s)>)r   Ú_is_miner
   r7   r!   Ú	threadingÚcurrent_threadrA   Ú_countrD   rE   r:   )r$   r!   r   r   r   rF   ¤   s    


zLock.__repr__N)r:   r;   r<   r+   rF   r   r   r   r   r   Ÿ   s   c               @   s   e Zd Zdd„ Zdd„ ZdS )r   c            C   s   t j| tdd|d� d S )Nr   )r(   )r   r+   ÚRECURSIVE_MUTEX)r$   r(   r   r   r   r+   º   s    zRLock.__init__c             C   s¬   y|| j jƒ rBtjƒ j}tjƒ jdkr6|dtjƒ j 7 }| j jƒ }n8| j jƒ dkrZd\}}n | j jƒ dkrrd\}}nd\}}W n t	k
r˜   d\}}Y nX d
| j
j||f S )NrG   rH   r   rI   r   rJ   ÚnonzerorK   rC   z<%s(%s, %s)>)rI   r   )rJ   rQ   )rK   rQ   )rC   rC   )r   rL   r
   r7   r!   rM   rN   rO   rA   rD   rE   r:   )r$   r!   Úcountr   r   r   rF   ½   s    



zRLock.__repr__N)r:   r;   r<   r+   rF   r   r   r   r   r   ¸   s   c               @   sj   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	ddd„Z
dd„ Zdd„ Zddd„ZdS )r   Nc            C   s>   |p
|j ƒ | _|jdƒ| _|jdƒ| _|jdƒ| _| jƒ  d S )Nr   )r   Ú_lockr   Ú_sleeping_countÚ_woken_countÚ_wait_semaphorer    )r$   Úlockr(   r   r   r   r+   Ô   s
    zCondition.__init__c             C   s   t j| ƒ | j| j| j| jfS )N)r	   r2   rS   rT   rU   rV   )r$   r   r   r   r4   Û   s    
zCondition.__getstate__c             C   s    |\| _ | _| _| _| jƒ  d S )N)rS   rT   rU   rV   r    )r$   r5   r   r   r   r6   à   s    zCondition.__setstate__c             C   s
   | j jƒ S )N)rS   r/   )r$   r   r   r   r/   å   s    zCondition.__enter__c             G   s   | j j|Ž S )N)rS   r0   )r$   r1   r   r   r   r0   è   s    zCondition.__exit__c             C   s   | j j| _| j j| _d S )N)rS   r-   r.   )r$   r   r   r   r    ë   s    
zCondition._make_methodsc             C   sJ   y| j jjƒ | jjjƒ  }W n tk
r4   d}Y nX d| jj| j|f S )NrC   z<%s(%s, %s)>)rT   r   rA   rU   rD   rE   r:   rS   )r$   Znum_waitersr   r   r   rF   ï   s    

zCondition.__repr__c             C   s‚   | j jjƒ stdƒ‚| jjƒ  | j jjƒ }xt|ƒD ]}| j jƒ  q4W z| jj	d|ƒS | j
jƒ  xt|ƒD ]}| j j	ƒ  qjW X d S )Nz,must acquire() condition before using wait()T)rS   r   rL   ÚAssertionErrorrT   r.   rO   r   rV   r-   rU   )r$   ÚtimeoutrR   r)   r   r   r   Úwait÷   s    

zCondition.waitc             C   s|   | j jjƒ stdƒ‚| jjdƒ s&t‚x$| jjdƒrJ| jjdƒ}|s(t‚q(W | jjdƒrx| jjƒ  | jjƒ  | jjdƒ d S )Nzlock is not ownedF)	rS   r   rL   rX   rV   r-   rU   rT   r.   )r$   Úresr   r   r   Únotify  s    

zCondition.notifyc             C   sª   | j jjƒ stdƒ‚| jjdƒ s&t‚x$| jjdƒrJ| jjdƒ}|s(t‚q(W d}x"| jjdƒrr| jjƒ  |d7 }qRW |r¦xt	|ƒD ]}| jjƒ  q‚W x| jjdƒr¤q–W d S )Nzlock is not ownedFr   r   )
rS   r   rL   rX   rV   r-   rU   rT   r.   r   )r$   r[   Zsleepersr)   r   r   r   Ú
notify_all  s    
zCondition.notify_allc             C   sh   |ƒ }|r|S |d k	r$t jƒ | }nd }d }x6|sb|d k	rP|t jƒ  }|dkrPP | j|ƒ |ƒ }q.W |S )Nr   )ÚtimeZ	monotonicrZ   )r$   Z	predicaterY   ÚresultZendtimeZwaittimer   r   r   Úwait_for6  s    

zCondition.wait_for)N)N)N)r:   r;   r<   r+   r4   r6   r/   r0   r    rF   rZ   r\   r]   r`   r   r   r   r   r   Ò   s   

c               @   s6   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zdd
d„Zd	S )r   c            C   s    |j |jƒ ƒ| _|jdƒ| _d S )Nr   )r   r   Ú_condr   Ú_flag)r$   r(   r   r   r   r+   N  s    zEvent.__init__c          	   C   s0   | j �  | jjdƒr"| jjƒ  dS dS Q R X d S )NFT)ra   rb   r-   r.   )r$   r   r   r   Úis_setR  s
    
zEvent.is_setc          	   C   s6   | j �& | jjdƒ | jjƒ  | j jƒ  W d Q R X d S )NF)ra   rb   r-   r.   r]   )r$   r   r   r   ÚsetY  s    
z	Event.setc          	   C   s"   | j � | jjdƒ W d Q R X d S )NF)ra   rb   r-   )r$   r   r   r   Úclear_  s    zEvent.clearNc          	   C   sT   | j �D | jjdƒr | jjƒ  n| j j|ƒ | jjdƒrF| jjƒ  dS dS Q R X d S )NFT)ra   rb   r-   r.   rZ   )r$   rY   r   r   r   rZ   c  s    
z
Event.wait)N)r:   r;   r<   r+   rc   rd   re   rZ   r   r   r   r   r   L  s
   c               @   sZ   e Zd Zddd„Zdd„ Zdd„ Zedd	„ ƒZejd
d	„ ƒZedd„ ƒZ	e	jdd„ ƒZ	dS )ÚBarrierNc      	      C   sR   dd l }ddlm} ||jdƒd ƒ}|jƒ }| j|||||fƒ d| _d| _d S )Nr   r   )ÚBufferWrapperr)   r   )ÚstructÚheaprg   Zcalcsizer   r6   Ú_staterO   )	r$   ZpartiesÚactionrY   r(   rh   rg   ÚwrapperZcondr   r   r   r+   u  s    zBarrier.__init__c             C   s.   |\| _ | _| _| _| _| jjƒ jdƒ| _d S )Nr)   )Ú_partiesÚ_actionÚ_timeoutra   Ú_wrapperZcreate_memoryviewÚcastÚ_array)r$   r5   r   r   r   r6   ~  s    zBarrier.__setstate__c             C   s   | j | j| j| j| jfS )N)rm   rn   ro   ra   rp   )r$   r   r   r   r4   ƒ  s    zBarrier.__getstate__c             C   s
   | j d S )Nr   )rr   )r$   r   r   r   rj   ‡  s    zBarrier._statec             C   s   || j d< d S )Nr   )rr   )r$   r&   r   r   r   rj   ‹  s    c             C   s
   | j d S )Nr   )rr   )r$   r   r   r   rO   �  s    zBarrier._countc             C   s   || j d< d S )Nr   )rr   )r$   r&   r   r   r   rO   “  s    )NN)
r:   r;   r<   r+   r6   r4   Úpropertyrj   ÚsetterrO   r   r   r   r   rf   s  s   
	rf   zRThis platform lacks a functioning sem_open implementation, therefore, the requiredz}This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will notz—This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.)Ú__all__rM   r   r=   r   r^   Ú r	   r
   r   r   r   ÚImportErrorÚlistr   rP   r?   r@   Úobjectr   r   r   r   r   r   rf   r   r   r   r   Ú<module>   s0    Mz'