]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/arm-ds5-gator.git/blob - daemon/Fifo.h
51e2bcd6a7f888662b9ba664abc7349ca8c483e9
[android-sdk/arm-ds5-gator.git] / daemon / Fifo.h
1 /**
2  * Copyright (C) ARM Limited 2010-2012. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
9 #ifndef __FIFO_H__
10 #define __FIFO_H__
12 #include <semaphore.h>
14 // Number of buffers allowed with large buffer mode
15 #define FIFO_BUFFER_LIMIT       64
17 class Fifo {
18 public:
19         Fifo(int numBuffers, int bufferSize);
20         ~Fifo();
21         int depth(void);
22         int numReadToWriteBuffersFilled();
23         int numWriteToReadBuffersFilled();
24         int numReadToWriteBuffersEmpty() {return depth() - numReadToWriteBuffersFilled();}
25         int numWriteToReadBuffersEmpty() {return depth() - numWriteToReadBuffersFilled();}
26         char* start();
27         char* write(int length);
28         char* read(int* length);
30 private:
31         int             mNumBuffers;
32         int             mBufferSize;
33         int             mWriteCurrent;
34         int             mReadCurrent;
35         sem_t   mReadToWriteSem[FIFO_BUFFER_LIMIT];
36         sem_t   mWriteToReadSem[FIFO_BUFFER_LIMIT];
37         char*   mBuffer[FIFO_BUFFER_LIMIT];
38         int             mLength[FIFO_BUFFER_LIMIT];
39 };
41 #endif  //__FIFO_H__