CPN
Computational Process Networks
QueueBase.h
Go to the documentation of this file.
1 //=============================================================================
2 // Computational Process Networks class library
3 // Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
14 //
15 // The GNU Public License is available in the file LICENSE, or you
16 // can write to the Free Software Foundation, Inc., 59 Temple Place -
17 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
18 // World Wide Web at http://www.fsf.org.
19 //=============================================================================
24 #ifndef CPN_QUEUEBASE_H
25 #define CPN_QUEUEBASE_H
26 #pragma once
27 
28 #include "common_priv.h"
31 #include <cpn/d4r/D4RQueue.h>
32 #include <cpn/utils/Logger.h>
33 
34 namespace CPN {
35 
40  public:
41 
42  virtual ~QueueBase();
43 
55  const void *GetRawDequeuePtr(unsigned thresh, unsigned chan);
56 
63  void Dequeue(unsigned count);
64 
77  bool RawDequeue(void *data, unsigned count,
78  unsigned numChans, unsigned chanStride);
79 
86  bool RawDequeue(void *data, unsigned count);
87 
101  void *GetRawEnqueuePtr(unsigned thresh, unsigned chan);
102 
114  void Enqueue(unsigned count);
115 
131  void RawEnqueue(const void *data, unsigned count,
132  unsigned numChans, unsigned chanStride);
133 
139  void RawEnqueue(const void *data, unsigned count);
140 
141  void Reset();
142  void Flush();
143  bool Flushed() const;
144 
148  unsigned NumChannels() const;
149 
153  unsigned Count() const;
154 
158  bool Empty() const;
159 
164  unsigned Freespace() const;
165 
169  bool Full() const;
170 
175  unsigned MaxThreshold() const;
176 
181  unsigned QueueLength() const;
182 
188  unsigned EnqueueChannelStride() const;
194  unsigned DequeueChannelStride() const;
195 
206  void Grow(unsigned queueLen, unsigned maxThresh);
207 
209  Key_t GetWriterKey() const { return writerkey; }
211  Key_t GetReaderKey() const { return readerkey; }
213  const std::string &GetDatatype() const { return datatype; }
215  void ShutdownReader();
217  void ShutdownWriter();
219  void NotifyTerminate();
220 
221  void Lock() const { lock.Lock(); }
222  void Unlock() const { lock.Unlock(); }
223 
225  unsigned ReadRequest();
227  unsigned WriteRequest();
228  bool IsReaderShutdown();
229  bool IsWriterShutdown();
230 
232  virtual void LogState();
233 
234  unsigned NumEnqueued() const;
235  unsigned NumDequeued() const;
236  protected:
237  QueueBase(KernelBase *k, const SimpleQueueAttr &attr);
238 
239  virtual void WaitForData();
240  virtual bool ReadBlocked();
241  void NotifyData();
242  virtual void WaitForFreespace();
243  virtual bool WriteBlocked();
244  void NotifyFreespace();
245 
246  virtual void Wait() { cond.Wait(lock); }
247  virtual void Signal() { cond.Broadcast(); }
248 
249  virtual void Detect();
250 
251  virtual const void *InternalGetRawDequeuePtr(unsigned thresh, unsigned chan) = 0;
252  virtual void InternalDequeue(unsigned count) = 0;
253  virtual void *InternalGetRawEnqueuePtr(unsigned thresh, unsigned chan) = 0;
254  virtual void InternalEnqueue(unsigned count) = 0;
255 
256  virtual void InternalFlush();
257  virtual void InternalReset();
258  virtual unsigned UnlockedNumChannels() const = 0;
259  virtual unsigned UnlockedCount() const = 0;
260  virtual bool UnlockedEmpty() const = 0;
261  virtual unsigned UnlockedFreespace() const = 0;
262  virtual bool UnlockedFull() const = 0;
263  virtual unsigned UnlockedMaxThreshold() const = 0;
264  virtual unsigned UnlockedQueueLength() const = 0;
265  virtual unsigned UnlockedEnqueueChannelStride() const = 0;
266  virtual unsigned UnlockedDequeueChannelStride() const = 0;
267  virtual void UnlockedGrow(unsigned queueLen, unsigned maxThresh) = 0;
268  virtual void UnlockedShutdownReader();
269  virtual void UnlockedShutdownWriter();
270  virtual unsigned UnlockedNumEnqueued() const = 0;
271  virtual unsigned UnlockedNumDequeued() const = 0;
272 
277  unsigned prepad;
278  unsigned postpad;
279  unsigned readrequest;
280  unsigned writerequest;
281  unsigned enqueuethresh;
282  unsigned dequeuethresh;
283  bool indequeue;
284  bool inenqueue;
285  bool flushed;
287  bool useD4R;
291  std::string datatype;
292  };
293 
294 }
295 #endif
Logger object that is used for forwarding log messages.
Definition: Logger.h:57
PthreadMutex & Lock(void)
Definition: PthreadMutex.h:49
unsigned readrequest
Definition: QueueBase.h:279
unsigned prepad
Definition: QueueBase.h:277
Logger logger
Definition: QueueBase.h:288
virtual void Wait()
Definition: QueueBase.h:246
void Lock() const
Definition: QueueBase.h:221
Key_t GetReaderKey() const
Definition: QueueBase.h:211
unsigned writerequest
Definition: QueueBase.h:280
uint64_t Key_t
Definition: common.h:79
unsigned postpad
Definition: QueueBase.h:278
The base class for all queues in the CPN library.
Definition: QueueBase.h:39
void Unlock() const
Definition: QueueBase.h:222
#define CPN_LOCAL
Definition: common.h:37
const std::string & GetDatatype() const
Definition: QueueBase.h:213
virtual void Signal()
Definition: QueueBase.h:247
PthreadMutex & Unlock(void)
Definition: PthreadMutex.h:50
unsigned dequeuethresh
Definition: QueueBase.h:282
const Key_t readerkey
Definition: QueueBase.h:273
std::string datatype
Definition: QueueBase.h:291
KernelBase * kernel
Definition: QueueBase.h:286
A very simple logging interface.
bool writeshutdown
Definition: QueueBase.h:276
Key_t GetWriterKey() const
Definition: QueueBase.h:209
static PthreadMutex lock
Definition: NodeLoader.cc:36
bool readshutdown
Definition: QueueBase.h:275
unsigned enqueuethresh
Definition: QueueBase.h:281
PthreadCondition cond
Definition: QueueBase.h:290
This is a simplified internal representation of the queue attributes needed to create a queue...
Definition: QueueAttr.h:237
PthreadMutex lock
Definition: QueueBase.h:289
const Key_t writerkey
Definition: QueueBase.h:274