[Lcdproc] lis pthreads patch [was lis driver fails to compile]

Markus Dolze bsdfan@nurfuerspam.de
Mon Nov 5 22:18:01 2007


This is a multi-part message in MIME format.
--------------070203050304090706080601
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Daryl F wrote:
> Peter,
>
> Here's the patch for the lis driver. It now uses pthread_create() and
> is hopefully portable to non-Linux kernels. 
>
> In adding another library test for autoconf I found the logic for
> checking for libftdi and libusb wasn't quite right either. Now it
> checks for all three and ensures that the version of libftdi with
> ftdi_setdtr() is available. This also fixes the minor annoyance of
> configure saying it will build the lis driver twice.
>
> Thanks to Rene Wagner for your help with this.
>
> Regards,
> Daryl
Hello,

I updated the patch to match current CVS. It compiles fine on FreeBSD.

Regards
Markus Dolze

--------------070203050304090706080601
Content-Type: text/plain;
 name="lis_pthread_v2.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="lis_pthread_v2.patch"

--- current/acinclude.m4	Mon Nov  5 21:23:59 2007
+++ testing/acinclude.m4	Mon Nov  5 23:09:42 2007
@@ -263,11 +263,53 @@
 			])
 			;;
 		lis)
-			if test "$enable_libftdi" = yes ; then
-				DRIVERS="$DRIVERS lis${SO}"
-				actdrivers=["$actdrivers lis"]
-			else
-				AC_MSG_WARN([The lis driver needs the ftdi library])
+			AC_CHECK_HEADERS([usb.h],[
+			    AC_CHECK_LIB(usb, main,[
+				ac_cv_lis_usb=yes
+			    ],[
+dnl			    else
+				ac_cv_lis_usb=no
+				AC_MSG_WARN([The lis driver needs the usb library])
+			    ])
+			],[
+dnl			else
+			    ac_cv_lis_usb=no
+			    AC_MSG_WARN([The lis driver needs usb.h])
+			])
+			AC_CHECK_HEADERS([ftdi.h],[
+			    AC_CHECK_LIB(ftdi, ftdi_setdtr,[
+				ac_cv_lis_ftdi=yes
+			    ],[
+dnl			    else
+			        ac_cv_lis_ftdi=no
+				AC_MSG_WARN([The lis driver needs the ftdi library >=0.8 with ftdi_setdtr()])
+			    ])
+			],[
+dnl			else
+			    ac_cv_lis_ftdi=no
+			    AC_MSG_WARN([The lis driver needs ftdi.h])
+			])
+			AC_CHECK_HEADERS([pthread.h],[
+			    AC_CHECK_LIB(pthread, pthread_create,[
+				ac_cv_lis_pthread=yes
+			    ],[
+dnl			    else
+				ac_cv_lis_pthread=no
+				AC_MSG_WARN([The lis driver needs the pthread library and pthread_create() from it])
+			    ])
+			],[
+dnl			else
+			    ac_cv_lis_pthread=no
+			    AC_MSG_WARN([The lis driver needs pthread.h])
+			])
+			if test "$ac_cv_lis_usb" = yes; then
+			    if test "$ac_cv_lis_ftdi" = yes; then
+				if test "$ac_cv_lis_pthread" = yes; then
+				    LIBLIS="-lusb -lftdi -lpthread"
+				    DRIVERS="$DRIVERS lis${SO}"
+				    actdrivers=["$actdrivers lis"]
+				fi
+			    fi
 			fi
 			;;
 		MD8800)
@@ -423,6 +465,7 @@
 AC_SUBST(LIBGLCD)
 AC_SUBST(LIBFTDI)
 AC_SUBST(LIBXOSD)
+AC_SUBST(LIBLIS)
 ])
 
 
--- current/server/drivers/Makefile.am	Mon Nov  5 21:23:59 2007
+++ testing/server/drivers/Makefile.am	Mon Nov  5 21:32:15 2007
@@ -45,7 +45,7 @@
 irman_LDADD =        @LIBIRMAN@
 lcterm_LDADD =       libLCD.a
 lirc_LDADD =         @LIBLIRC_CLIENT@
-lis_LDADD =          libLCD.a @LIBFTDI_LIBS@ libbignum.a
+lis_LDADD =          libLCD.a @LIBLIS@ libbignum.a
 MD8800_LDADD =       libLCD.a
 mtc_s16209x_LDADD =  libLCD.a
 MtxOrb_LDADD =       libLCD.a libbignum.a
--- current/server/drivers/lis.c	Mon Nov  5 21:23:59 2007
+++ testing/server/drivers/lis.c	Mon Nov  5 21:29:34 2007
@@ -45,6 +45,8 @@
  * 	2007/05/30	Remove set_custom_chars(). Implement
  * 			lis_set_chars(), lis_vbar(), lis_hbar()
  * 			and lis_num() using helper functions.
+ * 	2007/11/01	Change Linux-centric clone() to POSIX
+ * 			threads for portability.
  */
 #include <stdlib.h>
 #include <stdio.h>
@@ -54,6 +56,7 @@
 #include <string.h>
 #include <errno.h>
 #include <syslog.h>
+#include <pthread.h>
 
 #include <usb.h>
 #include <ftdi.h>
@@ -367,8 +370,9 @@
 	PrivateData *p;
 	int err;
 	const char *s;
-	unsigned char buffer[64], *thread_stack;
+	unsigned char buffer[64];
 	int count;
+	pthread_t read_thread;
 
 	report(RPT_DEBUG, "%s: Initializing driver",
 		drvthis->name);
@@ -502,16 +506,14 @@
 		goto err_ftdi;
 	}
 
-	// clone a thread to keep a read up on the device
-	thread_stack = calloc(4096, 1);
-	if(! thread_stack) {
-		report(RPT_ERR, "%s: cannot create thread stack", drvthis->name);
-		goto err_framebuf;
-	}
-
-	err = clone(lis_read_thread, thread_stack+4092, CLONE_VM | CLONE_THREAD| CLONE_SIGHAND, drvthis);
-	if (err == -1) {
-		report(RPT_ERR, "%s: clone() - %s", drvthis->name, strerror(errno));
+	// create a thread to keep a read up on the device
+	err = pthread_create(	&read_thread,
+				NULL,
+				(void *) lis_read_thread,
+				drvthis
+				);
+	if (err) {
+		report(RPT_ERR, "%s: pthread_create() - %s", drvthis->name, err);
 		goto err_framebuf;
 	}
 	p->parent_flag = 1;		// show we're now a happy parent, birth successful.

--------------070203050304090706080601--