/*<ATGCOPYRIGHT>
 * Copyright (C) 1997 Art Technology Group, Inc.
 * All Rights Reserved.  No use, copying or distribution of this
 * work may be made except in accordance with a valid license
 * agreement from Art Technology Group.  This notice must be
 * included on all copies, modifications and derivatives of this
 * work.
 *
 * Art Technology Group (ATG) MAKES NO REPRESENTATIONS OR WARRANTIES 
 * ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. ATG SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, 
 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * "Dynamo" is a trademark of Art Technology Group, Inc.
 </ATGCOPYRIGHT>*/

/* 
   rwLocks.h - interface for read-write locks
 */



#ifndef _RWLOCKS_H_
#define _RWLOCKS_H_


#ifdef _DRP_MTHREAD

#include "threadabstr.h"


/*typedef struct _RWLock RWLock; */


/* RWLock: read-write lock object */
struct _RWLock {
  Thread_CSKey critKey;         /* critical-section key for this read-write
				   lock (see threadabstr.h) */
  unsigned int readLocks;       /* number of read locks currently held on
				   this rwlock */
  unsigned int writeLocks;      /* number of write locks currently held on
				   this rwLock (should be 0 or 1) */
  unsigned int writersWaiting;  /* number of entities that are currently
				   trying to obtain a write lock */
};


/* default timeout values for obtaining read and write locks */
#define kRWL_DefaultReadTimeout 50
#define kRWL_DefaultWriteTimeout 100


int initializeRWLock(RWLock * oLock);
void discardRWLock(RWLock * oLock);

int getReadLock(RWLock * iLock, unsigned long iTimeout);
int releaseReadLock(RWLock * iLock);
int getWriteLock(RWLock * iLock, unsigned long iTimeout);
int releaseWriteLock(RWLock * iLock);

#else   /* i.e. ndef _DRP_MTHREAD */

/* define functions to empty macros */
#define initializeRWLock(l)     0
#define discardRWLock(l)        0
#define getReadLock(l,t)        0
#define releaseReadLock(l)      0
#define getWriteLock(l,t)       0
#define releaseWriteLock(l)     0

#endif

#endif
