diff options
author | dragonprevost <dragon@dkp.io> | 2018-10-23 12:31:18 -0700 |
---|---|---|
committer | dragonprevost <dragon@dkp.io> | 2018-10-23 12:31:18 -0700 |
commit | 7e731316021119dd708cd45f158df90007542636 (patch) | |
tree | 74884e539356f89317ff6d8cd4b75a1d1778cefb | |
parent | 69f496ba08ff63567a5707fb9ffa2a42b6e3b289 (diff) |
BROKEN: Swtiching from semaphores to pthread_mutex_t
-rw-r--r-- | motionMonitor/motionMonitor.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/motionMonitor/motionMonitor.c b/motionMonitor/motionMonitor.c index d71d91b..04ae52d 100644 --- a/motionMonitor/motionMonitor.c +++ b/motionMonitor/motionMonitor.c @@ -2,7 +2,6 @@ #include "legato.h" #include "util.h" #include <pthread.h> -#include <semaphore.h> #define N_CHANGE_BLOCKS 200 @@ -32,7 +31,7 @@ static const double impactThreshold = 20.0; Acceleration suddenImpact = {0, 0, 0}; pthread_t impactThread; -sem_t impactMutex; +pthread_mutex_t impactMutex; /* @@ -127,9 +126,9 @@ void *impactMonitor(void * ptr){ if(euclidian > impactThreshold){ LE_INFO("euclidian : %f", euclidian); //3. add x, y, z to impact array - sem_wait(&impactMutex); + pthread_mutex_lock(&impactMutex); recordImpact(&x, &y, &z); - sem_post(&impactMutex); + pthread_mutex_unlock(&impactMutex); } usleep(100*1000); @@ -142,10 +141,10 @@ void *impactMonitor(void * ptr){ */ void initThread(){ int thread, mutx; - + LE_INFO("initThread called"); + mutx = pthread_mutex_init(&impactMutex, NULL); thread = pthread_create( &impactThread, NULL, impactMonitor, NULL); - mutx = sem_init(&impactMutex, 0, 1); - + LE_INFO("mutexResult: %d", mutx); if(thread && mutx){ LE_INFO("Reader Thread Created"); }else{ |