/*
    Lock.h, Copyright  (c) by George Fankhauser, Claudio Jeker,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
        
        File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Topsy/Lock.h,v $
        Author(s):             George Fankhauser
        Affiliation:           ETH Zuerich, TIK
        Version:               $Revision: 2937 $
        Creation Date:         
        Last Date of Change:   $Date: 2007-03-21 16:06:20 +0100 (Mit, 21 Mär 2007) $      by: $Author: rnatau $
*/
#ifndef _LOCK_H_
#define _LOCK_H_

#include "Topsy.h"


typedef struct LockDesc_t
{
  Boolean lockVariable;
}
LockDesc;

typedef LockDesc* Lock;

typedef struct BigLockDesc_t
{
  LockDesc lock;
  int shared;
  int exclusive;
  int wait;
}
BigLockDesc;

typedef BigLockDesc* BigLock;

void lockInit(Lock lock);
void lock(Lock lock);
void unlock(Lock lock);
Boolean lockTry(Lock lock);

void bigLockInit(BigLock big);
void bigLockShared(BigLock big);
void bigLockUpgrade(BigLock big);
void bigLockDowngrade(BigLock big);
void bigLockUnlock(BigLock big);

Boolean bigLockSharedTry(BigLock big);
Boolean bigLockUpgradeTry(BigLock big);
Boolean bigLockUnexclusiveTry(BigLock big);
Boolean bigLockUnlockTry(BigLock big);

#endif
