FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: use C __atomic builtins for debug counters by fantix · Pull Request #719 · MagicStack/uvloop · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .pxd  (1) .pyx  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 12 additions & 6 deletions uvloop/cbhandles.pyx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ cdef class Handle:
cdef inline _set_loop(self, Loop loop):
self.loop = loop
if UVLOOP_DEBUG:
loop._debug_cb_handles_total += 1
loop._debug_cb_handles_count += 1
system.__atomic_fetch_add(
&loop._debug_cb_handles_total, 1, system.__ATOMIC_RELAXED)
system.__atomic_fetch_add(
&loop._debug_cb_handles_count, 1, system.__ATOMIC_RELAXED)
if loop._debug:
self._source_traceback = extract_stack()

Expand All @@ -21,7 +23,8 @@ cdef class Handle:

def __dealloc__(self):
if UVLOOP_DEBUG and self.loop is not None:
self.loop._debug_cb_handles_count -= 1
system.__atomic_fetch_sub(
&self.loop._debug_cb_handles_count, 1, system.__ATOMIC_RELAXED)
if self.loop is None:
raise RuntimeError('Handle.loop is None in Handle.__dealloc__')

Expand Down Expand Up @@ -174,8 +177,10 @@ cdef class TimerHandle:
self._cancelled = 0

if UVLOOP_DEBUG:
self.loop._debug_cb_timer_handles_total += 1
self.loop._debug_cb_timer_handles_count += 1
system.__atomic_fetch_add(
&self.loop._debug_cb_timer_handles_total, 1, system.__ATOMIC_RELAXED)
system.__atomic_fetch_add(
&self.loop._debug_cb_timer_handles_count, 1, system.__ATOMIC_RELAXED)

if context is None:
context = Context_CopyCurrent()
Expand Down Expand Up @@ -205,7 +210,8 @@ cdef class TimerHandle:

def __dealloc__(self):
if UVLOOP_DEBUG:
self.loop._debug_cb_timer_handles_count -= 1
system.__atomic_fetch_sub(
&self.loop._debug_cb_timer_handles_count, 1, system.__ATOMIC_RELAXED)
if self.timer is not None:
raise RuntimeError('active TimerHandle is deallacating')

Expand Down
8 changes: 8 additions & 0 deletions uvloop/includes/system.pxd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ cdef extern from "includes/fork_handler.h":
void setForkHandler(OnForkHandler handler)
void resetForkHandler()
void setMainThreadID(uint64_t id)


cdef extern from * nogil:
uint64_t __atomic_fetch_add(uint64_t *ptr, uint64_t val, int memorder)
uint64_t __atomic_fetch_sub(uint64_t *ptr, uint64_t val, int memorder)

cdef enum:
__ATOMIC_RELAXED

Back | FazBrowse Home | New Git URL