summaryrefslogtreecommitdiff
path: root/nuttx/arch/sim/src/up_x11eventloop.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-09-29 21:13:49 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-09-29 21:13:49 +0000
commiteaf142837ca2b85afa7037292dc5a08c34ff8367 (patch)
treecd55f971703914c912bb0e4bddf956d06146048a /nuttx/arch/sim/src/up_x11eventloop.c
parent46801bed95c44460286a1ed78fc07e813eebfb66 (diff)
downloadpx4-nuttx-eaf142837ca2b85afa7037292dc5a08c34ff8367.tar.gz
px4-nuttx-eaf142837ca2b85afa7037292dc5a08c34ff8367.tar.bz2
px4-nuttx-eaf142837ca2b85afa7037292dc5a08c34ff8367.zip
Don't run X11 event loop on a pthread; X11 is not thread-safe.
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4001 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/sim/src/up_x11eventloop.c')
-rw-r--r--nuttx/arch/sim/src/up_x11eventloop.c58
1 files changed, 19 insertions, 39 deletions
diff --git a/nuttx/arch/sim/src/up_x11eventloop.c b/nuttx/arch/sim/src/up_x11eventloop.c
index 4e35d25ab..478388065 100644
--- a/nuttx/arch/sim/src/up_x11eventloop.c
+++ b/nuttx/arch/sim/src/up_x11eventloop.c
@@ -38,7 +38,6 @@
****************************************************************************/
#include <stdio.h>
-#include <pthread.h>
#include <X11/Xlib.h>
@@ -59,7 +58,6 @@
****************************************************************************/
extern int up_buttonevent(int x, int y, int buttons);
-extern int up_tcleave(int x, int y, int buttons);
/****************************************************************************
* Public Variables
@@ -68,10 +66,8 @@ extern int up_tcleave(int x, int y, int buttons);
/* Defined in up_x11framebuffer.c */
extern Display *g_display;
-extern Window g_window;
-pthread_t g_eventloop;
-volatile int g_evloopactive;
+volatile int g_eventloop;
/****************************************************************************
* Private Variables
@@ -93,32 +89,33 @@ static int up_buttonmap(int state)
}
/****************************************************************************
- * Name: up_x11eventthread
+ * Public Functions
***************************************************************************/
-static void *up_x11eventthread(void *arg)
+/****************************************************************************
+ * Name: up_x11events
+ *
+ * Description:
+ * Called periodically from the IDLE loop to check for queued X11 events.
+ *
+ ***************************************************************************/
+
+void up_x11events(void)
{
- Window window;
XEvent event;
- /* Release queued events on the display */
+ /* Check if there are any pending, queue X11 events. */
- (void)XAllowEvents(g_display, AsyncBoth, CurrentTime);
+ if (XPending(g_display) > 0)
+ {
+ /* Yes, get the event (this should not block since we know there are
+ * pending events)
+ */
- /* Grab mouse button 1, enabling mouse-related events */
+ XNextEvent(g_display, &event);
- window = DefaultRootWindow(g_display);
- (void)XGrabButton(g_display, Button1, AnyModifier, window, 1,
- ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,
- GrabModeAsync, GrabModeAsync, None, None);
+ /* Then process the event */
- /* Then loop until we are commanded to stop (when g_evloopactive becomes zero),
- * waiting for events and processing events as they are received.
- */
-
- while ( g_evloopactive)
- {
- XNextEvent(g_display, &event);
switch (event.type)
{
case MotionNotify : /* Enabled by ButtonMotionMask */
@@ -140,21 +137,4 @@ static void *up_x11eventthread(void *arg)
break;
}
}
-
- XUngrabButton(g_display, Button1, AnyModifier, window);
- return NULL;
}
-
-/****************************************************************************
- * Name: up_x11eventloop
- ***************************************************************************/
-
-int up_x11eventloop(void)
-{
- /* Start the X11 event loop */
-
- g_evloopactive = 1;
- return pthread_create(&g_eventloop, 0, up_x11eventthread, 0);
-}
-
-