drivers/timers_unix/timers_unix.c
changeset 793 72e9e1064432
parent 663 70fc3603e36f
child 801 32d146b64a35
equal deleted inserted replaced
791:7740ac6fdedc 793:72e9e1064432
     1 #include <stdlib.h>
     1 #include <stdlib.h>
     2 
     2 
     3 #include <sys/time.h>
     3 #include <sys/time.h>
     4 #include <pthread.h> 
     4 #include <pthread.h>
     5 #include <signal.h>
     5 #include <signal.h>
     6 #include <time.h>
     6 #include <time.h>
     7 
     7 
     8 #include "applicfg.h"
     8 #include <applicfg.h>
     9 #include "timer.h"
     9 #include <timer.h>
    10 
    10 
    11 static pthread_mutex_t CanFestival_mutex = PTHREAD_MUTEX_INITIALIZER;
    11 static pthread_mutex_t CanFestival_mutex = PTHREAD_MUTEX_INITIALIZER;
    12 
    12 
    13 static struct timeval last_sig;
    13 static struct timeval last_sig;
    14 
    14 
   102 {
   102 {
   103     /*get signal*/
   103     /*get signal*/
   104   	//  if(signal(SIGTERM, canReceiveLoop_signal) == SIG_ERR) {
   104   	//  if(signal(SIGTERM, canReceiveLoop_signal) == SIG_ERR) {
   105 	//		perror("signal()");
   105 	//		perror("signal()");
   106 	//}
   106 	//}
       
   107 
       
   108     // Set the cancelation state for immediatly cancel the task
       
   109     int ret;
       
   110 
       
   111     ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
       
   112 
       
   113     if (ret != 0)
       
   114         perror("Can't enable the cancelation of the receiving task");
       
   115 
       
   116     ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
       
   117 
       
   118     if (ret != 0)
       
   119         perror("Can't set the asynchronous cancel typ");
       
   120 
   107     unixtimer_ReceiveLoop_task_proc((CAN_PORT)port);
   121     unixtimer_ReceiveLoop_task_proc((CAN_PORT)port);
   108 
   122 
   109     return NULL;
   123     return NULL;
   110 }
   124 }
   111 
   125 
   117 	}
   131 	}
   118 }
   132 }
   119 
   133 
   120 void WaitReceiveTaskEnd(TASK_HANDLE *Thread)
   134 void WaitReceiveTaskEnd(TASK_HANDLE *Thread)
   121 {
   135 {
   122 	if(pthread_kill(*Thread, SIGTERM)) {
   136 	if(pthread_cancel(*Thread)) {
   123 		perror("pthread_kill()");
   137 		perror("pthread_cancel()");
   124 	}
   138 	}
   125 	if(pthread_join(*Thread, NULL)) {
   139 	if(pthread_join(*Thread, NULL)) {
   126 		perror("pthread_join()");
   140 		perror("pthread_join()");
   127 	}
   141 	}
   128 }
   142 }