diff options
author | Ludovic Courtès <ludo@gnu.org> | 2010-09-24 15:14:11 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2010-09-24 15:39:47 +0200 |
commit | 271c3d3196d93746917426ecb0d494de4d27c071 (patch) | |
tree | a0aa6c49e259a43e05378ffbbd2dc6cbe5a4bda7 /libguile/vm.c | |
parent | f4a23f910f8ce4c8e656fe6c050a30ea39ac0fcf (diff) | |
download | guile-271c3d3196d93746917426ecb0d494de4d27c071.tar.gz |
Add `thread-vm' and `set-thread-vm!'.
* libguile/vm.c (thread_vm, scm_thread_vm, scm_set_thread_vm_x): New
functions.
(scm_the_vm): Add docstring. Use `thread_vm'.
* libguile/vm.h (scm_thread_vm, scm_set_thread_vm_x): New declarations.
* module/system/vm/vm.scm: Export `thread-vm' and `set-thread-vm!'.
Diffstat (limited to 'libguile/vm.c')
-rw-r--r-- | libguile/vm.c | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/libguile/vm.c b/libguile/vm.c index 01963f1c4..b229c2799 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -597,18 +597,53 @@ SCM_DEFINE (scm_vm_version, "vm-version", 0, 0, 0, } #undef FUNC_NAME -SCM_DEFINE (scm_the_vm, "the-vm", 0, 0, 0, - (void), - "") -#define FUNC_NAME s_scm_the_vm +/* Return T's VM. */ +static inline SCM +thread_vm (scm_i_thread *t) { - scm_i_thread *t = SCM_I_CURRENT_THREAD; - - if (SCM_UNLIKELY (scm_is_false ((t->vm)))) + if (SCM_UNLIKELY (scm_is_false (t->vm))) t->vm = make_vm (); return t->vm; } + +SCM_DEFINE (scm_thread_vm, "thread-vm", 1, 0, 0, + (SCM thread), + "Return @var{thread}'s VM.") +#define FUNC_NAME s_scm_thread_vm +{ + SCM_VALIDATE_THREAD (1, thread); + + return thread_vm (SCM_I_THREAD_DATA (thread)); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_set_thread_vm_x, "set-thread-vm!", 2, 0, 0, + (SCM thread, SCM vm), + "Set @var{thread}'s VM to @var{vm}. Warning: Code being\n" + "executed by @var{thread}'s current VM won't automatically\n" + "switch to @var{vm}.") +#define FUNC_NAME s_scm_set_thread_vm_x +{ + scm_i_thread *t; + + SCM_VALIDATE_THREAD (1, thread); + SCM_VALIDATE_VM (2, vm); + + t = SCM_I_THREAD_DATA (thread); + t->vm = vm; + + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + +SCM_DEFINE (scm_the_vm, "the-vm", 0, 0, 0, + (void), + "Return the current thread's VM.") +#define FUNC_NAME s_scm_the_vm +{ + return thread_vm (SCM_I_CURRENT_THREAD); +} #undef FUNC_NAME |