
    xKg                     l   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Zd dlZd dl	m
Z
 d dlmZ d dlmZmZ e j                   j"                  Ze j$                  e_        g e_        ej*                  dk(  r<e j,                  j.                  j0                  Ze j4                  ge_        de_        dZnZ e j8                  e j:                  j=                  d            j>                  Ze j4                  ge_        e j@                  e_        dZd	 Z!d
Z"d Z#d Z$ G d de      Z%e&dk(  r ejN                          yy)    N)jit)errors)TestCasetagnt   ci  c                 P    |D ]!  }t        dt        z         t               | |<   # y )N
   )sleepsleep_factorPyThread_get_thread_identaindicesidxs      X/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_gil.pyfr   "   s'    
 b< *,#     zvoid(int64[:], intp[:])c                 d    t                |D ]!  }t        dt        z         t               | |<   # y)z/
    Same as f(), but inside a lifted loop
    r   N)objectr   r   r   r   s      r   lifted_fr   .   s,     Hb< *,# r   c                 d    |D ]+  }t        dt        z         t                t               | |<   - y)z)
    Same as f(), but in object mode
    r   N)r   r   r   r   r   s      r   object_fr   8   s,     b< *,#	 r   c                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)TestGILReleasec                 L    t        j                  |t         j                        S )Ndtype)nparangeint64)self	n_memberss     r   make_test_arrayzTestGILRelease.make_test_arrayE   s    yy"((33r   c                    g } || j                  d      t        j                  dt        j                               | j                  d      }t	        |      D ]z  }t        j                  |j
                  t        j                        }t        j                  j                  |       t        j                  |||f      }|j                  |       | |D ]  }|j                           |D ]  }|j                           |S )Nr   r   2   )targetargs)r%   r    r!   intprangesizerandomshuffle	threadingThreadappendstartjoin)r#   func	n_threadsthreadsarrir   ts           r   run_in_threadszTestGILRelease.run_in_threadsH   s     	T!!!$bii&AB""2&y!A ii8GIIg&  C>BANN1 " AGGI AFFH 
r   c                 x    | j                  |d      }t        |      }| j                  t        |      d|       y )N   )r5   r   )r:   setassertEquallen)r#   r4   r7   distincts       r   check_gil_heldzTestGILRelease.check_gil_held\   s6    !!$!!4s8X84r   c                     dD ]=  }| j                  ||      }t        |      }	 | j                  t        |      d|        y  # t        $ r}|}Y d }~Rd }~ww xY w)N)r<          r   )r:   r=   assertGreaterr?   AssertionError)r#   r4   r5   r7   r@   efailures          r   check_gil_releasedz!TestGILRelease.check_gil_releaseda   sg    $I %%dI6C3xH""3x=!X>  % 	 " s   A	AAAc                 \     t        t        d      t              }| j                  |       y)zu
        Test the GIL is held by default, by checking serialized runs
        produce deterministic results.
        TnopythonNr   f_sigr   rA   r#   cfuncs     r   test_gil_heldzTestGILRelease.test_gil_heldo   s%    
 *ED)!,E"r   c                 ^     t        t        dd      t              }| j                  |       y)zj
        Test releasing the GIL, by checking parallel runs produce
        unpredictable results.
        TrL   nogilNr   rN   r   rI   rO   s     r   test_gil_releasedz TestGILRelease.test_gil_releasedw   s'    
 6ED5a8&r   c                 ^     t        t        dd      t              }| j                  |       y)zz
        Test the GIL can by released by a lifted loop even though the
        surrounding code uses object mode.
        TforceobjrT   N)r   rN   r   rI   rO   s     r   $test_gil_released_inside_lifted_loopz3TestGILRelease.test_gil_released_inside_lifted_loop   s'    
 6ED5h?&r   c                      t        t        d      t              t        t        dd      fd       }| j                  |       y)zh
        Releasing the GIL in the caller is sufficient to have it
        released in a callee.
        TrK   rS   c                      | |       y N r   r8   
compiled_fs     r   callerz:TestGILRelease.test_gil_released_by_caller.<locals>.caller       q!r   NrU   r#   ra   r`   s     @r   test_gil_released_by_callerz*TestGILRelease.test_gil_released_by_caller   sA    
 /S.q1
	UT	.	 
/	'r   c                      t        t        dd      t              t        t        dd      fd       }| j                  |       y)zR
        Same, but with both caller and callee asking to release the GIL.
        TrS   c                      | |       y r]   r^   r_   s     r   ra   zETestGILRelease.test_gil_released_by_caller_and_callee.<locals>.caller   rb   r   NrU   rc   s     @r   &test_gil_released_by_caller_and_calleez5TestGILRelease.test_gil_released_by_caller_and_callee   sC     ;ST:1=
	UT	.	 
/	'r   c                      t        t        dd      t              t        t        d      fd       }| j                  |       y)zP
        When only the callee asks to release the GIL, it gets ignored.
        TrS   rK   c                      | |       y r]   r^   r_   s     r   ra   z9TestGILRelease.test_gil_ignored_by_callee.<locals>.caller   rb   r   NrM   rc   s     @r   test_gil_ignored_by_calleez)TestGILRelease.test_gil_ignored_by_callee   sA     ;ST:1=
	UT	"	 
#	F#r   c                 B   t        j                  d      5 }t        j                  dt        j                          t        t        dd      t              }ddd       | j                  t        d D              |       | j                  d       y# 1 sw Y   >xY w)za
        When the function is compiled in object mode, a warning is
        printed out.
        T)recordalwaysrX   Nc              3      K   | ]9  }|j                   t        j                  u xr d t        |j                        v  ; yw)z:Code running in object mode won't allow parallel executionN)categoryr   NumbaWarningstrmessage).0ws     r   	<genexpr>z2TestGILRelease.test_object_mode.<locals>.<genexpr>   sH      ,%* JJ&*=*== o \`cdedmdm`n no%*s   ?A   )warningscatch_warningssimplefilterr   rp   r   rN   r   
assertTrueanyr:   )r#   wlistrP   s      r   test_object_modezTestGILRelease.test_object_mode   s    
 $$D1U!!(F,?,?@9CD9(CE 2 	 ,%*, ,-2	4 	E1% 21s   ABBN)__name__
__module____qualname__r%   r:   rA   rI   rQ   rV   rZ   rd   rg   rj   r}   r^   r   r   r   r   C   s9    4(5
#''	(($&r   r   __main__)(ctypesctypes.utilossysr/   rw   numpyr    unittestnumbar   
numba.corer   numba.tests.supportr   r   	pythonapir   c_longrestypeargtypesnamewindllkernel32Sleepr   c_uintr   CDLLutilfind_libraryusleepc_intr   rN   r   r   r   r~   mainr^   r   r   <module>r      s     	 
       - #,,FF $*MM  !%'  " 77d?MM""((Emm_ENEMLFKK0056==Emm_ENLLEML- 	"--o&X o&d zHMMO r   