From 8dac3bf3b10406d05c4d520e81082e490e3b76ff Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 25 Jun 2016 10:40:33 -0300 Subject: Added function to notify ScriptLanguage when a thread is created/freed, allows scripts to allocate a stack there via TLS --- drivers/unix/thread_posix.cpp | 7 +++++++ drivers/windows/thread_windows.cpp | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp index 6ace64a923..c71e09685b 100644 --- a/drivers/unix/thread_posix.cpp +++ b/drivers/unix/thread_posix.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "thread_posix.h" +#include "script_language.h" #if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED) @@ -50,7 +51,13 @@ void *ThreadPosix::thread_callback(void *userdata) { ThreadPosix *t=reinterpret_cast(userdata); t->id=(ID)pthread_self(); + + ScriptServer::thread_enter(); //scripts may need to attach a stack + t->callback(t->user); + + ScriptServer::thread_exit(); + return NULL; } diff --git a/drivers/windows/thread_windows.cpp b/drivers/windows/thread_windows.cpp index d5e489aab4..434f2e8fda 100644 --- a/drivers/windows/thread_windows.cpp +++ b/drivers/windows/thread_windows.cpp @@ -31,6 +31,7 @@ #if defined(WINDOWS_ENABLED) && !defined(WINRT_ENABLED) #include "os/memory.h" +#include "script_language.h" Thread::ID ThreadWindows::get_ID() const { @@ -45,8 +46,14 @@ Thread* ThreadWindows::create_thread_windows() { DWORD ThreadWindows::thread_callback( LPVOID userdata ) { ThreadWindows *t=reinterpret_cast(userdata); - t->callback(t->user); + + ScriptServer::thread_enter(); //scripts may need to attach a stack + t->id=(ID)GetCurrentThreadId(); // must implement + t->callback(t->user); + + ScriptServer::thread_exit(); + return 0; } -- cgit v1.2.3