pthread_all.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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
  5. // +build !freebsd,!openbsd
  6. package libc // import "modernc.org/libc"
  7. import (
  8. "unsafe"
  9. "modernc.org/libc/pthread"
  10. )
  11. // int pthread_attr_init(pthread_attr_t *attr);
  12. func Xpthread_attr_init(t *TLS, pAttr uintptr) int32 {
  13. *(*pthread.Pthread_attr_t)(unsafe.Pointer(pAttr)) = pthread.Pthread_attr_t{}
  14. return 0
  15. }
  16. // The pthread_mutex_init() function shall initialize the mutex referenced by
  17. // mutex with attributes specified by attr. If attr is NULL, the default mutex
  18. // attributes are used; the effect shall be the same as passing the address of
  19. // a default mutex attributes object. Upon successful initialization, the state
  20. // of the mutex becomes initialized and unlocked.
  21. //
  22. // If successful, the pthread_mutex_destroy() and pthread_mutex_init()
  23. // functions shall return zero; otherwise, an error number shall be returned to
  24. // indicate the error.
  25. //
  26. // int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
  27. func Xpthread_mutex_init(t *TLS, pMutex, pAttr uintptr) int32 {
  28. typ := pthread.PTHREAD_MUTEX_DEFAULT
  29. if pAttr != 0 {
  30. typ = int(X__ccgo_pthreadMutexattrGettype(t, pAttr))
  31. }
  32. mutexesMu.Lock()
  33. defer mutexesMu.Unlock()
  34. mutexes[pMutex] = newMutex(typ)
  35. return 0
  36. }