#include "src/pthread/pthread_spin_init.h"
#include "hdr/errno_macros.h"
#include "src/__support/CPP/new.h"
#include "src/__support/common.h"
#include "src/__support/threads/spin_lock.h"
#include <pthread.h>
namespace LIBC_NAMESPACE_DECL {
static_assert(sizeof(pthread_spinlock_t::__lockword) == sizeof(SpinLock) &&
alignof(decltype(pthread_spinlock_t::__lockword)) ==
alignof(SpinLock),
"pthread_spinlock_t::__lockword and SpinLock must be of the same "
"size and alignment");
LLVM_LIBC_FUNCTION(int, pthread_spin_init,
(pthread_spinlock_t * lock, [[maybe_unused]] int pshared)) {
if (!lock)
return EINVAL;
if (pshared != PTHREAD_PROCESS_SHARED && pshared != PTHREAD_PROCESS_PRIVATE)
return EINVAL;
::new (&lock->__lockword) SpinLock();
lock->__owner = 0;
return 0;
}
}