xrootd
XrdCpMthrQueue.hh
Go to the documentation of this file.
1 
2 // //
3 // XrdCpMthrQueue //
4 // //
5 // Author: Fabrizio Furano (INFN Padova, 2004) //
6 // //
7 // A thread safe queue to be used for multithreaded producers-consumers //
8 // //
10 
11 #include "XrdSys/XrdSysPthread.hh"
13 #include "XrdSys/XrdSysSemWait.hh"
14 #include "XrdSys/XrdSysHeaders.hh"
15 
16 using namespace std;
17 
18 struct XrdCpMessage {
19  void *buf;
20  long long offs;
21  int len;
22 };
23 
24 // The max allowed size for this queue
25 // If this value is reached, then the writer has to wait...
26 #define CPMTQ_BUFFSIZE 50000000
27 
29  private:
30  long fTotSize;
31  XrdClientVector<XrdCpMessage*> fMsgQue; // queue for incoming messages
32  int fMsgIter; // an iterator on it
33  int fWrWait; // Write waiters
34 
35  XrdSysRecMutex fMutex; // mutex to protect data structures
36 
37  XrdSysSemWait fReadSem; // variable to make the reader wait
38  // until some data is available
39  XrdSysSemaphore fWriteSem; // variable to make the writer wait
40  // if the queue is full
41  public:
42 
45 
46  int PutBuffer(void *buf, long long offs, int len);
47  int GetBuffer(void **buf, long long &offs, int &len);
48  int GetLength() { return fMsgQue.GetSize(); }
49  void Clear();
50 };
51