Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full

This is a stopgap until the thorpej-atomic branch is complete.
This commit is contained in:
ad 2007-09-07 00:24:56 +00:00
parent c67dc640cd
commit a6ed47a549
5 changed files with 67 additions and 9 deletions

@ -1,4 +1,4 @@
/* $NetBSD: _context_u.S,v 1.2 2003/01/18 10:34:18 thorpej Exp $ */
/* $NetBSD: _context_u.S,v 1.3 2007/09/07 00:24:57 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -99,3 +99,30 @@ ENTRY(_swapcontext_u_xmm)
movl %eax, (UC_REGS + _REG_UESP * 4)(%ecx)
movl 8(%esp), %ecx
SETC
ENTRY(pthread__atomic_cas_ptr)
movl 4(%esp), %ecx
movl 8(%esp), %eax
movl 12(%esp), %edx
movl (%eax), %eax
lock
cmpxchgl %edx, (%ecx)
jnz 1f
mov $1, %eax
ret
1:
mov 8(%esp), %edx
mov %eax, (%edx)
mov $0, %eax
ret
ENTRY(pthread__atomic_swap_ptr)
movl 4(%esp), %ecx
movl 8(%esp), %eax
xchgl %eax, (%ecx)
ret
ENTRY(pthread__membar_full)
lock
addl $0, -4(%esp)
ret

@ -1,4 +1,4 @@
/* $NetBSD: pthread_md.h,v 1.7 2006/03/29 22:55:15 cube Exp $ */
/* $NetBSD: pthread_md.h,v 1.8 2007/09/07 00:24:57 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -181,4 +181,8 @@ pthread__sp(void)
(uc)->uc_flags = ((uc)->uc_flags | _UC_FXSAVE) & ~_UC_USER; \
} while (/*CONSTCOND*/0)
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")
#define PTHREAD__CHEAP_UNLOCK
#define PTHREAD__HAVE_ATOMIC
#endif /* _LIB_PTHREAD_I386_MD_H */

@ -1,4 +1,4 @@
/* $NetBSD: _context_u.S,v 1.4 2004/10/21 16:49:47 fvdl Exp $ */
/* $NetBSD: _context_u.S,v 1.5 2007/09/07 00:24:57 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -135,3 +135,25 @@ ENTRY(_swapcontext_u)
movq %rax, (UC_REGS + _REG_URSP * 8)(%rdi)
movq %rsi, %rdi
SETC
ENTRY(pthread__atomic_cas_ptr)
movq (%rsi), %rax
lock
cmpxchgq %rdx, (%rdi)
jnz 1f
movq $1, %rax
ret
1:
movq %rax, (%rsi)
movq $0, %rax
ret
ENTRY(pthread__atomic_swap_ptr)
movq %rsi, %rax
xchgq %rax, (%rdi)
ret
ENTRY(pthread__membar_full)
lock
addq $0, -4(%rsp)
ret

@ -1,4 +1,4 @@
/* $NetBSD: pthread_md.h,v 1.4 2005/12/24 21:11:17 perry Exp $ */
/* $NetBSD: pthread_md.h,v 1.5 2007/09/07 00:24:57 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -103,4 +103,8 @@ pthread__sp(void)
(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER; \
} while (/*CONSTCOND*/0)
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")
#define PTHREAD__CHEAP_UNLOCK
#define PTHREAD__HAVE_ATOMIC
#endif /* _LIB_PTHREAD_X86_64_MD_H */

@ -1,4 +1,4 @@
/* $NetBSD: pthread_int.h,v 1.49 2007/08/16 13:54:16 ad Exp $ */
/* $NetBSD: pthread_int.h,v 1.50 2007/09/07 00:24:56 ad Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007 The NetBSD Foundation, Inc.
@ -240,10 +240,11 @@ void pthread__assertfunc(const char *file, int line, const char *function,
void pthread__errorfunc(const char *file, int line, const char *function,
const char *msg);
#if defined(i386) || defined(__x86_64__)
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")
#define PTHREAD__CHEAP_UNLOCK
#else
int pthread__atomic_cas_ptr(volatile void *, void **, void *);
void *pthread__atomic_swap_ptr(volatile void *, void *);
void pthread__membar_full(void);
#ifndef pthread__smt_pause
#define pthread__smt_pause() /* nothing */
#endif