Reinstalled threads

Tue, 24 Jun 2014 20:21:07 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 24 Jun 2014 20:21:07 +0200
changeset 74
879bd09e2b96
parent 73
4a28de5b9b47
child 75
4b976601737d

Reinstalled threads

thermferm/sensors.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/thermferm/sensors.c	Mon Jun 23 22:50:29 2014 +0200
+++ b/thermferm/sensors.c	Tue Jun 24 20:21:07 2014 +0200
@@ -31,7 +31,7 @@
 #ifdef HAVE_WIRINGPI_H
 PI_THREAD (my_sensors_loop)
 #else
-int my_sensors_loop(void)
+void *my_sensors_loop(void *threadid)
 #endif
 {
     w1_therm		*tmp1, *old1;
--- a/thermferm/server.c	Mon Jun 23 22:50:29 2014 +0200
+++ b/thermferm/server.c	Tue Jun 24 20:21:07 2014 +0200
@@ -315,7 +315,7 @@
 #ifdef HAVE_WIRINGPI_H
 PI_THREAD (my_server_loop)
 #else
-int my_server_loop(void)
+void *my_server_loop(void *threadid)
 #endif
 {
     socklen_t   addrlen;
--- a/thermferm/thermferm.c	Mon Jun 23 22:50:29 2014 +0200
+++ b/thermferm/thermferm.c	Tue Jun 24 20:21:07 2014 +0200
@@ -40,7 +40,9 @@
 extern unsigned char	lcdbuf[MAX_LCDS][20][4];
 #endif
 int			lcdupdate;
-
+#ifndef HAVE_WIRINGPI_H
+pthread_t		threads[2];
+#endif
 
 int  server(void);
 void help(void);
@@ -227,10 +229,10 @@
     char                buf[1024];
     time_t		now, last = (time_t)0;
     w1_therm		*tmp1;
-#ifdef HAVE_WIRINGPI_H
-    int			rc;
+    int			rc, run = 1, temp;
+#ifndef	HAVE_WIRINGPI_H
+    long		t = 0;
 #endif
-    int			run = 1, temp;
 
     if (lockprog((char *)"thermferm")) {
 	syslog(LOG_NOTICE, "Can't lock");
@@ -239,17 +241,23 @@
 
 #ifdef HAVE_WIRINGPI_H
     rc = piThreadCreate(my_sensors_loop);
+#else
+    rc = pthread_create(&threads[0], NULL, my_sensors_loop, (void *)t );
+#endif
     if (rc) {
 	fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc);
 	syslog(LOG_NOTICE, "my_sensors_loop thread didn't start rc=%d", rc);
     }
 
+#ifdef HAVE_WIRINGPI_H
     rc = piThreadCreate(my_server_loop);
+#else
+    rc = pthread_create(&threads[1], NULL, my_server_loop, (void *)t );
+#endif
     if (rc) {
 	fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc);
 	syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc);
     }
-#endif
 
     snprintf(buf, 1023, "tempA,tempB");
     logger((char *)"thermferm.log", (char *)"thermferm", buf);
--- a/thermferm/thermferm.h	Mon Jun 23 22:50:29 2014 +0200
+++ b/thermferm/thermferm.h	Tue Jun 24 20:21:07 2014 +0200
@@ -29,13 +29,13 @@
 #include <netdb.h>
 #include <poll.h>
 #include <stdbool.h>
+#ifndef HAVE_WIRINGPI_H
+#include <pthread.h>
+#endif
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
 
 
-/* mosquitto */
-//  # include <mosquitto.h>
-
 #ifdef HAVE_WIRINGPI_H
 /* wiringPi */
 #include <wiringPi.h>
@@ -180,7 +180,7 @@
 #ifdef HAVE_WIRINGPI_H
 PI_THREAD (my_sensors_loop);
 #else
-int my_sensors_loop(void);
+void *my_sensors_loop(void *);
 #endif
 
 /* server.c */
@@ -189,7 +189,7 @@
 #ifdef HAVE_WIRINGPI_H
 PI_THREAD (my_server_loop);
 #else
-int my_server_loop(void);
+void *my_server_loop(void *);
 #endif
 
 

mercurial