[pisa-src] r1098 - in trunk: . libpisa

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Mon, 12 Oct 2009 17:47:02 +0200

Author: tjansen
Date: Mon Oct 12 17:47:02 2009
New Revision: 1098

Log:
Add a sample idle thread. Require pthread in configure.ac.

Modified:
   trunk/configure.ac
   trunk/libpisa/scheduler.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac  Mon Oct 12 17:20:59 2009        (r1097)
+++ trunk/configure.ac  Mon Oct 12 17:47:02 2009        (r1098)
@@ -27,6 +27,7 @@
        [Define if you have pow function in libm.]), )
 AC_CHECK_LIB([crypto], DSA_generate_key,, AC_MSG_ERROR(openssl lib not found))
 AC_CHECK_LIB([config], [config_setting_index],, AC_MSG_ERROR(libconfig lib not 
found))
+AC_CHECK_LIB(pthread, pthread_create)
 
 # Checks for header files.
 AC_HEADER_STDC

Modified: trunk/libpisa/scheduler.c
==============================================================================
--- trunk/libpisa/scheduler.c   Mon Oct 12 17:20:59 2009        (r1097)
+++ trunk/libpisa/scheduler.c   Mon Oct 12 17:47:02 2009        (r1098)
@@ -10,6 +10,8 @@
  * @date Oct. 2009
  */
 
+#include <pthread.h>
+
 #include "scheduler.h"
 
 /**
@@ -19,6 +21,23 @@
 static int *flag = NULL;
 
 /**
+ * Our thread ID for the scheduler thread
+ */
+static pthread_t thread;
+
+/**
+ * Main function of the scheduler thread
+ */
+static void *pisa_sched_main(void *arg)
+{
+       /* TODO: sleep until first element is due. */
+       while (1)
+               sleep(1);
+
+       return NULL;
+}
+
+/**
  * Initialize the scheduler. Create a thread that sleeps until the first
  * element in the list is due.
  *
@@ -26,8 +45,13 @@
  */ 
 void pisa_sched_init(int *shared)
 {
+       int result;
+
        flag = shared;
-       /* TODO: create a new thread */
+
+       result = pthread_create(&thread, NULL, pisa_sched_main, NULL);
+       if (result != 0)
+               PISA_ERROR("Could not create maintenance thread.\n");
 }
 
 /**
@@ -36,6 +60,10 @@
  */
 void pisa_sched_cleanup(void)
 {
+       pthread_cancel(thread);
+
+       /* TODO: free the task list */
+
        *flag = 0;
 }
 

Other related posts:

  • » [pisa-src] r1098 - in trunk: . libpisa - Thomas Jansen