From d8ed2f5211e93a6105d4c27c2fe57dbff8c38aa7 Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Thu, 15 Mar 2012 07:12:38 +0000 Subject: [PATCH] support single threaded environments --- sljit_src/sljitConfig.h | 6 ++++++ sljit_src/sljitLir.h | 4 ++++ sljit_src/sljitUtils.c | 32 +++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/sljit_src/sljitConfig.h b/sljit_src/sljitConfig.h index c832dfe..85f9f56 100644 --- a/sljit_src/sljitConfig.h +++ b/sljit_src/sljitConfig.h @@ -60,6 +60,12 @@ #define SLJIT_UTIL_STACK 1 #endif +/* Single threaded application. Does not require any locks. */ +#ifndef SLJIT_SINGLE_THREADED +/* Disabled by default. */ +#define SLJIT_SINGLE_THREADED 0 +#endif + /* --------------------------------------------------------------------- */ /* Configuration */ /* --------------------------------------------------------------------- */ diff --git a/sljit_src/sljitLir.h b/sljit_src/sljitLir.h index 0cb1c1e..63d2625 100644 --- a/sljit_src/sljitLir.h +++ b/sljit_src/sljitLir.h @@ -42,6 +42,10 @@ - very effective to cache an important value once - A fixed stack space can be allocated for local variables - The compiler is thread-safe + - The compiler is highly configurable through preprocessor macros. + You can disable unneeded features (multithreading in single + threaded applications), and you can use your own system functions + (including memory allocators). See sljitConfig.h Disadvantages: - Limited number of registers (only 6+4 integer registers, max 3+2 temporary, max 3+2 saved and 4 floating point registers) diff --git a/sljit_src/sljitUtils.c b/sljit_src/sljitUtils.c index 094ac99..afa1b95 100644 --- a/sljit_src/sljitUtils.c +++ b/sljit_src/sljitUtils.c @@ -30,7 +30,37 @@ #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) || (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK) -#ifdef _WIN32 +#if (defined SLJIT_SINGLE_THREADED && SLJIT_SINGLE_THREADED) + +#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) + +static SLJIT_INLINE void allocator_grab_lock(void) +{ + // Always successful. +} + +static SLJIT_INLINE void allocator_release_lock(void) +{ + // Always successful. +} + +#endif /* SLJIT_EXECUTABLE_ALLOCATOR */ + +#if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK) + +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_grab_lock(void) +{ + // Always successful. +} + +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_release_lock(void) +{ + // Always successful. +} + +#endif /* SLJIT_UTIL_GLOBAL_LOCK */ + +#elif defined(_WIN32) /* SLJIT_SINGLE_THREADED */ #include "windows.h" -- 2.11.4.GIT