Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 07 Dec 2002 15:52:01 +0100
From:      Dag-Erling Smorgrav <des@ofug.org>
To:        sparc@freebsd.org
Cc:        peter@freebsd.org
Subject:   libc_r
Message-ID:  <xzpbs3xj2zy.fsf@flood.ping.uio.no>

next in thread | raw e-mail | index | archive | help
--=-=-=

I was quite surprised to discover that sparc64, which is supposedly a
tier 1 platform and our reference 64-bit platform, doesn't have a
working libc_r, so I decided to take a shot at it.  I've arrived at
what I believe is a correct implementation for _atomic_lock() (see
attached source code).  It seems to work as expected when called from
a simple test program which attempts to acquire the same lock twice:

l is now 0x0
_atomic_lock() returned 0x0
l after _atomic_lock(): 0xff00000000000000
l is now 0xff00000000000000
_atomic_lock() returned 0xff
l after _atomic_lock(): 0xff00000000000000

I've never written sparc assembler before, so caveat emptor, slippery
when wet, do not look into laser with remaining eye, etc.

I haven't started on pthread_private.h yet, and I'm not sure I can
handle it on my own, but I hope this will inspire someone to tackle
it.

DES
-- 
Dag-Erling Smorgrav - des@ofug.org


--=-=-=
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename=_atomic_lock.S
Content-Transfer-Encoding: quoted-printable

/*-
 * Copyright (c) 2002 Dag-Erling Co=EFdan Sm=F8rgrav
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer
 *    in this position and unchanged.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <machine/asm.h>

__FBSDID("$FreeBSD$");

/*
 * long _atomic_lock(long *)
 *
 * Atomically acquire a lock by storing a non-zero value in its
 * location, provided it is not already locked.  Note that we only use
 * the first byte of the location provided.
 */
ENTRY(_atomic_lock)
	ldstub [%o0], %o1
	membar #LoadLoad
	retl
	mov %o1, %o0
END(_atomic_lock)

--=-=-=--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-sparc" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpbs3xj2zy.fsf>