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