pthread_all.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2021 The Libc Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build !freebsd && !openbsd && !(linux && (amd64 || arm64 || loong64 || ppc64le || s390x || riscv64 || 386 || arm))
  5. package libc // import "modernc.org/libc"
  6. import (
  7. "unsafe"
  8. "modernc.org/libc/pthread"
  9. )
  10. type pthreadAttr struct {
  11. detachState int32
  12. }
  13. // int pthread_attr_init(pthread_attr_t *attr);
  14. func Xpthread_attr_init(t *TLS, pAttr uintptr) int32 {
  15. if __ccgo_strace {
  16. trc("t=%v pAttr=%v, (%v:)", t, pAttr, origin(2))
  17. }
  18. *(*pthreadAttr)(unsafe.Pointer(pAttr)) = pthreadAttr{}
  19. return 0
  20. }
  21. // The pthread_mutex_init() function shall initialize the mutex referenced by
  22. // mutex with attributes specified by attr. If attr is NULL, the default mutex
  23. // attributes are used; the effect shall be the same as passing the address of
  24. // a default mutex attributes object. Upon successful initialization, the state
  25. // of the mutex becomes initialized and unlocked.
  26. //
  27. // If successful, the pthread_mutex_destroy() and pthread_mutex_init()
  28. // functions shall return zero; otherwise, an error number shall be returned to
  29. // indicate the error.
  30. //
  31. // int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
  32. func Xpthread_mutex_init(t *TLS, pMutex, pAttr uintptr) int32 {
  33. if __ccgo_strace {
  34. trc("t=%v pAttr=%v, (%v:)", t, pAttr, origin(2))
  35. }
  36. typ := pthread.PTHREAD_MUTEX_DEFAULT
  37. if pAttr != 0 {
  38. typ = int(X__ccgo_pthreadMutexattrGettype(t, pAttr))
  39. }
  40. mutexesMu.Lock()
  41. defer mutexesMu.Unlock()
  42. mutexes[pMutex] = newMutex(typ)
  43. return 0
  44. }
  45. func Xpthread_atfork(tls *TLS, prepare, parent, child uintptr) int32 {
  46. // fork(2) not supported.
  47. return 0
  48. }
  49. // int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
  50. func Xpthread_sigmask(tls *TLS, now int32, set, old uintptr) int32 {
  51. // ignored
  52. return 0
  53. }