From 21f71092047f4af1c53007d08b3c193573031f92 Mon Sep 17 00:00:00 2001 From: Kevin Tew Date: Thu, 9 Jun 2011 23:24:58 -0600 Subject: [PATCH] Places: rename send receive to put get --- collects/racket/place.rkt | 26 ++--- collects/scribblings/reference/places.scrbl | 18 ++-- .../benchmarks/places/place-channel.rktl | 22 ++--- .../benchmarks/places/place-launch.rktl | 16 ++-- .../benchmarks/places/place-processes.rkt | 22 ++--- .../racket/benchmarks/places/place-utils.rkt | 8 +- .../racket/benchmarks/places/symbols.rktl | 4 +- collects/tests/racket/place-channel.rkt | 96 +++++++++---------- collects/tests/racket/place.rktl | 8 +- src/racket/src/place.c | 4 +- 10 files changed, 112 insertions(+), 112 deletions(-) diff --git a/collects/racket/place.rkt b/collects/racket/place.rkt index d769b9bdaa..29a7ec2f28 100644 --- a/collects/racket/place.rkt +++ b/collects/racket/place.rkt @@ -17,11 +17,11 @@ place-kill place-break place-channel - place-channel-send - place-channel-receive + place-channel-put + place-channel-get place-channel? place? - place-channel-send/receive + place-channel-put/get processor-count place/anon place/thunk @@ -31,9 +31,9 @@ (define-struct TH-place (th ch cust) #:property prop:evt (lambda (x) (TH-place-channel-in (TH-place-ch x)))) -(define (place-channel-send/receive ch msg) - (place-channel-send ch msg) - (place-channel-receive ch)) +(define (place-channel-put/get ch msg) + (place-channel-put ch msg) + (place-channel-get ch)) (define (make-th-async-channel) (define ch (make-channel)) @@ -95,25 +95,25 @@ (apply make-prefab-struct key (map dcw (cdr (vector->list (struct->vector o)))))] - [else (raise-mismatch-error 'place-channel-send "cannot transmit a message containing value: " o)])) + [else (raise-mismatch-error 'place-channel-put "cannot transmit a message containing value: " o)])) (dcw x)) -(define (th-place-channel-send pl msg) +(define (th-place-channel-put pl msg) (define th (cond [(TH-place? pl) (TH-place-channel-out (TH-place-ch pl))] [(TH-place-channel? pl) (TH-place-channel-out pl)] - [else (raise-type-error 'place-channel-send "expect a place? or place-channel?" pl)])) + [else (raise-type-error 'place-channel-put "expect a place? or place-channel?" pl)])) (void (thread-send th (deep-copy msg) #f))) -(define (th-place-channel-receive pl) +(define (th-place-channel-get pl) (channel-get (cond [(TH-place? pl) (TH-place-channel-in (TH-place-ch pl))] [(TH-place-channel? pl) (TH-place-channel-in pl)] - [else (raise-type-error 'place-channel-receive "expect a place? or place-channel?" pl)]))) + [else (raise-type-error 'place-channel-get "expect a place? or place-channel?" pl)]))) (define (th-place-channel? pl) (or (TH-place? pl) @@ -127,8 +127,8 @@ (define-pl place-kill pl-place-kill th-place-kill) (define-pl place-break pl-place-break th-place-break) (define-pl place-channel pl-place-channel th-place-channel) -(define-pl place-channel-send pl-place-channel-send th-place-channel-send) -(define-pl place-channel-receive pl-place-channel-receive th-place-channel-receive) +(define-pl place-channel-put pl-place-channel-put th-place-channel-put) +(define-pl place-channel-get pl-place-channel-get th-place-channel-get) (define-pl place-channel? pl-place-channel? th-place-channel?) (define-pl place? pl-place? TH-place?) diff --git a/collects/scribblings/reference/places.scrbl b/collects/scribblings/reference/places.scrbl index 6cf2d3cf4b..a0f19c5c2b 100644 --- a/collects/scribblings/reference/places.scrbl +++ b/collects/scribblings/reference/places.scrbl @@ -50,8 +50,8 @@ places that share the value, because they are allowed in a A @tech{place channel} can be used as a @tech{synchronizable event} (see @secref["sync"]) to receive a value through the channel. A place -can also receive messages with @racket[place-channel-receive], and -messages can be sent with @racket[place-channel-send]. +can also receive messages with @racket[place-channel-get], and +messages can be sent with @racket[place-channel-put]. Constraints on messages across a place channel---and therefore on the kinds of data that places share---enable greater parallelism than @@ -67,8 +67,8 @@ message to each, and then waits for the places to complete and return: (place "place-worker.rkt" 'place-main))]) (for ([i (in-range 2)] [p pls]) - (place-channel-send p i) - (printf "~a\n" (place-channel-receive p))) + (place-channel-put p i) + (printf "~a\n" (place-channel-get p))) (map place-wait pls)) ] @@ -82,8 +82,8 @@ racket (provide place-main) (define (place-main pch) - (place-channel-send pch (format "Hello from place ~a" - (place-channel-receive pch)))) + (place-channel-put pch (format "Hello from place ~a" + (place-channel-get pch)))) ] @@ -158,15 +158,15 @@ racket channel}). } -@defproc[(place-channel-send [pch place-channel?] [v any/c]) void]{ +@defproc[(place-channel-put [pch place-channel?] [v any/c]) void]{ Sends an immutable message @racket[v] on channel @racket[pch]. } -@defproc[(place-channel-receive [pch place-channel?]) any/c]{ +@defproc[(place-channel-get [pch place-channel?]) any/c]{ Returns an immutable message received on channel @racket[pch]. } -@defproc[(place-channel-send/receive [pch place-channel?] [v any/c]) void]{ +@defproc[(place-channel-put/get [pch place-channel?] [v any/c]) void]{ Sends an immutable message @racket[v] on channel @racket[pch] and then waits for a reply message on the same channel. } diff --git a/collects/tests/racket/benchmarks/places/place-channel.rktl b/collects/tests/racket/benchmarks/places/place-channel.rktl index cd77be6413..710936e441 100644 --- a/collects/tests/racket/benchmarks/places/place-channel.rktl +++ b/collects/tests/racket/benchmarks/places/place-channel.rktl @@ -22,8 +22,8 @@ (define count 10) (define fourk-b-message (make-bytes message-size 66)) (for ([i (in-range count)]) - (place-channel-receive ch) - (place-channel-send ch fourk-b-message)))]) + (place-channel-get ch) + (place-channel-put ch fourk-b-message)))]) (define message-size (* 4024 1024)) (define four-k-message (make-bytes message-size 65)) @@ -31,8 +31,8 @@ (define-values (r t1 t2 t3) (time-apply (lambda () (for ([i (in-range count)]) - (pp:place-channel-send pl four-k-message) - (pp:place-channel-receive pl))) null)) + (pp:place-channel-put pl four-k-message) + (pp:place-channel-get pl))) null)) (print-out "processes-emulated-places" (/ (* 2 count message-size) (/ t2 1000))) @@ -51,8 +51,8 @@ (define count 150) (define fourk-b-message (make-bytes message-size 66)) (for ([i (in-range count)]) - (place-channel-receive ch) - (place-channel-send ch fourk-b-message))) + (place-channel-get ch) + (place-channel-put ch fourk-b-message))) ) END "pct1.ss") @@ -64,8 +64,8 @@ END (define-values (r t1 t2 t3) (time-apply (lambda () (for ([i (in-range count)]) - (place-channel-send pl four-k-message) - (place-channel-receive pl))) null)) + (place-channel-put pl four-k-message) + (place-channel-get pl))) null)) (print-out "places" (/ (* 2 count message-size) (/ t2 1000))) @@ -81,7 +81,7 @@ END (define (place-main ch) (define count 500) (for ([i (in-range count)]) - (place-channel-send ch (place-channel-receive ch)))) + (place-channel-put ch (place-channel-get ch)))) ) END "pct1.ss") @@ -95,8 +95,8 @@ END (define-values (r t1 t2 t3) (time-apply (lambda () (for ([i (in-range count)]) - (place-channel-send pl tree) - (place-channel-receive pl))) null)) + (place-channel-put pl tree) + (place-channel-get pl))) null)) (define s (* (- (expt 2 9) 1) 4 8 count)) (printf "cons-tree ~a ~a ~a ~a\n" t1 t2 t3 (exact->inexact (/ t2 1000))) diff --git a/collects/tests/racket/benchmarks/places/place-launch.rktl b/collects/tests/racket/benchmarks/places/place-launch.rktl index 10cfca7b0f..d4c9a6666a 100644 --- a/collects/tests/racket/benchmarks/places/place-launch.rktl +++ b/collects/tests/racket/benchmarks/places/place-launch.rktl @@ -12,11 +12,11 @@ (provide place-main) (define (barrier ch) - (place-channel-send ch 0) - (place-channel-receive ch)) + (place-channel-put ch 0) + (place-channel-get ch)) (define (place-main ch) - (place-channel-send ch 2) + (place-channel-put ch 2) (barrier ch)) ) END @@ -28,11 +28,11 @@ END (provide place-main) (define (barrier ch) - (place-channel-send ch 0) - (place-channel-receive ch)) + (place-channel-put ch 0) + (place-channel-get ch)) (define (place-main ch) - (place-channel-send ch 2) + (place-channel-put ch 2) (barrier ch)) ) END @@ -49,7 +49,7 @@ END (let ([pls (time-n msg 0 (for/list ([i (in-range plcnt)]) (let ([p (place module-path 'place-main)]) - (place-channel-receive p) + (place-channel-get p) p)))]) (barrier-m pls) (places-wait pls)) @@ -58,7 +58,7 @@ END (let ([pls (time-n msg 1 (let ([pls (for/list ([i (in-range plcnt)]) (place module-path 'place-main))]) - (map place-channel-receive pls) pls))]) + (map place-channel-get pls) pls))]) (barrier-m pls) (places-wait pls))) diff --git a/collects/tests/racket/benchmarks/places/place-processes.rkt b/collects/tests/racket/benchmarks/places/place-processes.rkt index 2719aa79e1..672f471b2c 100644 --- a/collects/tests/racket/benchmarks/places/place-processes.rkt +++ b/collects/tests/racket/benchmarks/places/place-processes.rkt @@ -15,9 +15,9 @@ place place-wait place-kill - place-channel-receive - place-channel-send - place-channel-send/receive + place-channel-get + place-channel-put + place-channel-put/get place-child-channel place/base map-reduce/lambda @@ -35,13 +35,13 @@ (define (place-child-channel) (make-place-channel-s (current-input-port) (current-output-port))) ;; send x on channel ch -(define (place-channel-send ch x) +(define (place-channel-put ch x) (define out (place-channel-s-out (resolve->channel ch))) (write (s-exp->fasl (serialize x)) out) (flush-output out)) ;; receives msg on channel ch -(define (place-channel-receive ch) +(define (place-channel-get ch) (deserialize (fasl->s-exp (read (place-channel-s-in (resolve->channel ch)))))) ;; create a place given a module file path and a func-name to invoke @@ -78,9 +78,9 @@ (subprocess-wait spo) (subprocess-status spo))) -(define (place-channel-send/receive ch x) - (place-channel-send ch x) - (place-channel-receive ch)) +(define (place-channel-put/get ch x) + (place-channel-put ch x) + (place-channel-get ch)) ;; splits lst into n equal pieces (define (split-n n lst) @@ -166,12 +166,12 @@ #'(begin (define places (for/list ([i (in-range (processor-count))]) (place/lambda (name ch) - (place-channel-send ch ((lambda (listvar) body ...) (place-channel-receive ch)))))) + (place-channel-put ch ((lambda (listvar) body ...) (place-channel-get ch)))))) (for ([p places] [item (split-n (processor-count) lst)]) - (place-channel-send p item)) - (define result ((lambda (listvar) body ...) (map place-channel-receive places))) + (place-channel-put p item)) + (define result ((lambda (listvar) body ...) (map place-channel-get places))) (map place-wait places) (map place-kill places) result)])) diff --git a/collects/tests/racket/benchmarks/places/place-utils.rkt b/collects/tests/racket/benchmarks/places/place-utils.rkt index 4b9deef498..9476903483 100644 --- a/collects/tests/racket/benchmarks/places/place-utils.rkt +++ b/collects/tests/racket/benchmarks/places/place-utils.rkt @@ -24,12 +24,12 @@ fn) (define (barrier-m pls) - (for ([ch pls]) (place-channel-receive ch)) - (for ([ch pls]) (place-channel-send ch 1))) + (for ([ch pls]) (place-channel-get ch)) + (for ([ch pls]) (place-channel-put ch 1))) (define (barrier ch) - (place-channel-send ch 0) - (place-channel-receive ch)) + (place-channel-put ch 0) + (place-channel-get ch)) (define (places-wait pls) (for ([p pls]) (place-wait p))) diff --git a/collects/tests/racket/benchmarks/places/symbols.rktl b/collects/tests/racket/benchmarks/places/symbols.rktl index d7f8ccaf44..2b19d6f62c 100644 --- a/collects/tests/racket/benchmarks/places/symbols.rktl +++ b/collects/tests/racket/benchmarks/places/symbols.rktl @@ -14,7 +14,7 @@ (provide place-main) (define (place-main ch) - (match (place-channel-receive ch) + (match (place-channel-get ch) [(list id reps cnt) (define ids (number->string id)) (for ([j (in-range reps)]) @@ -37,7 +37,7 @@ END (for ([i (in-range plcnt)] [pl pls]) - (place-channel-send pl (list i reps symcnt))) + (place-channel-put pl (list i reps symcnt))) (for ([j (in-range reps)]) (time-n "1million-symbols" j (barrier-m pls) diff --git a/collects/tests/racket/place-channel.rkt b/collects/tests/racket/place-channel.rkt index 226ff6fdb9..53e7fec47d 100644 --- a/collects/tests/racket/place-channel.rkt +++ b/collects/tests/racket/place-channel.rkt @@ -15,19 +15,19 @@ (define big (make-string 1025 #\K)) -(define (big-sender ch msg) (car (place-channel-send/receive ch (cons msg big)))) +(define (big-sender ch msg) (car (place-channel-put/get ch (cons msg big)))) (define-syntax (normal-receiver stx) (syntax-case stx () [(_ ch x body ...) - #'(let ([x (place-channel-receive ch)]) - (place-channel-send ch (begin body ...)))])) + #'(let ([x (place-channel-get ch)]) + (place-channel-put ch (begin body ...)))])) (define-syntax (big-receiver stx) (syntax-case stx () [(_ ch x body ...) - #'(let ([x (car (place-channel-receive ch))]) - (place-channel-send ch (cons (begin body ...) big)))])) + #'(let ([x (car (place-channel-get ch))]) + (place-channel-put ch (cons (begin body ...) big)))])) (define (test expect fun . args) (printf "~s ==> " (cons fun args)) @@ -41,28 +41,28 @@ (printf " BUT EXPECTED ~s\n" expect)) ok?))) -(define (echo ch) (place-channel-send ch (place-channel-receive ch))) -(define (recv/print ch) (displayln (place-channel-receive ch))) +(define (echo ch) (place-channel-put ch (place-channel-get ch))) +(define (recv/print ch) (displayln (place-channel-get ch))) (define-struct building (rooms location) #:prefab) (define-struct (house building) (occupied ) #:prefab) (define h1 (make-house 5 'factory 'yes)) -(define-syntax (test-place-channel-receive/send stx) +(define-syntax (test-place-channel-get/put stx) (syntax-case stx () [(_ ch x body ...) #'(normal-receiver ch x body ...)])) -(define-syntax (test-place-channel-receive/send-* stx) +(define-syntax (test-place-channel-get/put-* stx) (syntax-case stx () [(_ ch x body ...) #'(begin (normal-receiver ch x body) ...)])) (define-syntax-rule (channel-test-basic-types-worker receiver ch) (begin - (define-syntax-rule (test-place-channel-receive/send-* x body (... ...)) + (define-syntax-rule (test-place-channel-get/put-* x body (... ...)) (begin (receiver ch x body) (... ...))) - (test-place-channel-receive/send-* x + (test-place-channel-get/put-* x (not x) (not x) (void) @@ -80,10 +80,10 @@ `(,x)))) (define (channel-test-basic-types-master sender ch) - (define-syntax-rule (test-place-channel-send-receive sender ch (send expect) ...) + (define-syntax-rule (test-place-channel-put-receive sender ch (send expect) ...) (begin (test expect sender ch send) ...)) - (test-place-channel-send-receive sender ch + (test-place-channel-put-receive sender ch (#t #f) (#f #t) (null (void)) @@ -104,13 +104,13 @@ (channel-test-basic-types-worker normal-receiver ch) (channel-test-basic-types-worker big-receiver ch) - (define pc1 (place-channel-receive ch)) - (test-place-channel-receive/send pc1 x (string-append x "-ok")) + (define pc1 (place-channel-get ch)) + (test-place-channel-get/put pc1 x (string-append x "-ok")) - (define pc3 (first (place-channel-receive ch))) - (test-place-channel-receive/send pc3 x (string-append x "-ok3")) + (define pc3 (first (place-channel-get ch))) + (test-place-channel-get/put pc3 x (string-append x "-ok3")) - (test-place-channel-receive/send-* ch x + (test-place-channel-get/put-* ch x (begin (flvector-set! x 2 5.0) "Ready1") (begin (flvector-set! x 2 6.0) "Ready2") (begin (fxvector-set! x 2 5) "Ready2.1") @@ -118,8 +118,8 @@ (begin (bytes-set! x 2 67) "Ready3") (begin (bytes-set! x 2 67) "Ready4")) - (define pc5 (place-channel-receive ch)) - (place-channel-send pc5 "Ready5") + (define pc5 (place-channel-get ch)) + (place-channel-put pc5 "Ready5") (channel-test-basic-types-worker normal-receiver pc5) (channel-test-basic-types-worker big-receiver pc5) @@ -144,7 +144,7 @@ (printf "Master ~a length ~a\n" desc ll) (define p (place/anon ch - (define l (place-channel-receive ch)) + (define l (place-channel-get ch)) (define wl (length l)) (printf "Worker length ~a\n" wl) (when (symbol? (car l)) @@ -153,11 +153,11 @@ (unless (and (symbol? v) (eq? v (intern-num-sym (modulo x 1000)))) (printf "bad ~s\n" v)))) - (place-channel-send ch wl))) + (place-channel-put ch wl))) - (place-channel-send p l) - (define wlen (place-channel-receive p)) + (place-channel-put p l) + (define wlen (place-channel-get p)) (unless (= wlen ll) (raise (format "~a master length ~a != worker length ~a\n" desc ll wlen)) (place-wait p)))) @@ -171,66 +171,66 @@ (define b1 (shared-bytes 66 66 66 66)) (define b2 (make-shared-bytes 4 65)) - (channel-test-basic-types-master place-channel-send/receive pl) + (channel-test-basic-types-master place-channel-put/get pl) (channel-test-basic-types-master big-sender pl) (define-values (pc1 pc2) (place-channel)) - (place-channel-send pl pc2) - (test "Testing-ok" place-channel-send/receive pc1 "Testing") + (place-channel-put pl pc2) + (test "Testing-ok" place-channel-put/get pc1 "Testing") (define-values (pc3 pc4) (place-channel)) - (place-channel-send pl (list pc4)) - (test "Testing-ok3" place-channel-send/receive pc3 "Testing") + (place-channel-put pl (list pc4)) + (test "Testing-ok3" place-channel-put/get pc3 "Testing") - (test "Ready1" place-channel-send/receive pl flv1) + (test "Ready1" place-channel-put/get pl flv1) (test 5.0 flvector-ref flv1 2) - (test "Ready2" place-channel-send/receive pl flv2) + (test "Ready2" place-channel-put/get pl flv2) (test 6.0 flvector-ref flv2 2) - (test "Ready2.1" place-channel-send/receive pl fxv1) + (test "Ready2.1" place-channel-put/get pl fxv1) (test 5 fxvector-ref fxv1 2) - (test "Ready2.2" place-channel-send/receive pl fxv2) + (test "Ready2.2" place-channel-put/get pl fxv2) (test 6 fxvector-ref fxv2 2) - (test "Ready3" place-channel-send/receive pl b1) + (test "Ready3" place-channel-put/get pl b1) (test 67 bytes-ref b1 2) - (test "Ready4" place-channel-send/receive pl b2) + (test "Ready4" place-channel-put/get pl b2) (test 67 bytes-ref b2 2) (define-values (pc5 pc6) (place-channel)) - (place-channel-send pl pc5) + (place-channel-put pl pc5) (test "Ready5" sync pc6) - (channel-test-basic-types-master place-channel-send/receive pc6) + (channel-test-basic-types-master place-channel-put/get pc6) (channel-test-basic-types-master big-sender pc6) (let ([try-graph (lambda (s) (let ([v (read (open-input-string s))]) - (place-channel-send pc6 v) - (test v place-channel-receive pc6)))]) + (place-channel-put pc6 v) + (test v place-channel-get pc6)))]) (try-graph "#0=(#0# . #0#)") (try-graph "#0=#(#0# 7 #0#)") (try-graph "#0=#s(thing 7 #0#)")) - (check-exn exn:fail? (λ () (place-channel-send pl (open-output-string)))) - (check-not-exn (λ () (place-channel-send pl "Test String"))) - (check-not-exn (λ () (place-channel-send pl (bytes->path #"/tmp/unix" 'unix)))) - (check-not-exn (λ () (place-channel-send pl (bytes->path #"C:\\Windows" 'windows)))) + (check-exn exn:fail? (λ () (place-channel-put pl (open-output-string)))) + (check-not-exn (λ () (place-channel-put pl "Test String"))) + (check-not-exn (λ () (place-channel-put pl (bytes->path #"/tmp/unix" 'unix)))) + (check-not-exn (λ () (place-channel-put pl (bytes->path #"C:\\Windows" 'windows)))) (place-wait pl)) (let ([p (place/anon ch - (with-handlers ([exn:break? (lambda (x) (place-channel-send ch "OK"))]) - (place-channel-send ch "ALIVE") + (with-handlers ([exn:break? (lambda (x) (place-channel-put ch "OK"))]) + (place-channel-put ch "ALIVE") (sync never-evt) - (place-channel-send ch "NOK")))]) + (place-channel-put ch "NOK")))]) - (test "ALIVE" place-channel-receive p) + (test "ALIVE" place-channel-get p) (place-break p) - (test "OK" place-channel-receive p) + (test "OK" place-channel-get p) (place-wait p)) (test-long (lambda (x) 3) "Listof ints") diff --git a/collects/tests/racket/place.rktl b/collects/tests/racket/place.rktl index 6da052e9f9..a9fc3235e8 100644 --- a/collects/tests/racket/place.rktl +++ b/collects/tests/racket/place.rktl @@ -19,11 +19,11 @@ (arity-test place 2 2) (arity-test place-wait 1 1) (arity-test place-channel 0 0) -(arity-test place-channel-send 2 2) -(arity-test place-channel-receive 1 1) +(arity-test place-channel-put 2 2) +(arity-test place-channel-get 1 1) (arity-test place-channel? 1 1) (arity-test place? 1 1) -(arity-test place-channel-send/receive 2 2) +(arity-test place-channel-put/get 2 2) (arity-test processor-count 0 0) (err/rt-test (place "foo.rkt")) @@ -35,4 +35,4 @@ (sync never-evt))]) (place-kill p)) -(report-errs) \ No newline at end of file +(report-errs) diff --git a/src/racket/src/place.c b/src/racket/src/place.c index f356ba4888..b49096421c 100644 --- a/src/racket/src/place.c +++ b/src/racket/src/place.c @@ -96,8 +96,8 @@ void scheme_init_place(Scheme_Env *env) PLACE_PRIM_W_ARITY("place-break", scheme_place_break, 1, 1, plenv); PLACE_PRIM_W_ARITY("place?", scheme_place_p, 1, 1, plenv); PLACE_PRIM_W_ARITY("place-channel", scheme_place_channel, 0, 0, plenv); - PLACE_PRIM_W_ARITY("place-channel-send", scheme_place_send, 1, 2, plenv); - PLACE_PRIM_W_ARITY("place-channel-receive", scheme_place_receive, 1, 1, plenv); + PLACE_PRIM_W_ARITY("place-channel-put", scheme_place_send, 1, 2, plenv); + PLACE_PRIM_W_ARITY("place-channel-get", scheme_place_receive, 1, 1, plenv); PLACE_PRIM_W_ARITY("place-channel?", scheme_place_channel_p, 1, 1, plenv); #ifdef MZ_USE_PLACES