1/*
2	Copyright 1999-2001, 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
13#ifdef __cplusplus
14  extern "C" {
15#endif
16
17typedef struct lock lock;
18typedef struct mlock mlock;
19
20struct lock {
21	sem_id		s;
22	long		c;
23};
24
25struct mlock {
26	sem_id		s;
27};
28
29extern _IMPEXP_KERNEL int	new_lock(lock *l, const char *name);
30extern _IMPEXP_KERNEL int	free_lock(lock *l);
31
32#define	LOCK(l)		if (atomic_add(&l.c, -1) <= 0) acquire_sem(l.s);
33#define	UNLOCK(l)	if (atomic_add(&l.c, 1) < 0) release_sem(l.s);
34
35extern _IMPEXP_KERNEL int	new_mlock(mlock *l, long c, const char *name);
36extern _IMPEXP_KERNEL int	free_mlock(mlock *l);
37
38#define		LOCKM(l,cnt)	acquire_sem_etc(l.s, cnt, 0, 0)
39#define		UNLOCKM(l,cnt)	release_sem_etc(l.s, cnt, 0)
40
41
42#ifdef __cplusplus
43  } // extern "C"
44#endif
45
46#endif
47