00001 /* 00002 * Copyright (C) 2006, Jose Renato Santos. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 */ 00017 00018 /////////////////////////////////////////////////////////////////// 00019 // FifoQueue.h: interface for the CFifoQueue class. 00020 /////////////////////////////////////////////////////////////////// 00021 00022 #if !defined(FIFOQUEUE_H__) 00023 #define FIFOQUEUE_H__ 00024 00025 #include <fstream> 00026 00027 #include "RioMutex.h" 00028 #include "RioSemaphore.h" 00029 00030 #include "RioTypes.h" 00031 00032 //typedef BlockRequest QueueElement; 00033 typedef struct 00034 { 00035 RequestId Id; 00036 RioStreamId Stream; 00037 RequestOperation Operation; 00038 int BufferId; 00039 RioResult Status; 00040 RioPhysicalBlock Block; 00041 } QueueElement; 00042 00043 class CFifoQueue 00044 { 00045 public: 00046 CFifoQueue(); 00047 virtual ~CFifoQueue(); 00048 HRESULT Initialize (int Size, 00049 CSemaphore *SemaphoreElement, 00050 ofstream *Logstream); 00051 void Put (QueueElement *Request); 00052 bool Get (QueueElement *Request); 00053 int nRequests(); 00054 private: 00055 int m_Size; 00056 int m_n; 00057 int m_First; 00058 int m_End; 00059 CSemaphore *m_SemaphorePosition; 00060 CSemaphore *m_SemaphoreElement; 00061 CMutex m_Mutex; 00062 QueueElement *m_Request; 00063 ofstream *m_log; 00064 }; 00065 00066 #endif // !defined(FIFOQUEUE_H__)