ó
O'—^c           @@  sd  d  d l  m Z d  d l 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	 m
 Z
 d d l m Z m Z m Z d d l m Z d d l m Z d g Z y e j Z Wn e k
 rÜ e j Z n Xe j d	 k rd
 e f d „  ƒ  YZ n/ d
 e f d „  ƒ  YZ d „  Z e j e e ƒ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   i    (   t   absolute_importNi   (   t	   _billiardt   win32(   t   Finalizet   infot   get_temp_dir(   t   assert_spawning(   t   ForkingPicklert   BufferWrapperR   t   Arenac           B@  s/   e  Z e j ƒ  Z d  „  Z d „  Z d „  Z RS(   c         C@  sƒ   | |  _  d t j ƒ  t t j ƒ f |  _ t j d |  j  d |  j ƒ|  _ t	 j
 ƒ  d k sj t d ƒ ‚ |  j  |  j f |  _ d  S(   Ns	   pym-%d-%diÿÿÿÿt   tagnamei    s   tagname already in use(   t   sizet   ost   getpidt   nextR	   t   _countert   namet   mmapt   bufferR   t   GetLastErrort   AssertionErrort   _state(   t   selfR   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   __init__(   s
    	"!c         C@  s   t  |  ƒ |  j S(   N(   R   R   (   R   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   __getstate__/   s    
c         C@  sY   | \ |  _  |  _ |  _ t j d |  j  d |  j ƒ|  _ t j ƒ  t j k sU t ‚ d  S(   NiÿÿÿÿR
   (	   R   R   R   R   R   R   R   t   ERROR_ALREADY_EXISTSR   (   R   t   state(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   __setstate__3   s    !(   t   __name__t
   __module__t	   itertoolst   countR   R   R   R   (    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyR	   $   s   		c           B@  s    e  Z e j ƒ  Z d  d „ Z RS(   iÿÿÿÿc         C@  sÑ   d d l  m } | |  _ | |  _ | d k r² | r² t j j t ƒ  d t j ƒ  t	 |  j
 ƒ f ƒ } t j | t j t j Bt j Bd ƒ |  _ t j | ƒ t j |  j | ƒ n  t j |  j |  j ƒ |  _ d  S(   Ni   (   t   _forking_is_enablediÿÿÿÿs	   pym-%d-%di€  (   t   forkingR    R   t   filenoR   t   patht   joinR   R   R   R   t   opent   O_RDWRt   O_CREATt   O_EXCLt   unlinkt	   ftruncateR   R   (   R   R   R"   R    R   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyR   >   s    			"#(   R   R   R   R   R   R   (    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyR	   :   s   c         C@  s4   |  j  d k r t d ƒ ‚ n  t |  j |  j  f f S(   NiÿÿÿÿsC   Arena is unpicklable becauseforking was enabled when it was created(   R"   t
   ValueErrorR	   R   (   t   a(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   reduce_arenaL   s    t   Heapc           B@  sb   e  Z d  Z e j d „ Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z RS(	   i   c         C@  sm   t  j ƒ  |  _ t j ƒ  |  _ | |  _ g  |  _ i  |  _ i  |  _	 i  |  _
 t ƒ  |  _ g  |  _ g  |  _ d  S(   N(   R   R   t   _lastpidt	   threadingt   Lockt   _lockt   _sizet   _lengthst   _len_to_seqt   _start_to_blockt   _stop_to_blockt   sett   _allocated_blockst   _arenast   _pending_free_blocks(   R   R   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyR   ]   s    						c         C@  s   | d } |  | | @S(   Ni   (    (   t   nt	   alignmentt   mask(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   _roundupj   s    
c   	      C@  s  t  j |  j | ƒ } | t |  j ƒ k r |  j t |  j | ƒ t j ƒ } |  j d 9_ t	 d | ƒ t
 | ƒ } |  j j | ƒ | d | f S|  j | } |  j | } | j ƒ  } | sÓ |  j | =|  j | =n  | \ } } } |  j | | f =|  j | | f =| S(   Ni   s"   allocating a new mmap of length %di    (   t   bisectt   bisect_leftR4   t   lenR?   t   maxR3   R   t   PAGESIZER   R	   R:   t   appendR5   t   popR6   R7   (	   R   R   t   it   lengtht   arenat   seqt   blockt   startt   stop(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   _mallocp   s"    !c   	      C@  s!  | \ } } } y |  j  | | f } Wn t k
 r9 n X|  j | ƒ \ } } y |  j | | f } Wn t k
 ry n X|  j | ƒ \ } } | | | f } | | } y |  j | j | ƒ Wn4 t k
 rö | g |  j | <t j |  j | ƒ n X| |  j | | f <| |  j  | | f <d  S(   N(	   R7   t   KeyErrort   _absorbR6   R5   RE   R@   t   insortR4   (	   R   RK   RI   RL   RM   t
   prev_blockt   _t
   next_blockRH   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   _free†   s(    
c         C@  s€   | \ } } } |  j  | | f =|  j | | f =| | } |  j | } | j | ƒ | sv |  j | =|  j j | ƒ n  | | f S(   N(   R6   R7   R5   t   removeR4   (   R   RK   RI   RL   RM   RH   RJ   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyRP   ¤   s    

c         C@  sP   xI y |  j  j ƒ  } Wn t k
 r* Pn X|  j j | ƒ |  j | ƒ q Wd  S(   N(   R;   RF   t
   IndexErrorR9   RV   RU   (   R   RK   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   _free_pending_blocks³   s    c         C@  s€   t  j ƒ  |  j k s t ‚ |  j j t ƒ s@ |  j j | ƒ n< z+ |  j	 ƒ  |  j
 j | ƒ |  j | ƒ Wd  |  j j ƒ  Xd  S(   N(   R   R   R/   R   R2   t   acquiret   FalseR;   RE   RX   R9   RV   RU   t   release(   R   RK   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   free½   s    
c         C@  sü   d | k o t  k  n s" t ‚ t j ƒ  |  j k rD |  j ƒ  n  |  j j ƒ  |  j ƒ  zŒ |  j	 t
 | d ƒ |  j ƒ } |  j | ƒ \ } } } | | } | | k  rÃ |  j | | | f ƒ n  | | | f } |  j j | ƒ | SWd  |  j j ƒ  Xd  S(   Ni    i   (   t   maxsizeR   R   R   R/   R   R2   RY   RX   R?   RC   t
   _alignmentRN   RU   R9   t   addR[   (   R   R   RI   RL   RM   t   new_stopRK   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   mallocÖ   s    "

(   R   R   R^   R   RD   R   t   staticmethodR?   RN   RU   RP   RX   R\   Ra   (    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyR.   Y   s   				
	c           B@  s,   e  Z e ƒ  Z d  „  Z d „  Z d „  Z RS(   c         C@  sc   d | k o t  k  n s" t ‚ t j j | ƒ } | | f |  _ t |  t j j d | f ƒd  S(   Ni    t   args(   R]   R   R   t   _heapRa   R   R   R\   (   R   R   RK   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyR   ò   s    "c         C@  sJ   |  j  \ \ } } } } t j | j ƒ \ } } | | k sB t ‚ | | S(   N(   R   R   t   address_of_bufferR   R   (   R   RI   RL   RM   R   t   addressRH   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   get_addressø   s    c         C@  s   |  j  d S(   Ni   (   R   (   R   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   get_sizeþ   s    (   R   R   R.   Rd   R   Rg   Rh   (    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyR   î   s   			(   t
   __future__R    R@   R   R   t   sysR0   R   t   _extR   R   t   utilR   R   R   R!   R   t	   reductionR   t   __all__R]   t   AttributeErrort   maxintt   platformt   objectR	   R-   t   registerR.   R   (    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/heap.pyt   <module>	   s,   		•