<commit_before>module Network.HTTP2.Priority.Queue (
    Entry
  , Q.newEntry
  , Q.renewEntry
  , Q.item
  , TPriorityQueue
  , new
  , isEmpty
  , enqueue
  , dequeue
  ) where

import Control.Concurrent.STM
import Network.HTTP2.Priority.Heap (PriorityQueue, Entry)
import qualified Network.HTTP2.Priority.Heap as Q

----------------------------------------------------------------

newtype TPriorityQueue a = TPriorityQueue (TVar (PriorityQueue a))

new :: STM (TPriorityQueue a)
new = TPriorityQueue <$> newTVar Q.empty

isEmpty :: TPriorityQueue a -> STM Bool
isEmpty (TPriorityQueue th) = Q.isEmpty <$> readTVar th

enqueue :: TPriorityQueue a -> Entry a -> STM ()
enqueue (TPriorityQueue th) ent = modifyTVar' th $ Q.enqueue ent

dequeue :: TPriorityQueue a -> STM (Entry a)
dequeue (TPriorityQueue th) = do
  h <- readTVar th
  case Q.dequeue h of
    Nothing -> retry
    Just (ent, h') -> do
      writeTVar th h'
      return ent
<commit_msg>rescuing GHC 7.8.<commit_after>module Network.HTTP2.Priority.Queue (
    Entry
  , Q.newEntry
  , Q.renewEntry
  , Q.item
  , TPriorityQueue
  , new
  , isEmpty
  , enqueue
  , dequeue
  ) where

#if __GLASGOW_HASKELL__ < 709
import Control.Applicative ((<$>))
#endif
import Control.Concurrent.STM
import Network.HTTP2.Priority.Heap (PriorityQueue, Entry)
import qualified Network.HTTP2.Priority.Heap as Q

----------------------------------------------------------------

newtype TPriorityQueue a = TPriorityQueue (TVar (PriorityQueue a))

new :: STM (TPriorityQueue a)
new = TPriorityQueue <$> newTVar Q.empty

isEmpty :: TPriorityQueue a -> STM Bool
isEmpty (TPriorityQueue th) = Q.isEmpty <$> readTVar th

enqueue :: TPriorityQueue a -> Entry a -> STM ()
enqueue (TPriorityQueue th) ent = modifyTVar' th $ Q.enqueue ent

dequeue :: TPriorityQueue a -> STM (Entry a)
dequeue (TPriorityQueue th) = do
  h <- readTVar th
  case Q.dequeue h of
    Nothing -> retry
    Just (ent, h') -> do
      writeTVar th h'
      return ent

{'fraction_non_alphanumeric': 0.16195761856710394, 'fraction_numerical': 0.005549949545913219, 'mean_word_length': 2.658671586715867, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2738719', 'n_tokens_mistral': 646, 'n_tokens_neox': 640, 'n_words': 190}