Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Threading issues #190

Closed
MoAlyousef opened this issue Feb 15, 2021 · 7 comments
Closed

Android: Threading issues #190

MoAlyousef opened this issue Feb 15, 2021 · 7 comments
Assignees
Labels
CMake CMake bug or needs CMake support

Comments

@MoAlyousef
Copy link
Contributor

MoAlyousef commented Feb 15, 2021

On Android, FLTK's locking mechanisms don't work correctly (deadlock crashes), neither for enabling the global lock (via Fl::lock) or thru the Fl::awake(void *) messages (pipes). The Fl_lock.cxx file has the locking functions in an Android ifdef and remain to be implemented. I was able to get things working by subclassing the Fl_Android_System_Driver from the Fl_Posix_System_Driver instead of the Fl_System_Driver. I had to copy some implementation of the other posix systems (X11 namely for locking) since Android also uses pthreads.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4e8d8c759..c7aa9d93c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -300,6 +300,7 @@ elseif (ANDROID)
 
   set (DRIVER_FILES
     drivers/Android/Fl_Android_Application.cxx
+    drivers/Posix/Fl_Posix_System_Driver.cxx
     drivers/Android/Fl_Android_System_Driver.cxx
     drivers/Android/Fl_Android_Screen_Driver.cxx
     drivers/Android/Fl_Android_Screen_Keyboard.cxx
@@ -311,6 +312,7 @@ elseif (ANDROID)
   )
   set (DRIVER_HEADER_FILES
     drivers/Android/Fl_Android_Application.H
+    drivers/Posix/Fl_Posix_System_Driver.H
     drivers/Android/Fl_Android_System_Driver.H
     drivers/Android/Fl_Android_Screen_Driver.H
     drivers/Android/Fl_Android_Window_Driver.H
diff --git a/src/drivers/Android/Fl_Android_System_Driver.H b/src/drivers/Android/Fl_Android_System_Driver.H
index 5e6dafb1e..a985d9324 100644
--- a/src/drivers/Android/Fl_Android_System_Driver.H
+++ b/src/drivers/Android/Fl_Android_System_Driver.H
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <FL/fl_string.h>
 #include "../../Fl_System_Driver.H"
+#include "../Posix/Fl_Posix_System_Driver.H"
 #include <stdarg.h>
 
 /*
@@ -38,7 +39,7 @@
  - multithreading
  */
 
-class Fl_Android_System_Driver : public Fl_System_Driver
+class Fl_Android_System_Driver : public Fl_Posix_System_Driver
 {
 #if 0
 public:
@@ -122,9 +123,8 @@ public:
   virtual void add_fd(int fd, Fl_FD_Handler cb, void* = 0);
   virtual void remove_fd(int, int when);
   virtual void remove_fd(int);
-  virtual void gettime(time_t *sec, int *usec);
-#endif
   virtual char *strdup(const char *s) {return ::strdup(s);}
+#endif
 };
 
 #endif // FL_ANDROID_SYSTEM_DRIVER_H

The above diff works for multithreading, for Fl::awake I just use a std::queue, std::unique_lock and a mutex (in the Rust wrapper).

Edit: cleaned up patch thanks to Manolo's refactoring.

@Albrecht-S
Copy link
Member

I believe this is something that @MatthiasWM could address. Matthias?

Note: I'm working on a new implementation of FLTK's timeout mechanism which could affect the internals used here in the Android port. But anyway, maybe the suggestion can be applied.

@Albrecht-S Albrecht-S added the CMake CMake bug or needs CMake support label Dec 12, 2021
@MatthiasWM
Copy link
Contributor

Sorry, I have not touched the Android implementation in a long while. It will take at least a week to find myself back into the code. Wrapping up Fluid and Preferences has priority right now. But, yeah, the patch doesn't look wrong at first glance.

@Albrecht-S
Copy link
Member

Thanks, Matthias, I assigned this issue to you. Feel free to unassign...

@MatthiasWM
Copy link
Contributor

The Android port has been removed from the FLTK for now. The implementation was incomplete and highly experimental.

@MatthiasWM
Copy link
Contributor

Sorry for any inconvenience.

@dumblob
Copy link

dumblob commented Feb 15, 2022

Let's hope FLTK will return to Android (and maybe even iOS) sooner or later.

@MatthiasWM
Copy link
Contributor

Yes, Android, iOS, and Linux frame buffer support are in the pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake CMake bug or needs CMake support
Projects
None yet
Development

No branches or pull requests

4 participants