summaryrefslogtreecommitdiff
path: root/src/drivers/WinAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/WinAPI')
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.H4
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx67
2 files changed, 69 insertions, 2 deletions
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 <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);
+}