/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident "$Header: slock.c 1.2 89/05/31 $"

/*
 * lock.c
 *	Implementation of spin-locks.
 * 
 * A "lock" is a byte of memory, initialized to zero (unlocked).
 *
 * A lock may be released by just clearing it (uses bus-watch cache).
 */

#include "parallel.h"
#include "parc.h"

/*
 * s_init_lock()
 *	Initialize the lock by simply writing it with L_UNLOCKED.
 *
 * Note that locks are implicitly initialized (unlocked) by placing them
 * in newly created space (shsbrk()) or shared bss.  Locks may also be
 * explicitly initialized to L_UNLOCKED.
 */

s_init_lock(lock)
	slock_t	*lock;
{
	S_UNLOCK(lock);
}

/*
 * fortran version
 */
s_init_lock_(lock)
	slock_t	*lock;
{
	S_UNLOCK(lock);
}


/*
 * s_lock()
 *	Acquire a lock by waiting for it to be unlocked, then
 *	atomically setting it to locked.
 */

s_lock(lock)
	register slock_t *lock;
{
	S_LOCK(lock);
}

/*
 * fortran version
 */
s_lock_(lock)
	register slock_t *lock;
{
	S_LOCK(lock);
}


/*
 * s_unlock()
 *	Release a lock.
 */

s_unlock(lock)
	slock_t	*lock;
{
	S_UNLOCK(lock);
}

/*
 * fortran version
 */
 s_unlock_(lock)
	slock_t	*lock;
{
	S_UNLOCK(lock);
}


/*
 * s_clock()
 *
 * Conditional "spin" lock.
 *
 * If the lock is available, grab it and return L_SUCCESS
 * Otherwise DON'T spin on the lock.  Just return L_FAILED
 */

	/*
	 * Use a machine-dependent implementation, extracted from parallel.h
	 */
s_clock(lp)	
slock_t *lp;
{
	return(S_CLOCK(lp));
}

/*
 * Fortran version
 */
s_clock_(lp)	
slock_t *lp;
{
	return(S_CLOCK(lp));
}
