1/*
2	Copyright 1999, Be Incorporated.   All Rights Reserved.
3	This file may be used under the terms of the Be Sample Code License.
4*/
5
6#ifndef _LOCK_H
7#define _LOCK_H
8
9#include <BeBuild.h>
10
11#include <OS.h>
12
13typedef struct lock lock;
14typedef struct mlock mlock;
15
16struct lock {
17	sem_id		s;
18	long		c;
19};
20
21struct mlock {
22	sem_id		s;
23};
24
25extern _IMPEXP_KERNEL int	new_lock(lock *l, const char *name);
26extern _IMPEXP_KERNEL int	free_lock(lock *l);
27
28#define	LOCK(l)		if (atomic_add(&l.c, -1) <= 0) acquire_sem(l.s);
29#define	UNLOCK(l)	if (atomic_add(&l.c, 1) < 0) release_sem(l.s);
30
31extern _IMPEXP_KERNEL int	new_mlock(mlock *l, long c, const char *name);
32extern _IMPEXP_KERNEL int	free_mlock(mlock *l);
33
34#define		LOCKM(l,cnt)	acquire_sem_etc(l.s, cnt, 0, 0)
35#define		UNLOCKM(l,cnt)	release_sem_etc(l.s, cnt, 0)
36
37#endif
38