summaryrefslogtreecommitdiff
path: root/src/Data/PacketQueue.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/PacketQueue.hs')
-rw-r--r--src/Data/PacketQueue.hs24
1 files changed, 2 insertions, 22 deletions
diff --git a/src/Data/PacketQueue.hs b/src/Data/PacketQueue.hs
index f1be1375..23db0ee0 100644
--- a/src/Data/PacketQueue.hs
+++ b/src/Data/PacketQueue.hs
@@ -8,7 +8,6 @@ module Data.PacketQueue
8 ( PacketQueue 8 ( PacketQueue
9 , getCapacity 9 , getCapacity
10 , new 10 , new
11 , newOverwrite
12 , dequeue 11 , dequeue
13 , getMissing 12 , getMissing
14 , dequeueOrGetMissing 13 , dequeueOrGetMissing
@@ -41,7 +40,6 @@ data PacketQueue a = PacketQueue
41 , seqno :: TVar Word32 -- (buffer_start) 40 , seqno :: TVar Word32 -- (buffer_start)
42 , qsize :: Word32 41 , qsize :: Word32
43 , buffend :: TVar Word32 -- on incoming, next packet they'll send + 1 42 , buffend :: TVar Word32 -- on incoming, next packet they'll send + 1
44 , qOverWriteMode :: Bool -- TODO: Remove me, use Data.CyclicBuffer instead.
45 } 43 }
46 44
47packetQueueViewList :: PacketQueue a -> STM [(Word32,a)] 45packetQueueViewList :: PacketQueue a -> STM [(Word32,a)]
@@ -67,24 +65,6 @@ new capacity seqstart = do
67 , seqno = seqv 65 , seqno = seqv
68 , qsize = cap 66 , qsize = cap
69 , buffend = bufe 67 , buffend = bufe
70 , qOverWriteMode = False
71 }
72
73-- | Create a new PacketQueue with Overwrite on Wrap.
74newOverwrite :: Word32 -- ^ Capacity of queue.
75 -> Word32 -- ^ Initial sequence number.
76 -> STM (PacketQueue a)
77newOverwrite capacity seqstart = do
78 let cap = if capacity `mod` 2 == 0 then capacity else capacity + 1
79 q <- newArray (0,cap - 1) Nothing
80 seqv <- newTVar seqstart
81 bufe <- newTVar 0
82 return PacketQueue
83 { pktq = q
84 , seqno = seqv
85 , qsize = cap
86 , buffend = bufe
87 , qOverWriteMode = True
88 } 68 }
89 69
90-- | Update the packet queue given: 70-- | Update the packet queue given:
@@ -158,11 +138,11 @@ enqueue :: PacketQueue a -- ^ The packet queue.
158 -> Word32 -- ^ Sequence number of the packet. 138 -> Word32 -- ^ Sequence number of the packet.
159 -> a -- ^ The packet. 139 -> a -- ^ The packet.
160 -> STM (Word32,Word32) 140 -> STM (Word32,Word32)
161enqueue PacketQueue{ pktq, seqno, qsize, buffend,qOverWriteMode } no x = do 141enqueue PacketQueue{ pktq, seqno, qsize, buffend} no x = do
162 low <- readTVar seqno 142 low <- readTVar seqno
163 let proj = no - low 143 let proj = no - low
164 -- Ignore packet if out of range. 144 -- Ignore packet if out of range.
165 when ( proj < qsize || qOverWriteMode) $ do 145 when ( proj < qsize) $ do
166 let i = no `mod` qsize 146 let i = no `mod` qsize
167 writeArray pktq i (Just x) 147 writeArray pktq i (Just x)
168 modifyTVar' buffend (\be -> if be - low <= proj then no + 1 else be) 148 modifyTVar' buffend (\be -> if be - low <= proj then no + 1 else be)