diff options
| author | Stefan Eßer <se@FreeBSD.org> | 2022-08-30 18:35:22 +0000 |
|---|---|---|
| committer | Stefan Eßer <se@FreeBSD.org> | 2022-08-30 18:37:36 +0000 |
| commit | 161a37cc712bae177402d7143cb21b7d085c69c7 (patch) | |
| tree | 8eabf221dc1a31abf6f88dd6fcdb0b4e2a78fc82 /include/library.h | |
| parent | 1576f66712876ee8b0fcc8b35fb062e1813b4fc0 (diff) | |
Diffstat (limited to 'include/library.h')
| -rw-r--r-- | include/library.h | 136 |
1 files changed, 52 insertions, 84 deletions
diff --git a/include/library.h b/include/library.h index 63d24ee5f7a9..94c62923062a 100644 --- a/include/library.h +++ b/include/library.h @@ -39,91 +39,42 @@ #include <bcl.h> #include <num.h> +#include <vm.h> /** - * A header for functions that need to lock and setjmp(). It also sets the - * variable that tells bcl that it is running. - * @param l The label to jump to on error. + * A header that sets a jump. + * @param vm The thread data. + * @param l The label to jump to on error. */ -#define BC_FUNC_HEADER_LOCK(l) \ - do \ - { \ - BC_SIG_LOCK; \ - BC_SETJMP_LOCKED(l); \ - vm.err = BCL_ERROR_NONE; \ - vm.running = 1; \ - } \ +#define BC_FUNC_HEADER(vm, l) \ + do \ + { \ + BC_SETJMP(vm, l); \ + vm->err = BCL_ERROR_NONE; \ + } \ while (0) /** - * A footer to unlock and stop the jumping if an error happened. It also sets - * the variable that tells bcl that it is running. - * @param e The error variable to set. + * A footer for functions that do not return an error code. */ -#define BC_FUNC_FOOTER_UNLOCK(e) \ - do \ - { \ - BC_SIG_ASSERT_LOCKED; \ - e = vm.err; \ - vm.running = 0; \ - BC_UNSETJMP; \ - BC_LONGJMP_STOP; \ - vm.sig_lock = 0; \ - } \ +#define BC_FUNC_FOOTER_NO_ERR(vm) \ + do \ + { \ + BC_UNSETJMP(vm); \ + } \ while (0) /** - * A header that sets a jump and sets running. - * @param l The label to jump to on error. + * A footer for functions that *do* return an error code. + * @param vm The thread data. + * @param e The error variable to set. */ -#define BC_FUNC_HEADER(l) \ - do \ - { \ - BC_SETJMP(l); \ - vm.err = BCL_ERROR_NONE; \ - vm.running = 1; \ - } \ - while (0) - -/** - * A header that assumes that signals are already locked. It sets a jump and - * running. - * @param l The label to jump to on error. - */ -#define BC_FUNC_HEADER_INIT(l) \ - do \ - { \ - BC_SETJMP_LOCKED(l); \ - vm.err = BCL_ERROR_NONE; \ - vm.running = 1; \ - } \ - while (0) - -/** - * A footer for functions that do not return an error code. It clears running - * and unlocks the signals. It also stops the jumping. - */ -#define BC_FUNC_FOOTER_NO_ERR \ - do \ - { \ - vm.running = 0; \ - BC_UNSETJMP; \ - BC_LONGJMP_STOP; \ - vm.sig_lock = 0; \ - } \ - while (0) - -/** - * A footer for functions that *do* return an error code. It clears running and - * unlocks the signals. It also stops the jumping. - * @param e The error variable to set. - */ -#define BC_FUNC_FOOTER(e) \ - do \ - { \ - e = vm.err; \ - BC_FUNC_FOOTER_NO_ERR; \ - } \ +#define BC_FUNC_FOOTER(vm, e) \ + do \ + { \ + e = vm->err; \ + BC_FUNC_FOOTER_NO_ERR(vm); \ + } \ while (0) /** @@ -151,10 +102,10 @@ * is bad. * @param c The context. */ -#define BC_CHECK_CTXT(c) \ +#define BC_CHECK_CTXT(vm, c) \ do \ { \ - c = bcl_context(); \ + c = bcl_contextHelper(vm); \ if (BC_ERR(c == NULL)) \ { \ BclNumber n_num; \ @@ -168,10 +119,10 @@ * A header to check the context and return an error directly if it is bad. * @param c The context. */ -#define BC_CHECK_CTXT_ERR(c) \ +#define BC_CHECK_CTXT_ERR(vm, c) \ do \ { \ - c = bcl_context(); \ + c = bcl_contextHelper(vm); \ if (BC_ERR(c == NULL)) \ { \ return BCL_ERROR_INVALID_CONTEXT; \ @@ -183,12 +134,12 @@ * A header to check the context and abort if it is bad. * @param c The context. */ -#define BC_CHECK_CTXT_ASSERT(c) \ - do \ - { \ - c = bcl_context(); \ - assert(c != NULL); \ - } \ +#define BC_CHECK_CTXT_ASSERT(vm, c) \ + do \ + { \ + c = bcl_contextHelper(vm); \ + assert(c != NULL); \ + } \ while (0) /** @@ -272,4 +223,21 @@ typedef struct BclCtxt } BclCtxt; +/** + * Returns the @a BcVm for the current thread. + * @return The vm for the current thread. + */ +BcVm* +bcl_getspecific(void); + +#ifndef _WIN32 + +typedef pthread_key_t BclTls; + +#else // _WIN32 + +typedef DWORD BclTls; + +#endif // _WIN32 + #endif // LIBBC_PRIVATE_H |
