[Lcdproc] lis pthreads patch [was lis driver fails to compile]
Daryl F
wyatt@prairieturtle.ca
Sun Nov 4 23:08:01 2007
--MP_+Z=Qn4z2mVYwXpEwK9/qglJ
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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
--MP_+Z=Qn4z2mVYwXpEwK9/qglJ
Content-Type: text/x-patch; name=lis_pthread.patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=lis_pthread.patch
diff -ruN lcdproc-CVS-current-20071101/aclocal.m4 lcdproc-CVS-current-20071101-lis-pthread/aclocal.m4
--- lcdproc-CVS-current-20071101/aclocal.m4 2007-11-01 02:00:33.000000000 -0500
+++ lcdproc-CVS-current-20071101-lis-pthread/aclocal.m4 2007-11-04 16:50:19.000000000 -0600
@@ -270,27 +270,53 @@
])
;;
lis)
- AC_CHECK_HEADERS([usb.h ftdi.h],[
- AC_CHECK_LIB(ftdi, main,[
- LIBFTDI="-lusb -lftdi"
- DRIVERS="$DRIVERS lis${SO}"
- actdrivers=["$actdrivers lis"]
+ 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_MSG_WARN([The lis driver needs the ftdi library])
+ ac_cv_lis_ftdi=no
+ AC_MSG_WARN([The lis driver needs the ftdi library >=0.8 with ftdi_setdtr()])
])
],[
dnl else
- AC_MSG_WARN([The lis driver needs ftdi.h and usb.h])
+ ac_cv_lis_ftdi=no
+ AC_MSG_WARN([The lis driver needs ftdi.h])
])
- AC_CACHE_CHECK([for ftdi_setdtr() in libftdi], ac_cv_ftdi_setdtr,
- [oldlibs="$LIBS"
- LIBS="$LIBS $LIBFTDI"
- AC_TRY_LINK_FUNC(ftdi_setdtr, ac_cv_ftdi_setdtr=yes, ac_cv_ftdi_setdtr=no)
- LIBS="$oldlibs"
+ 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_ftdi_setdtrt" = no; then
- AC_MSG_WARN([Upgrade to libftdi >= version 0.8])
+ 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)
@@ -454,6 +480,7 @@
AC_SUBST(LIBFTDI)
AC_SUBST(LIBXOSD)
AC_SUBST(LIBUSBLCD)
+AC_SUBST(LIBLIS)
])
diff -ruN lcdproc-CVS-current-20071101/server/drivers/Makefile.am lcdproc-CVS-current-20071101-lis-pthread/server/drivers/Makefile.am
--- lcdproc-CVS-current-20071101/server/drivers/Makefile.am 2007-09-26 02:01:00.000000000 -0500
+++ lcdproc-CVS-current-20071101-lis-pthread/server/drivers/Makefile.am 2007-11-04 16:13:00.000000000 -0600
@@ -43,7 +43,7 @@
irman_LDADD = @LIBIRMAN@
lcterm_LDADD = libLCD.a
lirc_LDADD = @LIBLIRC_CLIENT@
-lis_LDADD = libLCD.a @LIBFTDI@ libbignum.a
+lis_LDADD = libLCD.a @LIBLIS@ libbignum.a
MD8800_LDADD = libLCD.a
mtc_s16209x_LDADD = libLCD.a
MtxOrb_LDADD = libLCD.a libbignum.a
diff -ruN lcdproc-CVS-current-20071101/server/drivers/lis.c lcdproc-CVS-current-20071101-lis-pthread/server/drivers/lis.c
--- lcdproc-CVS-current-20071101/server/drivers/lis.c 2007-06-18 02:00:30.000000000 -0500
+++ lcdproc-CVS-current-20071101-lis-pthread/server/drivers/lis.c 2007-11-04 16:54:51.000000000 -0600
@@ -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.
--MP_+Z=Qn4z2mVYwXpEwK9/qglJ--