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