Your IP : 3.14.245.172


Current Path : /opt/alt/python35/lib64/python3.5/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/multiprocessing/__pycache__/heap.cpython-35.pyc



��Yf� �@s#ddlZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	dgZ
ejdkr�ddlZGdd	�d	e
�Zn>Gd
d	�d	e
�Zdd�Zd
d�Zejee�Gdd�de
�ZGdd�de
�ZdS)�N�)�context)�	reduction)�util�
BufferWrapper�win32c@s@eZdZej�Zdd�Zdd�Zdd�ZdS)�ArenacCs�||_xttd�D]Z}dtj�t|j�f}tjd|d|�}tj�dkrfP|j	�qWt
d��||_||_|j|jf|_
dS)N�dz	pym-%d-%sr�tagnamerzCannot find name for new mmap���)�size�range�os�getpid�next�_rand�mmap�_winapiZGetLastError�close�FileExistsError�name�buffer�_state)�selfr�irZbuf�r�9/opt/alt/python35/lib64/python3.5/multiprocessing/heap.py�__init__#s			zArena.__init__cCstj|�|jS)N)rZassert_spawningr)rrrr�__getstate__2s
zArena.__getstate__cCs>|\|_|_|_tjd|jd|j�|_dS)Nrr
r)rrrrr)r�staterrr�__setstate__6szArena.__setstate__N)	�__name__�
__module__�__qualname__�tempfileZ_RandomNameSequencerrrr rrrrrsrc@seZdZddd�ZdS)rrcCs-||_||_|d
krtjddtj�dtj��\|_}tj|�tj	|tj
|jf�t|jddd��{}d}||kr�d	|}x%t||�D]}|j
|�q�W~|j
d	||�|j�|kst�WdQRXtj|j|j�|_dS)Nr�prefixzpym-%d-�dir�wb�closefdFisri)r�fdr$ZmkstemprrrZget_temp_dir�unlink�Finalizer�openr
�write�tell�AssertionErrorrr)rrr)r�fZbsZzeros�_rrrrAs"			(

zArena.__init__Nr)r!r"r#rrrrrr?scCs:|jdkrtd��t|jtj|j�ffS)NrzDArena is unpicklable because forking was enabled when it was createdr)r)�
ValueError�
rebuild_arenarrZDupFd)�arrr�reduce_arenaTsr5cCst||j��S)N)r�detach)rZdupfdrrrr3Zsr3c@s�eZdZdZejdd�Zedd��Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�ZdS)�Heap�cCsmtj�|_tj�|_||_g|_i|_i|_	i|_
t�|_g|_
g|_dS)N)rr�_lastpid�	threadingZLock�_lock�_size�_lengths�_len_to_seq�_start_to_block�_stop_to_block�set�_allocated_blocks�_arenas�_pending_free_blocks)rrrrrrgs						z
Heap.__init__cCs|d}|||@S)Nrr)�nZ	alignment�maskrrr�_roundupts
z
Heap._roundupc	Cstj|j|�}|t|j�kr�|jt|j|�tj�}|jd9_t	j
d|�t|�}|jj
|�|d|fS|j|}|j|}|j�}|s�|j|=|j|=|\}}}|j||f=|j||f=|S)N�z"allocating a new mmap of length %dr)�bisectZbisect_leftr=�lenrG�maxr<r�PAGESIZEr�inforrC�appendr>�popr?r@)	rrr�length�arena�seq�block�start�stoprrr�_malloczs"!


zHeap._mallocc	Cs$|\}}}y|j||f}Wntk
r:YnX|j|�\}}y|j||f}Wntk
r{YnX|j|�\}}|||f}||}y|j|j|�Wn5tk
r�|g|j|<tj|j|�YnX||j||f<||j||f<dS)N)	r@�KeyError�_absorbr?r>rNrIZinsortr=)	rrSrQrTrUZ
prev_blockr1Z
next_blockrPrrr�_free�s(



z
Heap._freecCs}|\}}}|j||f=|j||f=||}|j|}|j|�|ss|j|=|jj|�||fS)N)r?r@r>�remover=)rrSrQrTrUrPrRrrrrX�s



zHeap._absorbcCsQxJy|jj�}Wntk
r+PYnX|jj|�|j|�qWdS)N)rDrO�
IndexErrorrBrZrY)rrSrrr�_free_pending_blocks�s
zHeap._free_pending_blocksc
Cs�tj�|jkst�|jjd�s@|jj|�n<z+|j�|j	j
|�|j|�Wd|jj�XdS)NF)
rrr9r/r;�acquirerDrNr\rBrZrY�release)rrSrrr�free�s

z	Heap.freecCs�d|kotjkns%t�tj�|jkrD|j�|j��|j�|j	t
|d�|j�}|j|�\}}}||}||kr�|j
|||f�|||f}|jj|�|SWdQRXdS)Nrr)�sys�maxsizer/rrr9rr;r\rGrK�
_alignmentrVrYrB�add)rrrQrTrUZnew_stoprSrrr�malloc�s%



zHeap.mallocN)r!r"r#rbrrLr�staticmethodrGrVrYrXr\r_rdrrrrr7cs

r7c@s1eZdZe�Zdd�Zdd�ZdS)rcCsid|kotjkns%t�tjj|�}||f|_tj|tjj	d|f�dS)Nr�args)
r`rar/r�_heaprdrrr+r_)rrrSrrrr�s%zBufferWrapper.__init__cCs3|j\\}}}}t|j�|||�S)N)r�
memoryviewr)rrQrTrUrrrr�create_memoryview�szBufferWrapper.create_memoryviewN)r!r"r#r7rgrrirrrrr�s	)rIrrr`r$r:�rrr�__all__�platformr�objectrr5r3�registerr7rrrrr�<module>
s$	 �

?>