[PATCH 4/4] Use select(2) instead of nanosleep(2) in order to avoid busy-waiting (closes: #872470).

Jeremy Sowden jeremy at azazel.net
Sat Jun 22 21:29:22 BST 2019


---
 debian/patches/fix-599382.patch | 56 ++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 14 deletions(-)

diff --git a/debian/patches/fix-599382.patch b/debian/patches/fix-599382.patch
index 6d77a31d875d..04d56210e5dd 100644
--- a/debian/patches/fix-599382.patch
+++ b/debian/patches/fix-599382.patch
@@ -1,7 +1,10 @@
 Description: Avoid segfault when receiving CTRL-C twice.
+Updated to replace busy-wait loop with nextEvent function using select(2).
 Author: Kevin Kreamer <kevin at kreamer.org>
+Author: Jeremy Sowden <jeremy at azazel.net>
 Bug-Debian: https://bugs.debian.org/599382
-Last-Update: 2016-12-16
+Bug-Debian: https://bugs.debian.org/872470
+Last-Update: 2019-06-22
 
 --- a/wmdrawer.c
 +++ b/wmdrawer.c
@@ -74,26 +77,51 @@ Last-Update: 2016-12-16
  }
  
  void xfreeAllMemory (void) {
-@@ -853,8 +864,17 @@
-   /* X btn's coord */
-   int xbtn = 0, ybtn = 0;
-   unsigned int delta, btnIsPressed = 0;
-+  struct timespec tv;
+@@ -825,6 +836,29 @@
+   return 0;
+ }
+ 
++static int nextEvent (XEvent *e) {
++  fd_set rset;
++
++  dbg_msg (1, "Enter nextEvent function\n");
++
++  XSync (display, False);
++  if (XPending (display)) {
++    XNextEvent (display, e);
++    dbg_msg (1, "Event type = %d\n", e->type);
++    return 1;
++  }
++
++  FD_ZERO (&rset);
++  FD_SET (ConnectionNumber (display), &rset);
++
++  if (select (ConnectionNumber (display)+1, &rset, NULL, NULL, NULL) > 0) {
++    XNextEvent (display, e);
++    return 1;
++  }
 +
-+  tv.tv_sec = 0;
-+  tv.tv_nsec = 100000;
++  return 0;
++}
 +
+ /* Convert mouse coordinate into button coordinate */
+ static void convertMCoordIntoBCoord (int mcol, int mrow, int *bcol, int *brow) {
+   switch (config.direction) {
+@@ -854,8 +888,11 @@
+   int xbtn = 0, ybtn = 0;
+   unsigned int delta, btnIsPressed = 0;
+ 
+-  while (True) {
+-    XNextEvent (display, &e);
 +  while (shouldExit == 0) {
-+    if (XPending (display) == 0) {
-+      nanosleep(&tv, NULL);
++    if (nextEvent(&e) == 0) {
 +      continue;
 +    }
- 
--  while (True) {
-     XNextEvent (display, &e);
++
      rebuildApp ();
      /* look at X.h & Xlib.h in /usr/X11R6/include/X11/ */
-@@ -1012,7 +1032,7 @@
+     switch (e.type) {
+@@ -1012,7 +1049,7 @@
        }
        break;
      case DestroyNotify:
-- 
2.20.1




More information about the Pkg-wmaker-devel mailing list