From e69306a2ba01c3f9b992f979b7d6a0f6952a73f2 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 27 Jul 2024 09:11:38 +0800 Subject: [PATCH 1/2] c/pthread/sync: use go:linkname for internal func --- c/pthread/sync/sync.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/c/pthread/sync/sync.go b/c/pthread/sync/sync.go index 8c9ce5db..233a5e98 100644 --- a/c/pthread/sync/sync.go +++ b/c/pthread/sync/sync.go @@ -76,18 +76,18 @@ func (m *Mutex) Init(attr *MutexAttr) c.Int { return 0 } // llgo:link (*Mutex).Destroy C.pthread_mutex_destroy func (m *Mutex) Destroy() {} -func (m *Mutex) Lock() { m.lockInternal() } - -// llgo:link (*Mutex).lockInternal C.pthread_mutex_lock -func (m *Mutex) lockInternal() c.Int { return 0 } - // llgo:link (*Mutex).TryLock C.pthread_mutex_trylock func (m *Mutex) TryLock() c.Int { return 0 } -func (m *Mutex) Unlock() { m.unlockInternal() } +func (m *Mutex) Lock() { lockInternal(m) } -// llgo:link (*Mutex).unlockInternal C.pthread_mutex_unlock -func (m *Mutex) unlockInternal() c.Int { return 0 } +func (m *Mutex) Unlock() { unlockInternal(m) } + +//go:linkname lockInternal C.pthread_mutex_lock +func lockInternal(m *Mutex) c.Int + +//go:linkname unlockInternal C.pthread_mutex_unlock +func unlockInternal(m *Mutex) c.Int // ----------------------------------------------------------------------------- From 2cd99943212841a9e976b2e2ae5588073003e537 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 27 Jul 2024 09:28:09 +0800 Subject: [PATCH 2/2] C.wrap_pthread_mutex_lock --- c/pthread/sync/_pthd/pthd.c | 12 ++++++++++++ c/pthread/sync/sync.go | 12 ++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/c/pthread/sync/_pthd/pthd.c b/c/pthread/sync/_pthd/pthd.c index e8275a54..f7bc7eb9 100644 --- a/c/pthread/sync/_pthd/pthd.c +++ b/c/pthread/sync/_pthd/pthd.c @@ -5,3 +5,15 @@ pthread_once_t llgoSyncOnceInitVal = PTHREAD_ONCE_INIT; // ----------------------------------------------------------------------------- + +// wrap return type to void +void wrap_pthread_mutex_lock(pthread_mutex_t *mutex) { + pthread_mutex_lock(mutex); +} + +// wrap return type to void +void wrap_pthread_mutex_unlock(pthread_mutex_t *mutex) { + pthread_mutex_unlock(mutex); +} + +// ----------------------------------------------------------------------------- diff --git a/c/pthread/sync/sync.go b/c/pthread/sync/sync.go index 233a5e98..b9e45d48 100644 --- a/c/pthread/sync/sync.go +++ b/c/pthread/sync/sync.go @@ -79,15 +79,11 @@ func (m *Mutex) Destroy() {} // llgo:link (*Mutex).TryLock C.pthread_mutex_trylock func (m *Mutex) TryLock() c.Int { return 0 } -func (m *Mutex) Lock() { lockInternal(m) } +// llgo:link (*Mutex).Lock C.wrap_pthread_mutex_lock +func (m *Mutex) Lock() {} -func (m *Mutex) Unlock() { unlockInternal(m) } - -//go:linkname lockInternal C.pthread_mutex_lock -func lockInternal(m *Mutex) c.Int - -//go:linkname unlockInternal C.pthread_mutex_unlock -func unlockInternal(m *Mutex) c.Int +// llgo:link (*Mutex).Unlock C.wrap_pthread_mutex_unlock +func (m *Mutex) Unlock() {} // -----------------------------------------------------------------------------