1// readerWriter.h
2
3#ifndef _READERWRITER_H_
4#define _READERWRITER_H_
5
6#include "beCompat.h"
7#include "betalk.h"
8
9typedef struct managedData
10{
11	int32 readCount;
12	int32 writeCount;
13
14	// These two semaphores control access to the readCount and writeCount
15	// variables.
16	sem_id readCountSem;
17	sem_id writeCountSem;
18
19	// The first process wishes to gain read access blocks on the reader
20	// semaphore, but all other block on the readerQueue, so that writers
21	// can effectively jump the queue.
22	sem_id readerQueue;
23
24	// Semaphores for holding waiting processes.
25	sem_id reader;
26	sem_id writer;
27} bt_managed_data;
28
29
30bool initManagedData(bt_managed_data *data);
31void closeManagedData(bt_managed_data *data);
32void beginReading(bt_managed_data *data);
33void endReading(bt_managed_data *data);
34void beginWriting(bt_managed_data *data);
35void endWriting(bt_managed_data *data);
36
37#endif
38