atomically for non-threaded builds is just a begin

This commit is contained in:
Alex Shinn 2012-05-07 08:19:37 +09:00
parent be7a80007b
commit 1ab1008f20
2 changed files with 16 additions and 7 deletions

View file

@ -334,11 +334,13 @@ static sexp sexp_gc_op (sexp ctx, sexp self, sexp_sint_t n) {
return sexp_make_unsigned_integer(ctx, sum_freed); return sexp_make_unsigned_integer(ctx, sum_freed);
} }
#ifdef SEXP_USE_GREEN_THREADS
static sexp sexp_set_atomic (sexp ctx, sexp self, sexp_sint_t n, sexp new) { static sexp sexp_set_atomic (sexp ctx, sexp self, sexp_sint_t n, sexp new) {
sexp res = sexp_global(ctx, SEXP_G_ATOMIC_P); sexp res = sexp_global(ctx, SEXP_G_ATOMIC_P);
sexp_global(ctx, SEXP_G_ATOMIC_P) = new; sexp_global(ctx, SEXP_G_ATOMIC_P) = new;
return res; return res;
} }
#endif
static sexp sexp_string_contains (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp y) { static sexp sexp_string_contains (sexp ctx, sexp self, sexp_sint_t n, sexp x, sexp y) {
const char *res; const char *res;
@ -482,7 +484,9 @@ sexp sexp_init_library (sexp ctx, sexp self, sexp_sint_t n, sexp env, const char
sexp_define_foreign(ctx, env, "object-size", 1, sexp_object_size); sexp_define_foreign(ctx, env, "object-size", 1, sexp_object_size);
sexp_define_foreign_opt(ctx, env, "integer->immediate", 2, sexp_integer_to_immediate, SEXP_FALSE); sexp_define_foreign_opt(ctx, env, "integer->immediate", 2, sexp_integer_to_immediate, SEXP_FALSE);
sexp_define_foreign(ctx, env, "gc", 0, sexp_gc_op); sexp_define_foreign(ctx, env, "gc", 0, sexp_gc_op);
#ifdef SEXP_USE_GREEN_THREADS
sexp_define_foreign(ctx, env, "%set-atomic!", 1, sexp_set_atomic); sexp_define_foreign(ctx, env, "%set-atomic!", 1, sexp_set_atomic);
#endif
sexp_define_foreign(ctx, env, "string-contains", 2, sexp_string_contains); sexp_define_foreign(ctx, env, "string-contains", 2, sexp_string_contains);
sexp_define_foreign_opt(ctx, env, "integer->error-string", 1, sexp_error_string, SEXP_FALSE); sexp_define_foreign_opt(ctx, env, "integer->error-string", 1, sexp_error_string, SEXP_FALSE);
sexp_define_foreign(ctx, env, "update-free-vars!", 1, sexp_update_free_vars); sexp_define_foreign(ctx, env, "update-free-vars!", 1, sexp_update_free_vars);

View file

@ -363,10 +363,15 @@
;;> (e.g. running an infinite loop) can render the system unusable. ;;> (e.g. running an infinite loop) can render the system unusable.
;;> Never expose to a sandbox. ;;> Never expose to a sandbox.
(cond-expand
(threads
(define-syntax atomically (define-syntax atomically
(syntax-rules () (syntax-rules ()
((atomic . body) ((atomically . body)
(let* ((atomic? (%set-atomic! #t)) (let* ((atomic? (%set-atomic! #t))
(res (begin . body))) (res (begin . body)))
(%set-atomic! atomic?) (%set-atomic! atomic?)
res)))) res)))))
(else
(define-syntax atomically
(syntax-rules () ((atomically . body) (begin . body))))))