Skip to content

Commit

Permalink
fixup! Fix: add Thread.start/stop_world + remove GC.sig_suspend/resume
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Jun 19, 2024
1 parent e105927 commit 9c934d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/crystal/system/thread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ class Thread
system_resume
end

def stop_world : Nil
def self.stop_world : Nil
GC.stop_world
end

def start_world : Nil
def self.start_world : Nil
GC.start_world
end
end
Expand Down
24 changes: 11 additions & 13 deletions src/crystal/system/unix/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ module Crystal::System::Thread
# notify that the thread has been interrupted
Thread.current_thread.@suspended.set(true)

# block all signals but sig_resume
# block all signals but SIG_RESUME
mask = LibC::SigsetT.new
LibC.sigfillset(pointerof(mask))
LibC.sigdelset(pointerof(mask), sig_resume)
LibC.sigdelset(pointerof(mask), SIG_RESUME)

# suspend the thread until it receives the sig_resume signal
# suspend the thread until it receives the SIG_RESUME signal
LibC.sigsuspend(pointerof(mask))
end
LibC.sigemptyset(pointerof(action.@sa_mask))
LibC.sigaction(sig_suspend, pointerof(action), nil)
LibC.sigaction(SIG_SUSPEND, pointerof(action), nil)
end

private def self.install_sig_resume_signal_handler
Expand All @@ -188,13 +188,13 @@ module Crystal::System::Thread
# do nothing (a handler is still required to receive the signal)
end
LibC.sigemptyset(pointerof(action.@sa_mask))
LibC.sigaction(sig_resume, pointerof(action), nil)
LibC.sigaction(SIG_RESUME, pointerof(action), nil)
end

private def system_suspend : Nil
@suspended.set(false)

if LibC.pthread_kill(@system_handle, Thread.sig_suspend) == -1
if LibC.pthread_kill(@system_handle, SIG_SUSPEND) == -1
System.panic("pthread_kill()")
end
end
Expand All @@ -206,30 +206,28 @@ module Crystal::System::Thread
end

private def system_resume : Nil
if LibC.pthread_kill(@system_handle, Thread.sig_resume) == -1
if LibC.pthread_kill(@system_handle, SIG_RESUME) == -1
System.panic("pthread_kill()")
end
end

protected class_property(sig_suspend : Int32) do
# follows bdwgc
# the suspend/resume signals follow BDWGC

private SIG_SUSPEND =
{% if flag?(:linux) %}
LibC::SIGPWR
{% elsif LibC.has_constant?(:SIGRTMIN) %}
LibC::SIGRTMIN + 6
{% else %}
LibC::SIGXFSZ
{% end %}
end

protected class_property(sig_resume : Int32) do
# follows bdwgc
private SIG_RESUME =
{% if LibC.has_constant?(:SIGRTMIN) %}
LibC::SIGRTMIN + 5
{% else %}
LibC::SIGXCPU
{% end %}
end
end

# In musl (alpine) the calls to unwind API segfaults
Expand Down

0 comments on commit 9c934d5

Please sign in to comment.