Date: Tue, 1 Mar 2005 21:51:35 GMT From: Olivier Houchard <cognet@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 72298 for review Message-ID: <200503012151.j21LpZbC099654@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=72298 Change 72298 by cognet@cognet on 2005/03/01 21:50:44 - Define ARM_HAS_ATOMIC_CMPSET_32, and provide a braindead atomic_cmpset_32() implementation. - Use malloc/free instead of _rtld_allocate_tls/_rtld_free_tls, as tls support is not there on arm yet. (Many thanks to David for bringing back arm support) Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/arch/arm/Makefile.inc#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/arm/arm/pthread_md.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/arm/include/pthread_md.h#4 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/arm/Makefile.inc#4 (text+ko) ==== @@ -2,4 +2,6 @@ .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/${MACHINE_ARCH} +CFLAGS+= -DARM_HAS_ATOMIC_CMPSET_32 + SRCS+= pthread_md.c ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/arm/arm/pthread_md.c#4 (text+ko) ==== @@ -26,22 +26,22 @@ * $FreeBSD$ */ +#include <stdlib.h> #include <sys/types.h> #include <rtld_tls.h> #include "pthread_md.h" +struct umtx arm_umtx = { + .u_owner = UMTX_UNOWNED +}; + struct tcb * _tcb_ctor(struct pthread *thread, int initial) { struct tcb *tcb; - void *oldtls; - if (initial) - oldtls = _tcb_get(); - else - oldtls = NULL; - tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); + tcb = malloc(sizeof(struct tcb)); if (tcb) tcb->tcb_thread = thread; return (tcb); @@ -50,5 +50,5 @@ void _tcb_dtor(struct tcb *tcb) { - _rtld_free_tls(tcb, sizeof(struct tcb), 16); + free(tcb); } ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/arm/include/pthread_md.h#4 (text+ko) ==== @@ -35,7 +35,12 @@ #include <sys/types.h> #include <machine/sysarch.h> #include <stddef.h> +#include <errno.h> + +static __inline int atomic_cmpset_32(volatile uint32_t *, uint32_t, uint32_t); +#include <sys/umtx.h> + #define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* @@ -58,7 +63,7 @@ static __inline void _tcb_set(struct tcb *tcb) { - *((struct tcb *)ARM_TP_ADDRESS) = tcb; + *((struct tcb **)ARM_TP_ADDRESS) = tcb; } /* @@ -67,7 +72,7 @@ static __inline struct tcb * _tcb_get(void) { - return (*((struct tcb *)ARM_TP_ADDRESS)); + return (*((struct tcb **)ARM_TP_ADDRESS)); } extern struct pthread *_thr_initial; @@ -80,4 +85,22 @@ return (NULL); } +extern struct umtx arm_umtx; + +static __inline int +atomic_cmpset_32(volatile uint32_t *dst, uint32_t old, uint32_t newval) +{ + int ret; + + _umtx_lock(&arm_umtx); + arm_umtx.u_owner = (void*)((uint32_t)arm_umtx.u_owner | UMTX_CONTESTED); + if (*dst == old) { + *dst = newval; + ret = 1; + } else + ret = 0; + _umtx_unlock(&arm_umtx); + return (ret); +} + #endif /* _PTHREAD_MD_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200503012151.j21LpZbC099654>