CPN
Computational Process Networks
ThresholdQueue.h
Go to the documentation of this file.
1 //=============================================================================
2 // $Id: ThresholdQueue.h,v 1.1 2006/06/12 20:30:13 gallen Exp $
3 //-----------------------------------------------------------------------------
4 // A queue class that is optimized for DSP applications.
5 // Specifically, reading and writing is done directly from queue memory,
6 // and data is guaranteed to be contiguous in memory.
7 //-----------------------------------------------------------------------------
8 // The following _must_ hold: 1 <= qMaxThreshold < qLength
9 //=============================================================================
10 
11 
12 #ifndef ThresholdQueue_h
13 #define ThresholdQueue_h
14 #pragma once
15 #include "common_priv.h"
16 
17 //-----------------------------------------------------------------------------
18 // Implementation notes:
19 //
20 // +-------------------------+--------------+------
21 // | queueLength | mirrorLength | ...
22 // +-------------------------+--------------+------
23 //
24 // This works like a normal queue, but is intended to make up for the lack
25 // of circular address buffers on a general purpose processor.
26 // Where supported, MirrorBufferSet will be used, providing the mirroring in
27 // hardware with the virtual memory manager.
28 // Without MirrorBufferSet, there is a memory vs. performance tradeoff.
29 // When queueLength>>mirrorLength, data copying is seldom necessary.
30 // When queueLength==mirrorLength, copying must happen very frequently.
31 //-----------------------------------------------------------------------------
32 // This class follows the Computational Process Network calling conventions:
33 // - GetDequeuePtr(<thresh>) returns a pointer to <thresh> contiguous elements
34 // which are the next elements to be dequeued. That is, <thresh> elements
35 // must be in the queue before the consumer can fire. This threshold is
36 // equivalent to the [CG] parameter 'T'.
37 // - Dequeue(<count>) releases <count> elements from the queue. This <count>
38 // is equivalent to the [CG] parameter 'W'. Clearly, T >= W.
39 // - GetEnqueuePtr(<thresh>) returns a pointer to space in the queue for
40 // <thresh> contiguous elements, which are the next elements to be
41 // enqueued. That is, space for <thresh> elements must be in the queue
42 // before the producer can fire. (There is no equivalent in [CG].)
43 // - Enqueue(<count>) inserts <count> elements into the queue. This <count>
44 // is equivalent to the [CG] parameter 'U'. Clearly, enqueueThresh >= U.
45 //-----------------------------------------------------------------------------
46 // [CG] is Karp and Miller's Computation Graphs
47 //-----------------------------------------------------------------------------
48 // queueLength - The max number of elements in the queue
49 // dequeueThresh - The number of elements guaranteed contiguous beyond
50 // a pointer returned by GetDequeuePtr()
51 // enqueueThresh - The number of elements which may be written contiguously
52 // beyond a pointer returned by GetEnqueuePtr()
53 // maxThreshold - The max allowable value for dequeueThresh or
54 // enqueueThresh. Also, mirrorLength = maxThreshold-1
55 //-----------------------------------------------------------------------------
56 // To dequeue data:
57 // int count = <dequeueChunkSize>;
58 // T* ptr = theQueue.GetDequeuePtr(count);
59 // if (ptr) {
60 // for (int i=0; i<count; i++)
61 // <outgoingData> = ptr[i];
62 // Dequeue(count);
63 // }
64 // To enqueue data:
65 // int count = <enqueueChunkSize>;
66 // T* ptr = theQueue.GetEnqueuePtr(count);
67 // if (ptr) {
68 // for (int i=0; i<count; i++)
69 // ptr[i] = <incomingData>;
70 // Enqueue(count);
71 // }
72 //-----------------------------------------------------------------------------
73 // Other constructor parameters:
74 // useVMM - use MirrorBufferSet to get mirroring with virtual memory
75 // chanOffset - additional channel-to-channel offset to reduce cache thrashing
76 // baseOffset - additional base offset to reduce cache thrashing
77 // These offsets are in bytes, and do not apply unless useVMM=1
78 // These are performance tuning parameters. They should be a multiple of
79 // the number of bytes in a cache line, and a multiple of sizeof(T)
80 //-----------------------------------------------------------------------------
81 
82 #include "ThresholdQueueBase.h"
83 
84 
85 template<class T>
87  public:
88  ThresholdQueue(ulong queueLen, ulong maxThresh, ulong numChans=1)
89  : ThresholdQueueBase(sizeof(T), queueLen, maxThresh, numChans) { }
91  : ThresholdQueueBase(sizeof(T), attr) { }
92 
93  T* GetEnqueuePtr(ulong enqueueThresh, ulong chan=0) const
94  { return (T*) GetRawEnqueuePtr(enqueueThresh,chan); }
95 
96  const T* GetDequeuePtr(ulong dequeueThresh, ulong chan=0) const
97  { return (const T*) GetRawDequeuePtr(dequeueThresh,chan); }
98 };
99 
100 #endif
const T * GetDequeuePtr(ulong dequeueThresh, ulong chan=0) const
ThresholdQueue(const ThresholdQueueAttr &attr)
T * GetEnqueuePtr(ulong enqueueThresh, ulong chan=0) const
const void * GetRawDequeuePtr(ulong dequeueThresh, ulong chan=0) const
ThresholdQueue(ulong queueLen, ulong maxThresh, ulong numChans=1)
void * GetRawEnqueuePtr(ulong enqueueThresh, ulong chan=0) const