From f3e1cf10aaa75ff178ade937fdd51d834552614d Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 30 May 2011 07:18:02 -0600 Subject: [PATCH] change `hash-count' to take the lock; fix docs --- collects/scribblings/reference/hashes.scrbl | 8 ++++---- src/racket/src/list.c | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/collects/scribblings/reference/hashes.scrbl b/collects/scribblings/reference/hashes.scrbl index f9aa0ce420..0d162093cd 100644 --- a/collects/scribblings/reference/hashes.scrbl +++ b/collects/scribblings/reference/hashes.scrbl @@ -366,10 +366,10 @@ within @scheme[proc]. @see-also-concurrency-caveat[]} @defproc[(hash-count [hash hash?]) exact-nonnegative-integer?]{ -Returns the number of keys mapped by @scheme[hash]. If @scheme[hash] -is not created with @scheme['weak], then the result is computed in -constant time and atomically. If @scheme[hash] is created with -@scheme['weak], see the @concurrency-caveat[] above.} +Returns the number of keys mapped by @scheme[hash]. Unless @scheme[hash] +retains keys weakly, the result is computed in +constant time and atomically. If @scheme[hash] retains it keys weakly, a +traversal is required to count the keys.} @defproc[(hash-iterate-first [hash hash?]) diff --git a/src/racket/src/list.c b/src/racket/src/list.c index 1d95b3d09f..a463a1e032 100644 --- a/src/racket/src/list.c +++ b/src/racket/src/list.c @@ -1972,6 +1972,8 @@ static Scheme_Object *hash_table_count(int argc, Scheme_Object *argv[]) Scheme_Bucket **buckets, *bucket; const char *key; + if (t->mutex) scheme_wait_sema(t->mutex,0); + buckets = t->buckets; weak = t->weak; @@ -1989,6 +1991,8 @@ static Scheme_Object *hash_table_count(int argc, Scheme_Object *argv[]) SCHEME_USE_FUEL(1); } + if (t->mutex) scheme_post_sema(t->mutex); + return scheme_make_integer(count); } else { scheme_wrong_type("hash-count", "hash", 0, argc, argv);