diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2021-02-16 16:28:44 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2021-02-16 16:28:57 +0100 |
| commit | 9fdd675eab7cae04dc176ea2aba2d53c59101beb (patch) | |
| tree | cb291e89411d0b73a74a3259fd651caccd0c405f /src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | |
| parent | b709b2a2d3451ec48d454a895a459dadf7c184e5 (diff) | |
Remove FL_CFG_SYS_POSIX and FL_CFG_SYS_WIN32 preprocessor vars from Fl_lock.cxx
Diffstat (limited to 'src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx')
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 67 |
1 files changed, 66 insertions, 1 deletions
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 <config.h> +#include <FL/platform.H> #include "Fl_WinAPI_System_Driver.H" #include <FL/Fl.H> #include <FL/fl_utf8.h> @@ -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); +} |
