Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCRE2: optimize memory allocations #15395

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/crystal/system/thread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,16 @@ class Thread
rescue ex
@exception = ex
ensure
run_destructors
Thread.threads.delete(self)
Fiber.inactive(fiber)
detach { system_close }
end
end

protected def run_destructors : Nil
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: cleanup before merge (not needed anymore).


protected def name=(@name : String)
self.system_name = name
end
Expand Down
33 changes: 33 additions & 0 deletions src/crystal/system/thread_local.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Thread
struct Local(T)
# def initialize
# {% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
# end

# def initialize(&destructor : Proc(T, Nil))
# {% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
# end
Comment on lines +3 to +9
Copy link
Contributor

@Sija Sija Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps these could be uncommented and then called via super in descendant classes to avoid duplicating the code?

Suggested change
# def initialize
# {% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
# end
# def initialize(&destructor : Proc(T, Nil))
# {% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
# end
def initialize
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
end
def initialize(&destructor : Proc(T, Nil))
initialize
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It avoids some repetition, but I'm not sure it would improve readability?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we could use Box for this? Seems to be exactly the use case. Technically we don't need support for boxing structs onto the heap though. So this draws in additional complexity which we might want to avoid here.

Copy link
Contributor Author

@ysbaddaden ysbaddaden Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you lost me @straight-shoota 😕

Do you mean to Box the destructor proc? Oh, to Box the value in case it's not a Pointer/Reference! 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to not support non pointer values. If we ever need to, we'll figure it out then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea for using Box would be that it might simplify the code for Thread::Local. All explicit casts would become Box(T).box and Box(T).unbox and no need for checking T type in the macro.
I suppose it doesn't simplify that much though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But Box always allocates into the GC heap, and we'd put the pointer to the box in the local storage that we'd have to dereference on every get 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errata: Box doesn't allocate into the GC heap when T is Nil or Reference but we want to store pointers and that will allocate.

Maybe it's an overlook? 🤔


def get : T
get? || raise KeyError.new
end

def get(& : -> T) : T
get? || set(yield)
end

# def get? : T?

# def set(value : T) : T
end
end

{% if flag?(:wasi) %}
require "./wasi/thread_local"
{% elsif flag?(:unix) %}
require "./unix/thread_local"
{% elsif flag?(:win32) %}
require "./win32/thread_local"
{% else %}
{% raise "Thread not supported" %}
{% end %}
30 changes: 30 additions & 0 deletions src/crystal/system/unix/thread_local.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "c/pthread"

class Thread
struct Local(T)
@key : LibC::PthreadKeyT

def initialize
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
err = LibC.pthread_key_create(out @key, nil)
raise RuntimeError.from_os_error("pthread_key_create", Errno.new(err)) unless err == 0
end

def initialize(&destructor : Proc(T, Nil))
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
err = LibC.pthread_key_create(out @key, destructor.unsafe_as(Proc(Void*, Nil)))
raise RuntimeError.from_os_error("pthread_key_create", Errno.new(err)) unless err == 0
end
Comment on lines +7 to +17
Copy link
Member

@straight-shoota straight-shoota Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Extract the common code into a helper to remove duplication.

Suggested change
def initialize
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
err = LibC.pthread_key_create(out @key, nil)
raise RuntimeError.from_os_error("pthread_key_create", Errno.new(err)) unless err == 0
end
def initialize(&destructor : Proc(T, Nil))
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
err = LibC.pthread_key_create(out @key, destructor.unsafe_as(Proc(Void*, Nil)))
raise RuntimeError.from_os_error("pthread_key_create", Errno.new(err)) unless err == 0
end
def initialize
create_key
end
def initialize(&destructor : Proc(T, Nil))
create_key destructor
end
private def create_key(destructor = nil)
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
err = LibC.pthread_key_create(out @key, destructor.unsafe_as(Proc(Void*, Nil)))
raise RuntimeError.from_os_error("pthread_key_create", Errno.new(err)) unless err == 0
end

ditto for win32


def get? : T?
pointer = LibC.pthread_getspecific(@key)
pointer.as(T) if pointer
end

def set(value : T) : T
err = LibC.pthread_setspecific(@key, value.as(Void*))
raise RuntimeError.from_os_error("pthread_setspecific", Errno.new(err)) unless err == 0
value
end
end
end
21 changes: 21 additions & 0 deletions src/crystal/system/wasi/thread_local.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Thread
struct Local(T)
@value : T?

def initialize
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
end

def initialize(&destructor : T ->)
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
end

def get? : T?
@value
end

def set(value : T) : T
@value = value
end
end
end
30 changes: 30 additions & 0 deletions src/crystal/system/win32/thread_local.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "c/fibersapi"

class Thread
struct Local(T)
@key : LibC::DWORD

def initialize
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
@key = LibC.FlsAlloc
raise RuntimeError.from_winerror("FlsAlloc: out of indexes") if @key == LibC::FLS_OUT_OF_INDEXES
end

def initialize(&destructor : Proc(T, Nil))
{% raise "T must be a Reference or Pointer" unless T < Reference || T < Pointer %}
@key = LibC.FlsAlloc(destructor.unsafe_as(Proc(Void*, Nil)))
raise RuntimeError.from_winerror("FlsAlloc: out of indexes") if @key == LibC::FLS_OUT_OF_INDEXES
end

def get? : T?
pointer = LibC.FlsGetValue(@key)
pointer.as(T) if pointer
end

def set(value : T) : T
ret = LibC.FlsSetValue(@key, value.as(Void*))
raise RuntimeError.from_winerror("FlsSetValue") if ret == 0
value
end
end
end
1 change: 1 addition & 0 deletions src/lib_c/aarch64-android/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ lib LibC
fun pthread_getspecific(__key : PthreadKeyT) : Void*
fun pthread_join(__pthread : PthreadT, __return_value_ptr : Void**) : Int
fun pthread_key_create(__key_ptr : PthreadKeyT*, __key_destructor : Void* ->) : Int
fun pthread_key_delete(__key_ptr : PthreadKeyT) : Int

fun pthread_mutexattr_destroy(__attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(__attr : PthreadMutexattrT*) : Int
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/aarch64-darwin/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ lib LibC
fun pthread_cond_wait(x0 : PthreadCondT*, x1 : PthreadMutexT*) : Int
fun pthread_create(x0 : PthreadT*, x1 : PthreadAttrT*, x2 : Void* -> Void*, x3 : Void*) : Int
fun pthread_detach(x0 : PthreadT) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_get_stackaddr_np(x0 : PthreadT) : Void*
fun pthread_get_stacksize_np(x0 : PthreadT) : SizeT
fun pthread_join(x0 : PthreadT, x1 : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(x0 : PthreadMutexattrT*, x1 : Int) : Int
Expand All @@ -26,4 +30,5 @@ lib LibC
fun pthread_mutex_unlock(x0 : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/aarch64-darwin/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ lib LibC
end

type PthreadT = Void*
alias PthreadKeyT = UInt
alias SSizeT = Long
alias SusecondsT = Int
alias TimeT = Long
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/aarch64-linux-gnu/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ lib LibC
fun pthread_create(newthread : PthreadT*, attr : PthreadAttrT*, start_routine : Void* -> Void*, arg : Void*) : Int
fun pthread_detach(th : PthreadT) : Int
fun pthread_getattr_np(thread : PthreadT, attr : PthreadAttrT*) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_equal(thread1 : PthreadT, thread2 : PthreadT) : Int
fun pthread_join(th : PthreadT, thread_return : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(attr : PthreadMutexattrT*, type : Int) : Int
Expand All @@ -37,4 +41,5 @@ lib LibC
fun pthread_mutex_unlock(mutex : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(PthreadT, Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/aarch64-linux-gnu/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ lib LibC
end

alias PthreadT = ULong
alias PthreadKeyT = UInt
alias SSizeT = Long
alias SusecondsT = Long
alias TimeT = Long
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/aarch64-linux-musl/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ lib LibC
fun pthread_create(x0 : PthreadT*, x1 : PthreadAttrT*, x2 : Void* -> Void*, x3 : Void*) : Int
fun pthread_detach(x0 : PthreadT) : Int
fun pthread_getattr_np(x0 : PthreadT, x1 : PthreadAttrT*) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_join(x0 : PthreadT, x1 : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(x0 : PthreadMutexattrT*, x1 : Int) : Int
Expand All @@ -28,4 +32,5 @@ lib LibC
fun pthread_mutex_unlock(x0 : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(PthreadT, Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/aarch64-linux-musl/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ lib LibC
end

type PthreadT = Void*
alias PthreadKeyT = UInt
alias SSizeT = Long
alias SusecondsT = Long
alias TimeT = Long
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/arm-linux-gnueabihf/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ lib LibC
fun pthread_create(newthread : PthreadT*, attr : PthreadAttrT*, start_routine : Void* -> Void*, arg : Void*) : Int
fun pthread_detach(th : PthreadT) : Int
fun pthread_getattr_np(thread : PthreadT, attr : PthreadAttrT*) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_equal(thread1 : PthreadT, thread2 : PthreadT) : Int
fun pthread_join(th : PthreadT, thread_return : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(attr : PthreadMutexattrT*, type : Int) : Int
Expand All @@ -37,4 +41,5 @@ lib LibC
fun pthread_mutex_unlock(mutex : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(PthreadT, Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/arm-linux-gnueabihf/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ lib LibC
end

alias PthreadT = ULong
alias PthreadKeyT = UInt
alias SSizeT = Int
alias SusecondsT = Long
alias TimeT = Long
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/i386-linux-gnu/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ lib LibC
fun pthread_create(newthread : PthreadT*, attr : PthreadAttrT*, start_routine : Void* -> Void*, arg : Void*) : Int
fun pthread_detach(th : PthreadT) : Int
fun pthread_getattr_np(thread : PthreadT, attr : PthreadAttrT*) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_join(th : PthreadT, thread_return : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(attr : PthreadMutexattrT*, type : Int) : Int
Expand All @@ -36,4 +40,5 @@ lib LibC
fun pthread_mutex_unlock(mutex : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(PthreadT, Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/i386-linux-gnu/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ lib LibC
end

alias PthreadT = ULong
alias PthreadKeyT = UInt
alias SSizeT = Int
alias SusecondsT = Long
alias TimeT = Long
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/i386-linux-musl/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ lib LibC
fun pthread_create(x0 : PthreadT*, x1 : PthreadAttrT*, x2 : Void* -> Void*, x3 : Void*) : Int
fun pthread_detach(x0 : PthreadT) : Int
fun pthread_getattr_np(x0 : PthreadT, x1 : PthreadAttrT*) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_join(x0 : PthreadT, x1 : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(x0 : PthreadMutexattrT*, x1 : Int) : Int
Expand All @@ -28,4 +32,5 @@ lib LibC
fun pthread_mutex_unlock(x0 : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(PthreadT, Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/i386-linux-musl/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ lib LibC
end

type PthreadT = Void*
alias PthreadKeyT = UInt
alias SSizeT = Int
alias SusecondsT = Long
alias TimeT = Long
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/x86_64-darwin/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ lib LibC
fun pthread_detach(x0 : PthreadT) : Int
fun pthread_get_stackaddr_np(x0 : PthreadT) : Void*
fun pthread_get_stacksize_np(x0 : PthreadT) : SizeT
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_join(x0 : PthreadT, x1 : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(x0 : PthreadMutexattrT*, x1 : Int) : Int
Expand All @@ -26,4 +30,5 @@ lib LibC
fun pthread_mutex_unlock(x0 : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/x86_64-darwin/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ lib LibC
end

type PthreadT = Void*
alias PthreadKeyT = UInt
alias SSizeT = Long
alias SusecondsT = Int
alias TimeT = Long
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/x86_64-dragonfly/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ lib LibC
fun pthread_cond_wait(x0 : PthreadCondT*, x1 : PthreadMutexT*) : Int
fun pthread_create(x0 : PthreadT*, x1 : PthreadAttrT*, x2 : Void* -> Void*, x3 : Void*) : Int
fun pthread_detach(x0 : PthreadT) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_join(x0 : PthreadT, x1 : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(x0 : PthreadMutexattrT*, x1 : Int) : Int
Expand All @@ -30,4 +34,5 @@ lib LibC
fun pthread_mutex_unlock(x0 : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(PthreadT, Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/x86_64-dragonfly/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lib LibC
type PthreadAttrT = Void*
type PthreadCondT = Void*
type PthreadCondattrT = Void*
alias PthreadKeyT = Int
type PthreadMutexT = Void*
type PthreadMutexattrT = Void*
type PthreadT = Void*
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/x86_64-freebsd/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ lib LibC
fun pthread_cond_wait(x0 : PthreadCondT*, x1 : PthreadMutexT*) : Int
fun pthread_create(x0 : PthreadT*, x1 : PthreadAttrT*, x2 : Void* -> Void*, x3 : Void*) : Int
fun pthread_detach(x0 : PthreadT) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_join(x0 : PthreadT, x1 : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(x0 : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(x0 : PthreadMutexattrT*, x1 : Int) : Int
Expand All @@ -30,4 +34,5 @@ lib LibC
fun pthread_mutex_unlock(x0 : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_set_name_np(PthreadT, Char*)
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
1 change: 1 addition & 0 deletions src/lib_c/x86_64-freebsd/c/sys/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lib LibC
type PthreadAttrT = Void*
type PthreadCondT = Void*
type PthreadCondattrT = Void*
alias PthreadKeyT = Int
type PthreadMutexT = Void*
type PthreadMutexattrT = Void*
type PthreadT = Void*
Expand Down
5 changes: 5 additions & 0 deletions src/lib_c/x86_64-linux-gnu/c/pthread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ lib LibC
fun pthread_create(newthread : PthreadT*, attr : PthreadAttrT*, start_routine : Void* -> Void*, arg : Void*) : Int
fun pthread_detach(th : PthreadT) : Int
fun pthread_getattr_np(thread : PthreadT, attr : PthreadAttrT*) : Int
fun pthread_getspecific(PthreadKeyT) : Void*
fun pthread_join(th : PthreadT, thread_return : Void**) : Int
alias PthreadKeyDestructor = (Void*) ->
fun pthread_key_create(PthreadKeyT*, PthreadKeyDestructor) : Int
fun pthread_key_delete(PthreadKeyT) : Int
fun pthread_mutexattr_destroy(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_init(attr : PthreadMutexattrT*) : Int
fun pthread_mutexattr_settype(attr : PthreadMutexattrT*, type : Int) : Int
Expand All @@ -36,4 +40,5 @@ lib LibC
fun pthread_mutex_unlock(mutex : PthreadMutexT*) : Int
fun pthread_self : PthreadT
fun pthread_setname_np(PthreadT, Char*) : Int
fun pthread_setspecific(PthreadKeyT, Void*) : Int
end
Loading
Loading