From 9fdd675eab7cae04dc176ea2aba2d53c59101beb Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 16 Feb 2021 16:28:44 +0100 Subject: Remove FL_CFG_SYS_POSIX and FL_CFG_SYS_WIN32 preprocessor vars from Fl_lock.cxx --- src/drivers/WinAPI/Fl_WinAPI_System_Driver.H | 4 +- src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 67 +++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) (limited to 'src/drivers/WinAPI') diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index 1860bc8b3..a31d5248b 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -1,7 +1,7 @@ // // Windows system driver for the Fast Light Tool Kit (FLTK). // -// Copyright 2010-2020 by Bill Spitzak and others. +// Copyright 2010-2021 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -119,6 +119,8 @@ public: virtual void remove_fd(int); virtual void gettime(time_t *sec, int *usec); virtual char* strdup(const char *s) { return ::_strdup(s); } + virtual void lock_ring(); + virtual void unlock_ring(); }; #endif // FL_WINAPI_SYSTEM_DRIVER_H diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx index 9c9d35553..38fd50a3d 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx @@ -1,7 +1,7 @@ // // Definition of Windows system driver for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2020 by Bill Spitzak and others. +// Copyright 1998-2021 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -15,6 +15,7 @@ // #include +#include #include "Fl_WinAPI_System_Driver.H" #include #include @@ -957,3 +958,67 @@ void Fl_WinAPI_System_Driver::gettime(time_t *sec, int *usec) { *sec = t.time; *usec = t.millitm * 1000; } + +// +// Code for lock support +// + +// These pointers are in Fl_win32.cxx: +extern void (*fl_lock_function)(); +extern void (*fl_unlock_function)(); + +// The main thread's ID +static DWORD main_thread; + +// Microsoft's version of a MUTEX... +static CRITICAL_SECTION cs; +static CRITICAL_SECTION *cs_ring; + +void Fl_WinAPI_System_Driver::unlock_ring() { + LeaveCriticalSection(cs_ring); +} + +void Fl_WinAPI_System_Driver::lock_ring() { + if (!cs_ring) { + cs_ring = (CRITICAL_SECTION*)malloc(sizeof(CRITICAL_SECTION)); + InitializeCriticalSection(cs_ring); + } + EnterCriticalSection(cs_ring); +} + +// +// 'unlock_function()' - Release the lock. +// + +static void unlock_function() { + LeaveCriticalSection(&cs); +} + +// +// 'lock_function()' - Get the lock. +// + +static void lock_function() { + EnterCriticalSection(&cs); +} + +int Fl_WinAPI_System_Driver::lock() { + if (!main_thread) InitializeCriticalSection(&cs); + + lock_function(); + + if (!main_thread) { + fl_lock_function = lock_function; + fl_unlock_function = unlock_function; + main_thread = GetCurrentThreadId(); + } + return 0; +} + +void Fl_WinAPI_System_Driver::unlock() { + unlock_function(); +} + +void Fl_WinAPI_System_Driver::awake(void* msg) { + PostThreadMessage( main_thread, fl_wake_msg, (WPARAM)msg, 0); +} -- cgit v1.2.3