fix getting the current thread on linux & mac
This commit is contained in:
15
error.go
15
error.go
@@ -1,16 +1,13 @@
|
|||||||
package xmlsec
|
package xmlsec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"C"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/crewjam/errset"
|
"github.com/crewjam/errset"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include <pthread.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
var globalErrors = map[uintptr]errset.ErrSet{}
|
var globalErrors = map[uintptr]errset.ErrSet{}
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
@@ -45,7 +42,7 @@ func onError(file *C.char, line C.int, funcName *C.char, errorObject *C.char, er
|
|||||||
Subject: C.GoString(errorSubject),
|
Subject: C.GoString(errorSubject),
|
||||||
Reason: int(reason),
|
Reason: int(reason),
|
||||||
Message: C.GoString(msg)}
|
Message: C.GoString(msg)}
|
||||||
threadID := uintptr(unsafe.Pointer(C.pthread_self()))
|
threadID := getThreadId()
|
||||||
globalErrors[threadID] = append(globalErrors[threadID], err)
|
globalErrors[threadID] = append(globalErrors[threadID], err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,22 +51,20 @@ func onError(file *C.char, line C.int, funcName *C.char, errorObject *C.char, er
|
|||||||
// error object.
|
// error object.
|
||||||
func startProcessingXML() {
|
func startProcessingXML() {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
threadID := uintptr(unsafe.Pointer(C.pthread_self()))
|
globalErrors[getThreadId()] = errset.ErrSet{}
|
||||||
globalErrors[threadID] = errset.ErrSet{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stopProcessingXML unlocks the goroutine-thread lock and deletes the current
|
// stopProcessingXML unlocks the goroutine-thread lock and deletes the current
|
||||||
// error stack.
|
// error stack.
|
||||||
func stopProcessingXML() {
|
func stopProcessingXML() {
|
||||||
runtime.UnlockOSThread()
|
runtime.UnlockOSThread()
|
||||||
threadID := uintptr(unsafe.Pointer(C.pthread_self()))
|
delete(globalErrors, getThreadId())
|
||||||
delete(globalErrors, threadID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// popError returns the global error for the current thread and resets it to
|
// popError returns the global error for the current thread and resets it to
|
||||||
// an empty error. Returns nil if no errors have occurred.
|
// an empty error. Returns nil if no errors have occurred.
|
||||||
func popError() error {
|
func popError() error {
|
||||||
threadID := uintptr(unsafe.Pointer(C.pthread_self()))
|
threadID := getThreadId()
|
||||||
rv := globalErrors[threadID].ReturnValue()
|
rv := globalErrors[threadID].ReturnValue()
|
||||||
globalErrors[threadID] = errset.ErrSet{}
|
globalErrors[threadID] = errset.ErrSet{}
|
||||||
return rv
|
return rv
|
||||||
|
|||||||
10
thread_darwin.go
Normal file
10
thread_darwin.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package xmlsec
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// #include <pthread.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
func getThreadId() uintptr {
|
||||||
|
return uintptr(unsafe.Pointer(C.pthread_self()))
|
||||||
|
}
|
||||||
7
thread_linux.go
Normal file
7
thread_linux.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package xmlsec
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func getThreadId() uintptr {
|
||||||
|
return uintptr(syscall.Gettid())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user