Your IP : 3.144.119.149


Current Path : /opt/alt/python34/lib64/python3.4/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/multiprocessing/__pycache__/heap.cpython-34.pyc

�
e f�@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�||_xwtd�D]]}dtj�t|j�f}tjd|d|�}tj�dkriPn|j	�qWt
d��||_||_|j|jf|_
dS)N�dz	pym-%d-%sr�tagnamerzCannot find name for new mmap���)�size�range�os�getpid�next�_rand�mmap�_winapi�GetLastError�close�FileExistsError�name�buffer�_state)�selfr�irZbuf�r�9/opt/alt/python34/lib64/python3.4/multiprocessing/heap.py�__init__#s			zArena.__init__cCstj|�|jS)N)rZassert_spawningr)rrrr�__getstate__2s
zArena.__getstate__cCsY|\|_|_|_tjd|jd|j�|_tj�tjksUt�dS)Nrr
r)	rrrrrrrZERROR_ALREADY_EXISTS�AssertionError)r�staterrr�__setstate__6s!zArena.__setstate__N)	�__name__�
__module__�__qualname__�tempfileZ_RandomNameSequencerrrr"rrrrrsrc@seZdZddd�ZdS)rrc
Cs�||_||_|d	kr�tjddtj�dtj��\|_}tj|�tj	|tj
|jf�t|jddd��}|jd|�WdQXnt
j
|j|j�|_dS)
Nr�prefixzpym-%d-�dir�wb�closefdFsr)r�fdr&ZmkstemprrrZget_temp_dir�unlink�Finalizer�open�writerr)rrr+r�frrrr?s			(
zArena.__init__Nr)r#r$r%rrrrrr=scCs=|jdkrtd��nt|jtj|j�ffS)NrzDArena is unpicklable because forking was enabled when it was createdr)r+�
ValueError�
rebuild_arenarrZDupFd)�arrr�reduce_arenaKsr4cCst||j��S)N)r�detach)rZdupfdrrrr2Qsr2c@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rrrr^s						z
Heap.__init__cCs|d}|||@S)Nrr)�nZ	alignment�maskrrr�_roundupks
z
Heap._roundupc	Cs	tj|j|�}|t|j�kr�|jt|j|�tj�}|jd9_t	j
d|�t|�}|jj
|�|d|fS|j|}|j|}|j�}|s�|j|=|j|=n|\}}}|j||f=|j||f=|S)N�z"allocating a new mmap of length %dr)�bisectZbisect_leftr<�lenrF�maxr;r�PAGESIZEr�inforrB�appendr=�popr>r?)	rrr�length�arena�seq�block�start�stoprrr�_mallocqs"!


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=rMrHZinsortr<)	rrRrPrSrTZ
prev_block�_Z
next_blockrOrrr�_free�s(



z
Heap._freecCs�|\}}}|j||f=|j||f=||}|j|}|j|�|sv|j|=|jj|�n||fS)N)r>r?r=�remover<)rrRrPrSrTrOrQrrrrW�s



zHeap._absorbcCsQxJy|jj�}Wntk
r+PYnX|jj|�|j|�qWdS)N)rCrN�
IndexErrorrArZrY)rrRrrr�_free_pending_blocks�s
zHeap._free_pending_blocksc
Cs�tj�|jkst�|jjd�s@|jj|�n<z+|j�|j	j
|�|j|�Wd|jj�XdS)NF)
rrr8r r:�acquirerCrMr\rArZrY�release)rrRrrr�free�s

z	Heap.freec
Cs�d|kotjkns%t�tj�|jkrG|j�n|jj�|j	�z�|j
t|d�|j�}|j
|�\}}}||}||kr�|j|||f�n|||f}|jj|�|SWd|jj�XdS)Nrr)�sys�maxsizer rrr8rr:r]r\rFrJ�
_alignmentrUrYrA�addr^)rrrPrSrTZnew_stoprRrrr�malloc�s%



zHeap.mallocN)r#r$r%rbrrKr�staticmethodrFrUrYrWr\r_rdrrrrr6Zs

r6c@s1eZdZe�Zdd�Zdd�ZdS)rcCsid|kotjkns%t�tjj|�}||f|_tj|tjj	d|f�dS)Nr�args)
r`rar r�_heaprdrrr-r_)rrrRrrrr�s%zBufferWrapper.__init__cCs3|j\\}}}}t|j�|||�S)N)r�
memoryviewr)rrPrSrTrrrr�create_memoryview�szBufferWrapper.create_memoryviewN)r#r$r%r6rgrrirrrrr�s	)rHrrr`r&r9�rrr�__all__�platformr�objectrr4r2�registerr6rrrrr�<module>
s$	�

?>