packages feed

timer-wheel 0.2.0 → 0.2.0.1

raw patch · 4 files changed

+135/−113 lines, 4 filesdep +vectordep −ghc-primdep −primitive

Dependencies added: vector

Dependencies removed: ghc-prim, primitive

Files

.travis.yml view
@@ -1,113 +1,142 @@ # This Travis job script has been generated by a script via #-#   runghc make_travis_yml_2.hs 'timer-wheel.cabal'+#   haskell-ci 'timer-wheel.cabal' # # For more information, see https://github.com/haskell-CI/haskell-ci #+# version: 0.3.20190418+# language: c-sudo: false-+dist: xenial git:-  submodules: false  # whether to recursively clone submodules-+  # whether to recursively clone submodules+  submodules: false cache:   directories:     - $HOME/.cabal/packages     - $HOME/.cabal/store- before_cache:-  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log+  - rm -fv $CABALHOME/packages/hackage.haskell.org/build-reports.log   # remove files that are regenerated by 'cabal update'-  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*-  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json-  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache-  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar-  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx--  - rm -rfv $HOME/.cabal/packages/head.hackage-+  - rm -fv $CABALHOME/packages/hackage.haskell.org/00-index.*+  - rm -fv $CABALHOME/packages/hackage.haskell.org/*.json+  - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.cache+  - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar+  - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar.idx+  - rm -rfv $CABALHOME/packages/head.hackage matrix:   include:-    - compiler: "ghc-8.6.3"-    # env: TEST=--disable-tests BENCH=--disable-benchmarks-      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.3], sources: [hvr-ghc]}}-    - compiler: "ghc-8.4.4"-    # env: TEST=--disable-tests BENCH=--disable-benchmarks-      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}}-    - compiler: "ghc-8.2.2"-    # env: TEST=--disable-tests BENCH=--disable-benchmarks-      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}}-    - compiler: "ghc-8.0.2"-    # env: TEST=--disable-tests BENCH=--disable-benchmarks-      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}}-+    - compiler: ghc-8.6.5+      addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.6.5","cabal-install-2.4"]}}+    - compiler: ghc-8.4.4+      addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.4","cabal-install-2.4"]}}+    - compiler: ghc-8.2.2+      addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.2.2","cabal-install-2.4"]}}+    - compiler: ghc-8.0.2+      addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.0.2","cabal-install-2.4"]}} before_install:-  - HC=${CC}-  - HCPKG=${HC/ghc/ghc-pkg}+  - HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')+  - HCPKG="$HC-pkg"   - unset CC-  - ROOTDIR=$(pwd)-  - mkdir -p $HOME/.local/bin-  - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"+  - CABAL=/opt/ghc/bin/cabal+  - CABALHOME=$HOME/.cabal+  - export PATH="$CABALHOME/bin:$PATH"+  - TOP=$(pwd)   - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))   - echo $HCNUMVER-+  - CABAL="$CABAL -vnormal+nowrap+markoutput"+  - set -o pipefail+  - |+    echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }'           >> .colorful.awk+    echo 'BEGIN { state = "output"; }'                                     >> .colorful.awk+    echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }'            >> .colorful.awk+    echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }'             >> .colorful.awk+    echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk+    echo '  if (state == "cabal") {'                                       >> .colorful.awk+    echo '    print blue($0)'                                              >> .colorful.awk+    echo '  } else {'                                                      >> .colorful.awk+    echo '    print $0'                                                    >> .colorful.awk+    echo '  }'                                                             >> .colorful.awk+    echo '}'                                                               >> .colorful.awk+  - cat .colorful.awk+  - |+    color_cabal_output () {+      awk -f $TOP/.colorful.awk+    }+  - echo text | color_cabal_output install:-  - cabal --version+  - ${CABAL} --version   - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"-  - BENCH=${BENCH---enable-benchmarks}-  - TEST=${TEST---enable-tests}-  - HADDOCK=${HADDOCK-true}-  - UNCONSTRAINED=${UNCONSTRAINED-true}-  - NOINSTALLEDCONSTRAINTS=${NOINSTALLEDCONSTRAINTS-false}+  - TEST=--enable-tests+  - BENCH=--enable-benchmarks   - GHCHEAD=${GHCHEAD-false}-  - travis_retry cabal update -v-  - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"-  - rm -fv cabal.project cabal.project.local-  - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'-  - "printf 'packages: \".\"\\n' > cabal.project"-  - "printf 'write-ghc-environment-files: always\\n' >> cabal.project"-  - touch cabal.project.local-  - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg  | grep -vw -- timer-wheel | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+  - rm -f $CABALHOME/config+  - |+    echo "verbose: normal +nowrap +markoutput"          >> $CABALHOME/config+    echo "remote-build-reporting: anonymous"            >> $CABALHOME/config+    echo "remote-repo-cache: $CABALHOME/packages"       >> $CABALHOME/config+    echo "logs-dir:          $CABALHOME/logs"           >> $CABALHOME/config+    echo "world-file:        $CABALHOME/world"          >> $CABALHOME/config+    echo "extra-prog-path:   $CABALHOME/bin"            >> $CABALHOME/config+    echo "symlink-bindir:    $CABALHOME/bin"            >> $CABALHOME/config+    echo "build-summary:     $CABALHOME/logs/build.log" >> $CABALHOME/config+    echo "store-dir:         $CABALHOME/store"          >> $CABALHOME/config+    echo "install-dirs user"                            >> $CABALHOME/config+    echo "  prefix: $CABALHOME"                         >> $CABALHOME/config+    echo "repository hackage.haskell.org"               >> $CABALHOME/config+    echo "  url: http://hackage.haskell.org/"           >> $CABALHOME/config+  - cat $CABALHOME/config+  - rm -fv cabal.project cabal.project.local cabal.project.freeze+  - travis_retry ${CABAL} v2-update -v+  # Generate cabal.project+  - rm -rf cabal.project cabal.project.local cabal.project.freeze+  - touch cabal.project+  - |+    echo 'packages: "."' >> cabal.project+  - |+    echo "write-ghc-environment-files: always" >> cabal.project+  - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(timer-wheel)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"   - cat cabal.project || true   - cat cabal.project.local || true-  - if [ -f "./configure.ac" ]; then-      (cd "." && autoreconf -i);-    fi-  - rm -f cabal.project.freeze-  - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all-  - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all-  - rm -rf .ghc.environment.* "."/dist-  - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)--# Here starts the actual work to be performed for the package under test;-# any command which exits with a non-zero exit code causes the build to fail.+  - if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi+  - ${CABAL} v2-freeze -w ${HC} ${TEST} ${BENCH} | color_cabal_output+  - "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"+  - rm  cabal.project.freeze+  - ${CABAL} v2-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all | color_cabal_output+  - ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all | color_cabal_output script:-  # test that source-distributions can be generated-  - cabal new-sdist all+  - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)+  # Packaging...+  - ${CABAL} v2-sdist all | color_cabal_output+  # Unpacking...   - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/   - cd ${DISTDIR} || false   - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;-  - "printf 'packages: timer-wheel-*/*.cabal\\n' > cabal.project"-  - "printf 'write-ghc-environment-files: always\\n' >> cabal.project"-  - touch cabal.project.local-  - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg  | grep -vw -- timer-wheel | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+  # Generate cabal.project+  - rm -rf cabal.project cabal.project.local cabal.project.freeze+  - touch cabal.project+  - |+    echo 'packages: "timer-wheel-*/*.cabal"' >> cabal.project+  - |+    echo "write-ghc-environment-files: always" >> cabal.project+  - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(timer-wheel)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"   - cat cabal.project || true   - cat cabal.project.local || true+  # Building...   # this builds all libraries and executables (without tests/benchmarks)-  - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all-+  - ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks all | color_cabal_output+  # Building with tests and benchmarks...   # build & run tests, build benchmarks-  - cabal new-build -w ${HC} ${TEST} ${BENCH} all-  - if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi--  # cabal check-  - (cd timer-wheel-* && cabal check)--  # haddock-  - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi--  # Build without installed constraints for packages in global-db-  - if $UNCONSTRAINED; then rm -f cabal.project.local; echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi+  - ${CABAL} v2-build -w ${HC} ${TEST} ${BENCH} all | color_cabal_output+  # Testing...+  - ${CABAL} v2-test -w ${HC} ${TEST} ${BENCH} all | color_cabal_output+  # cabal check...+  - (cd timer-wheel-* && ${CABAL} -vnormal check)+  # haddock...+  - ${CABAL} v2-haddock -w ${HC} ${TEST} ${BENCH} all | color_cabal_output+  # Building without installed constraints for packages in global-db...+  - rm -f cabal.project.local+  - ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks all | color_cabal_output  # REGENDATA ["timer-wheel.cabal"] # EOF
CHANGELOG.md view
@@ -5,7 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). -## Unreleased+## [0.2.0.1] - 2019-05-19++### Changed+- Swapped out `ghc-prim` and `primitive` for `vector`++## [0.2.0] - 2019-02-03+ ### Added - `destroy` function, for reaping the background thread - `recurring_` function
src/Wheel.hs view
@@ -12,18 +12,13 @@  import qualified Entries as Entries -import Control.Concurrent           (threadDelay)+import Control.Concurrent      (threadDelay) import Control.Concurrent.MVar-import Control.Monad                (join, when)-import Data.Foldable                (for_)-import Data.Primitive.MutVar        (MutVar, atomicModifyMutVar', newMutVar)-import Data.Primitive.UnliftedArray (MutableUnliftedArray, UnliftedArray,-                                     freezeUnliftedArray, indexUnliftedArray,-                                     sizeofUnliftedArray,-                                     unsafeNewUnliftedArray, writeUnliftedArray)-import Data.Word                    (Word64)-import GHC.Prim                     (RealWorld)-import System.IO.Unsafe             (unsafeInterleaveIO)+import Control.Monad           (join, when)+import Data.IORef+import Data.Vector             (Vector)+import Data.Word               (Word64)+import System.IO.Unsafe        (unsafeInterleaveIO)  #if MIN_VERSION_base(4,11,0) import GHC.Clock (getMonotonicTimeNSec)@@ -31,14 +26,13 @@ import System.Clock (Clock(Monotonic), getTime, toNanoSecs) #endif +import qualified Data.Vector as Vector  -type IORef-  = MutVar RealWorld  data Wheel   = Wheel-  { buckets :: !(UnliftedArray (IORef Entries))+  { buckets :: !(Vector (IORef Entries))   , resolution :: !Word64 -- micros   } @@ -47,14 +41,8 @@   -> Word64   -> IO Wheel create spokes resolution = do-  mbuckets :: MutableUnliftedArray RealWorld (IORef Entries) <--    unsafeNewUnliftedArray spokes--  for_ [0 .. spokes-1] $ \i ->-    writeUnliftedArray mbuckets i =<< newMutVar Entries.empty--  buckets :: UnliftedArray (IORef Entries) <--    freezeUnliftedArray mbuckets 0 spokes+  buckets :: Vector (IORef Entries) <-+    Vector.replicateM spokes (newIORef Entries.empty)    pure Wheel     { buckets = buckets@@ -63,7 +51,7 @@  numSpokes :: Wheel -> Int numSpokes wheel =-  sizeofUnliftedArray (buckets wheel)+  Vector.length (buckets wheel)  lenMicros :: Wheel -> Word64 lenMicros wheel =@@ -71,7 +59,7 @@  bucket :: Wheel -> Word64 -> IORef Entries bucket wheel time =-  indexUnliftedArray+  Vector.unsafeIndex     (buckets wheel)     (index wheel time) @@ -100,11 +88,11 @@       delay `div` lenMicros wheel    let-    bucketVar :: MutVar RealWorld Entries-    bucketVar =+    bucketRef :: IORef Entries+    bucketRef =       bucket wheel time -  atomicModifyMutVar' bucketVar+  atomicModifyIORef' bucketRef     (\entries ->       (Entries.insert key count action entries, ())) @@ -115,7 +103,7 @@     modifyMVar canceledVar $ \result -> do       canceled <-         maybe-          (atomicModifyMutVar' bucketVar+          (atomicModifyIORef' bucketRef             (\entries ->               maybe                 (entries, False)@@ -152,7 +140,7 @@     loop :: Word64 -> Int -> IO ()     loop nextTime i = do       join-        (atomicModifyMutVar' (indexUnliftedArray buckets i)+        (atomicModifyIORef' (Vector.unsafeIndex buckets i)           (\entries ->             if Entries.null entries               then
timer-wheel.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.0  name: timer-wheel-version: 0.2.0+version: 0.2.0.1 category: Data description:   This library provides a timer wheel data structure for@@ -31,7 +31,7 @@     GHC == 8.0.2   , GHC == 8.2.2   , GHC == 8.4.4-  , GHC == 8.6.3+  , GHC == 8.6.5  extra-source-files:   .travis.yml@@ -45,9 +45,8 @@   build-depends:     atomic-primops ^>= 0.8,     base ^>= 4.9 || ^>= 4.10 || ^>= 4.11 || ^>= 4.12,-    ghc-prim ^>= 0.5,-    primitive ^>= 0.6,-    psqueues ^>= 0.2.7+    psqueues ^>= 0.2.7,+    vector ^>= 0.10 || ^>= 0.11 || ^>= 0.12   if !impl(ghc >= 8.4)     build-depends:       clock ^>= 0.7