From a280d993608d0c40ad0b4efc8adcbf72f67d53a4 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 11 May 2012 00:05:25 +0000 Subject: NxWM: Finishes touchscreen implementation; NuttX: Standardize touchscreen initialization interfaces for all boards git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4721 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/libnxwidgets/src/cnxserver.cxx | 86 +++++++++++++++++--------------- 1 file changed, 45 insertions(+), 41 deletions(-) (limited to 'NxWidgets/libnxwidgets/src') diff --git a/NxWidgets/libnxwidgets/src/cnxserver.cxx b/NxWidgets/libnxwidgets/src/cnxserver.cxx index dc6316835..be67e5641 100644 --- a/NxWidgets/libnxwidgets/src/cnxserver.cxx +++ b/NxWidgets/libnxwidgets/src/cnxserver.cxx @@ -232,47 +232,51 @@ bool CNxServer::connect(void) m_hNxServer = nx_connect(); if (m_hNxServer) { - pthread_attr_t attr; - - // Start a separate thread to listen for server events. This is probably - // the least efficient way to do this, but it makes this logic flow more - // smoothly. - - (void)pthread_attr_init(&attr); - param.sched_priority = CONFIG_NXWIDGETS_LISTENERPRIO; - (void)pthread_attr_setschedparam(&attr, ¶m); - (void)pthread_attr_setstacksize(&attr, CONFIG_NXWIDGETS_LISTENERSTACK); - - m_stop = false; - m_running = true; - - ret = pthread_create(&thread, &attr, listener, (FAR void *)this); - if (ret != 0) - { - gdbg("NxServer::connect: pthread_create failed: %d\n", ret); - m_running = false; - disconnect(); - return false; - } - - // Don't return until we are connected to the server - - while (!m_connected && m_running) - { - // Wait for the listener thread to wake us up when we really - // are connected. - - (void)sem_wait(&m_connsem); - } - - // In the successful case, the listener is still running (m_running) - // and the server is connected (m_connected). Anything else is a failure. - - if (!m_connected || !m_running) - { - disconnect(); - return false; - } + pthread_attr_t attr; + + // Start a separate thread to listen for server events. This is probably + // the least efficient way to do this, but it makes this logic flow more + // smoothly. + + (void)pthread_attr_init(&attr); + param.sched_priority = CONFIG_NXWIDGETS_LISTENERPRIO; + (void)pthread_attr_setschedparam(&attr, ¶m); + (void)pthread_attr_setstacksize(&attr, CONFIG_NXWIDGETS_LISTENERSTACK); + + m_stop = false; + m_running = true; + + ret = pthread_create(&thread, &attr, listener, (FAR void *)this); + if (ret != 0) + { + gdbg("NxServer::connect: pthread_create failed: %d\n", ret); + m_running = false; + disconnect(); + return false; + } + + // Detach from the thread + + (void)pthread_detach(thread); + + // Don't return until we are connected to the server + + while (!m_connected && m_running) + { + // Wait for the listener thread to wake us up when we really + // are connected. + + (void)sem_wait(&m_connsem); + } + + // In the successful case, the listener is still running (m_running) + // and the server is connected (m_connected). Anything else is a failure. + + if (!m_connected || !m_running) + { + disconnect(); + return false; + } } else { -- cgit v1.2.3