- Add native_queue.go with CGO bindings for queue operations - Add native_queue_stub.go for non-CGO builds - Add hash_selector to choose between Go and native implementations - Add native_bridge_libs.go for CGO builds with native_libs tag - Add native_bridge_nocgo.go stub for non-CGO builds - Update queue errors and task handling for native integration - Update worker config and runloop for native library support
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
//go:build cgo && native_libs
|
|
// +build cgo,native_libs
|
|
|
|
package worker
|
|
|
|
// #cgo LDFLAGS: -L${SRCDIR}/../../native/build -Wl,-rpath,${SRCDIR}/../../native/build -ldataset_hash
|
|
// #include "../../native/dataset_hash/dataset_hash.h"
|
|
// #include <stdlib.h>
|
|
import "C"
|
|
|
|
import (
|
|
"errors"
|
|
"unsafe"
|
|
)
|
|
|
|
// dirOverallSHA256HexNative implementation with native library.
|
|
func dirOverallSHA256HexNative(root string) (string, error) {
|
|
ctx := C.fh_init(0) // 0 = auto-detect threads
|
|
if ctx == nil {
|
|
return "", errors.New("failed to initialize native hash context")
|
|
}
|
|
defer C.fh_cleanup(ctx)
|
|
|
|
croot := C.CString(root)
|
|
defer C.free(unsafe.Pointer(croot))
|
|
|
|
result := C.fh_hash_directory_combined(ctx, croot)
|
|
if result == nil {
|
|
err := C.fh_last_error(ctx)
|
|
if err != nil {
|
|
return "", errors.New(C.GoString(err))
|
|
}
|
|
return "", errors.New("native hash failed")
|
|
}
|
|
defer C.fh_free_string(result)
|
|
|
|
return C.GoString(result), nil
|
|
}
|
|
|
|
// GetSIMDImplName returns the native SHA256 implementation name.
|
|
func GetSIMDImplName() string {
|
|
return C.GoString(C.fh_get_simd_impl_name())
|
|
}
|
|
|
|
// HasSIMDSHA256 returns true if SIMD SHA256 is available.
|
|
func HasSIMDSHA256() bool {
|
|
return C.fh_has_simd_sha256() == 1
|
|
}
|