<commit_before>
from cpython cimport pythread
from cpython.exc cimport PyErr_NoMemory

cdef extern from *:
    # Compatibility definitions for Python
    """
    #if PY_VERSION_HEX >= 0x030700a2
    typedef unsigned long pythread_t;
    #else
    typedef long pythread_t;
    #endif
    """
    
    # Just let Cython understand that pythread_t is
    # a long type, but be aware that it is actually
    # signed for versions of Python prior to 3.7.0a2 and
    # unsigned for later versions
    ctypedef unsigned long pythread_t

cdef class FastRLock:
    """Fast, re-entrant locking.

    Under uncongested conditions, the lock is never acquired but only
    counted.  Only when a second thread comes in and notices that the
    lock is needed, it acquires the lock and notifies the first thread
    to release it when it's done.  This is all made possible by the
    wonderful GIL.
    """
    cdef pythread.PyThread_type_lock _real_lock
    cdef pythread_t _owner               # ID of thread owning the lock
    cdef unsigned int _count             # re-entry count
    cdef unsigned int _pending_requests  # number of pending requests for real lock
    cdef bint _is_locked                 # whether the real lock is acquired

    def __cinit__(self):
        self._owner = 0
        self._count = 0
        self._is_locked = False
        self._pending_requests = 0
        self._real_lock = pythread.PyThread_allocate_lock()
        if self._real_lock is NULL:
            PyErr_NoMemory()

    def __dealloc__(self):
        if self._real_lock is not NULL:
            pythread.PyThread_free_lock(self._real_lock)
            self._real_lock = NULL

    def acquire(self, bint blocking=True):
        return lock_lock(self, pythread.PyThread_get_thread_ident(), blocking)

    def release(self):
        if self._count == 0 or self._owner != pythread.PyThread_get_thread_ident():
            raise RuntimeError("cannot release un-acquired lock")
        unlock_lock(self)

    # compatibility with RLock
<commit_msg>Minor code cleanups.<commit_after>
from cpython cimport pythread

cdef extern from *:
    # Compatibility definitions for Python
    """
    #if PY_VERSION_HEX >= 0x030700a2
    typedef unsigned long pythread_t;
    #else
    typedef long pythread_t;
    #endif
    """
    
    # Just let Cython understand that pythread_t is
    # a long type, but be aware that it is actually
    # signed for versions of Python prior to 3.7.0a2 and
    # unsigned for later versions
    ctypedef unsigned long pythread_t


cdef class FastRLock:
    """Fast, re-entrant locking.

    Under uncongested conditions, the lock is never acquired but only
    counted.  Only when a second thread comes in and notices that the
    lock is needed, it acquires the lock and notifies the first thread
    to release it when it's done.  This is all made possible by the
    wonderful GIL.
    """
    cdef pythread.PyThread_type_lock _real_lock
    cdef pythread_t _owner               # ID of thread owning the lock
    cdef unsigned int _count             # re-entry count
    cdef unsigned int _pending_requests  # number of pending requests for real lock
    cdef bint _is_locked                 # whether the real lock is acquired

    def __cinit__(self):
        self._owner = 0
        self._count = 0
        self._is_locked = False
        self._pending_requests = 0
        self._real_lock = pythread.PyThread_allocate_lock()
        if self._real_lock is NULL:
            raise MemoryError

    def __dealloc__(self):
        if self._real_lock is not NULL:
            pythread.PyThread_free_lock(self._real_lock)
            self._real_lock = NULL

    def acquire(self, bint blocking=True):
        return lock_lock(self, pythread.PyThread_get_thread_ident(), blocking)

    def release(self):
        if self._count == 0 or self._owner != pythread.PyThread_get_thread_ident():
            raise RuntimeError("cannot release un-acquired lock")
        unlock_lock(self)

    # compatibility with RLock

{'fraction_non_alphanumeric': 0.0557630072193179, 'fraction_numerical': 0.007966143888473986, 'mean_word_length': 2.5715555555555554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1720871', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1130, 'n_words': 413}