[Lcdproc] lis pthreads patch [was lis driver fails to compile]
Daryl F
wyatt@prairieturtle.ca
Tue Nov 6 05:39:01 2007
--MP_3hZR/4Trjw7HzG/3npJ=EHJ
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
On Mon, 05 Nov 2007 23:26:55 +0100
Markus Dolze <bsdfan@nurfuerspam.de> wrote:
> Markus Dolze wrote:
> > 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.
> Hi again,
>
> unfortunately I was a little bit too fast. The patch applies cleanly,
> but the changes to acinclude.m4 don't detect libusb and libftdi
> properly and therefore the lis driver is not built at all. I think
> converting it to the pkg-config thing will probably work.
>
> Regards
> Markus Dolze
Hi Markus,
Here's the reworked patch using the pkg-config method. I'm concerned
that it may not detect libpthread. libpthread doesn't use pkg-config.
Can you try it on FreeBSD and see if it will compile the lis driver?
Regards,
Daryl Fonseca-Holt
--MP_3hZR/4Trjw7HzG/3npJ=EHJ
Content-Type: text/x-patch; name=lis_pthread_and_pkgconfig.patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=lis_pthread_and_pkgconfig.patch
diff -ruN lcdproc-CVS-current/aclocal.m4 lcdproc-CVS-test/aclocal.m4
--- lcdproc-CVS-current/aclocal.m4 2007-11-05 02:00:44.000000000 -0600
+++ lcdproc-CVS-test/aclocal.m4 2007-11-05 23:22:21.000000000 -0600
@@ -276,9 +276,31 @@
])
;;
lis)
+ AC_CHECK_HEADERS([pthread.h],[
+ AC_CHECK_LIB(pthread, pthread_create,[
+ LIBPTHREAD_LIBS="-lpthread"
+ 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 "$enable_libftdi" = yes ; then
- DRIVERS="$DRIVERS lis${SO}"
- actdrivers=["$actdrivers lis"]
+ if test "$enable_libusb" = yes; then
+ if test "$ac_cv_lis_pthread" = yes; then
+ DRIVERS="$DRIVERS lis${SO}"
+ actdrivers=["$actdrivers lis"]
+ else
+ AC_MSG_WARN([The lis driver needs the pthread library])
+ fi
+ else
+ AC_MSG_WARN([The lis driver needs the usb library])
+ fi
else
AC_MSG_WARN([The lis driver needs the ftdi library])
fi
@@ -436,6 +458,7 @@
AC_SUBST(LIBGLCD)
AC_SUBST(LIBFTDI)
AC_SUBST(LIBXOSD)
+AC_SUBST(LIBPTHREAD_LIBS)
])
diff -ruN lcdproc-CVS-current/server/drivers/Makefile.am lcdproc-CVS-test/server/drivers/Makefile.am
--- lcdproc-CVS-current/server/drivers/Makefile.am 2007-11-04 02:00:37.000000000 -0600
+++ lcdproc-CVS-test/server/drivers/Makefile.am 2007-11-05 23:16:26.000000000 -0600
@@ -25,7 +25,7 @@
IOWarrior_CFLAGS = @LIBUSB_CFLAGS@ $(AM_CFLAGS)
hd44780_CFLAGS = @LIBUSB_CFLAGS@ @LIBFTDI_CFLAGS@ $(AM_CFLAGS)
g15_CFLAGS = @LIBUSB_CFLAGS@ $(AM_CFLAGS)
-lis_CFLAGS = @LIBFTDI_CFLAGS@ $(AM_CFLAGS)
+lis_CFLAGS = @LIBUSB_CFLAGS@ @LIBFTDI_CFLAGS@ $(AM_CFLAGS)
picolcd_CFLAGS = @LIBUSB_CFLAGS@ $(AM_CFLAGS)
shuttleVFD_CFLAGS = @LIBUSB_CFLAGS@ $(AM_CFLAGS)
ula200_CFLAGS = @LIBFTDI_CFLAGS@ $(AM_CFLAGS)
@@ -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 @LIBFTDI_LIBS@ @LIBUSB_LIBS@ @LIBPTHREAD_LIBS@ libbignum.a
MD8800_LDADD = libLCD.a
mtc_s16209x_LDADD = libLCD.a
MtxOrb_LDADD = libLCD.a libbignum.a
diff -ruN lcdproc-CVS-current/server/drivers/lis.c lcdproc-CVS-test/server/drivers/lis.c
--- lcdproc-CVS-current/server/drivers/lis.c 2007-06-18 02:00:30.000000000 -0500
+++ lcdproc-CVS-test/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_3hZR/4Trjw7HzG/3npJ=EHJ--