forked from racket/racket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cs, thread & io: finish implementing places
Implement place channels and messages, and change `place-enabled?` to claim that places are enabled, but `processor-count` still reports 1. The implementation of place channels has an interesting use of ephemerons --- that is, a use that isn't just solving a key-in-value problem. Using epehemerons solves the problem of forgetting a place channel and any thread blocked on the read end when there are no producers on the write end. Along similar lines, when only the write end is retained (i.e., no readers), the channel data is forgotten and writes become a no-op. The read end holds a "read key" and references the channel data through an ephemeron keyed by a "write key"; the write end similarly holds a "write key" and uses an ephemeron keyed by the "read key". This use of an epehemeron implements a reachability "and": retain the place-channel data only if the read end *and* the write end are both reachable. (Minor point: a read end also holds onto the "write key" anytime the channel already has data.)
- Loading branch information
Showing
27 changed files
with
773 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#lang racket/base | ||
|
||
(provide immutable-prefab-struct-key | ||
prefab-key-all-fields-immutable?) | ||
|
||
(define (immutable-prefab-struct-key v) | ||
(define k (prefab-struct-key v)) | ||
(and k | ||
(all-fields-immutable? k) | ||
k)) | ||
|
||
(define (prefab-key-all-fields-immutable? k) | ||
(unless (prefab-key? k) | ||
(raise-argument-error 'prefab-key-all-fields-immutable? "prefab-key?" k)) | ||
(all-fields-immutable? k)) | ||
|
||
(define (all-fields-immutable? k) | ||
(or (symbol? k) | ||
(null? k) | ||
(let* ([rk (cdr k)] ; skip name | ||
[rk (if (and (pair? rk) | ||
(exact-integer? (car rk))) | ||
(cdr rk) ; skip init count | ||
rk)] | ||
[rk (if (and (pair? rk) | ||
(pair? (car rk))) | ||
(if (zero? (caar rk)) | ||
(cdr rk) ; skip zero auto count | ||
(cons '#(1) (cdr rk))) ; reflect mutable auto field | ||
rk)]) | ||
(if (and (pair? rk) | ||
(vector? (car rk))) | ||
(if (zero? (vector-length (car rk))) | ||
(all-fields-immutable? (cdr rk)) | ||
#f) | ||
(all-fields-immutable? rk))))) |
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 |
---|---|---|
@@ -1,31 +1,8 @@ | ||
#lang racket/base | ||
(require racket/prefab) | ||
|
||
(provide immutable-prefab-struct-key | ||
all-fields-immutable?) | ||
|
||
(define (immutable-prefab-struct-key v) | ||
(define k (prefab-struct-key v)) | ||
(and k | ||
(all-fields-immutable? k) | ||
k)) | ||
|
||
(define (all-fields-immutable? k) | ||
(or (symbol? k) | ||
(null? k) | ||
(let* ([rk (cdr k)] ; skip name | ||
[rk (if (and (pair? rk) | ||
(exact-integer? (car rk))) | ||
(cdr rk) ; skip init count | ||
rk)] | ||
[rk (if (and (pair? rk) | ||
(pair? (car rk))) | ||
(if (zero? (caar rk)) | ||
(cdr rk) ; skip zero auto count | ||
(cons '#(1) (cdr rk))) ; reflect mutable auto field | ||
rk)]) | ||
(if (and (pair? rk) | ||
(vector? (car rk))) | ||
(if (zero? (vector-length (car rk))) | ||
(all-fields-immutable? (cdr rk)) | ||
#f) | ||
(all-fields-immutable? rk))))) | ||
(prefab-key-all-fields-immutable? k)) |
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
Oops, something went wrong.