Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
stm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
stm
Commits
e10e9752
Commit
e10e9752
authored
4 years ago
by
David Feuer
Committed by
konsumlamm
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add MArray TArray e IO instance
Closes #35
parent
98215788
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Control/Concurrent/STM/TArray.hs
+15
-7
15 additions, 7 deletions
Control/Concurrent/STM/TArray.hs
with
15 additions
and
7 deletions
Control/Concurrent/STM/TArray.hs
+
15
−
7
View file @
e10e9752
...
@@ -23,15 +23,16 @@ module Control.Concurrent.STM.TArray (
...
@@ -23,15 +23,16 @@ module Control.Concurrent.STM.TArray (
)
where
)
where
import
Data.Array
(
Array
,
bounds
)
import
Data.Array
(
Array
,
bounds
)
import
Data.Array.Base
(
listArray
,
arrEleBottom
,
unsafeAt
,
MArray
(
..
),
import
Data.Array.Base
(
listArray
,
unsafeAt
,
MArray
(
..
),
IArray
(
numElements
))
IArray
(
numElements
))
import
Data.Ix
(
rangeSize
)
import
Data.Ix
(
rangeSize
)
import
Data.Typeable
(
Typeable
)
import
Data.Typeable
(
Typeable
)
import
Control.Concurrent.STM.TVar
(
TVar
,
newTVar
,
readTVar
,
writeTVar
)
import
Control.Concurrent.STM.TVar
(
TVar
,
newTVar
,
readTVar
,
writeTVar
,
newTVarIO
,
readTVarIO
)
#
ifdef
__GLASGOW_HASKELL__
#
ifdef
__GLASGOW_HASKELL__
import
GHC.Conc
(
STM
)
import
GHC.Conc
(
STM
,
atomically
)
#
else
#
else
import
Control.Sequential.STM
(
STM
)
import
Control.Sequential.STM
(
STM
,
atomically
)
#
endif
#
endif
-- |TArray is a transactional array, supporting the usual 'MArray'
-- |TArray is a transactional array, supporting the usual 'MArray'
...
@@ -48,13 +49,20 @@ instance MArray TArray e STM where
...
@@ -48,13 +49,20 @@ instance MArray TArray e STM where
newArray
b
e
=
do
newArray
b
e
=
do
a
<-
rep
(
rangeSize
b
)
(
newTVar
e
)
a
<-
rep
(
rangeSize
b
)
(
newTVar
e
)
return
$
TArray
(
listArray
b
a
)
return
$
TArray
(
listArray
b
a
)
newArray_
b
=
do
a
<-
rep
(
rangeSize
b
)
(
newTVar
arrEleBottom
)
return
$
TArray
(
listArray
b
a
)
unsafeRead
(
TArray
a
)
i
=
readTVar
$
unsafeAt
a
i
unsafeRead
(
TArray
a
)
i
=
readTVar
$
unsafeAt
a
i
unsafeWrite
(
TArray
a
)
i
e
=
writeTVar
(
unsafeAt
a
i
)
e
unsafeWrite
(
TArray
a
)
i
e
=
writeTVar
(
unsafeAt
a
i
)
e
getNumElements
(
TArray
a
)
=
return
(
numElements
a
)
getNumElements
(
TArray
a
)
=
return
(
numElements
a
)
-- | Writes are slow in `IO`.
instance
MArray
TArray
e
IO
where
getBounds
(
TArray
a
)
=
return
(
bounds
a
)
newArray
b
e
=
do
a
<-
rep
(
rangeSize
b
)
(
newTVarIO
e
)
return
$
TArray
(
listArray
b
a
)
unsafeRead
(
TArray
a
)
i
=
readTVarIO
$
unsafeAt
a
i
unsafeWrite
(
TArray
a
)
i
e
=
atomically
$
writeTVar
(
unsafeAt
a
i
)
e
getNumElements
(
TArray
a
)
=
return
(
numElements
a
)
-- | Like 'replicateM' but uses an accumulator to prevent stack overflows.
-- | Like 'replicateM' but uses an accumulator to prevent stack overflows.
-- Unlike 'replicateM' the returned list is in reversed order.
-- Unlike 'replicateM' the returned list is in reversed order.
-- This doesn't matter though since this function is only used to create
-- This doesn't matter though since this function is only used to create
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment