-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `AsymmetricSemaphore`, `tag_waiter` field for register, and `onchange_tag` function * Add waiting mechanism on protocols * Add tests --------- Co-authored-by: Stefan Krastanov <[email protected]>
- Loading branch information
Showing
13 changed files
with
305 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using ConcurrentSim | ||
using ResumableFunctions | ||
import Base: unlock, lock, islocked | ||
|
||
"""Multiple processes can wait on this semaphore for a permission to run given by another process""" | ||
struct AsymmetricSemaphore | ||
nbwaiters::Ref{Int} | ||
lock::Resource | ||
end | ||
AsymmetricSemaphore(sim) = AsymmetricSemaphore(Ref(0), Resource(sim,1,level=1)) # start locked | ||
|
||
function Base.lock(s::AsymmetricSemaphore) | ||
return @process _lock(s.lock.env, s) | ||
end | ||
|
||
@resumable function _lock(sim, s::AsymmetricSemaphore) | ||
s.nbwaiters[] += 1 | ||
@yield lock(s.lock) | ||
s.nbwaiters[] -= 1 | ||
if s.nbwaiters[] > 0 | ||
unlock(s.lock) | ||
end | ||
end | ||
|
||
function unlock(s::AsymmetricSemaphore) | ||
if s.nbwaiters[] > 0 | ||
unlock(s.lock) | ||
end | ||
end | ||
|
||
function islocked(s::AsymmetricSemaphore) | ||
return islocked(s.lock) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.