diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2018-10-21 16:15:26 -0700 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2018-10-21 16:15:26 -0700 |
commit | 8e8dbfd58038cc7c83cf163f03a6e6b69eb34ad1 (patch) | |
tree | 1c6313a4643d07797a451fe302645f5a25c16e02 /motionMonitor | |
parent | 4ed74f2d45acf41416e69a2cc7df7cfb1e87c67d (diff) |
Lock shared resources whewn reading
Diffstat (limited to 'motionMonitor')
-rw-r--r-- | motionMonitor/motionMonitor.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/motionMonitor/motionMonitor.c b/motionMonitor/motionMonitor.c index b7844ea..a4736e2 100644 --- a/motionMonitor/motionMonitor.c +++ b/motionMonitor/motionMonitor.c @@ -101,26 +101,30 @@ le_result_t brnkl_motion_getSuddenImpact(double* xAcc, size_t *xSize, if(!totalImpacts) LE_INFO("No Sudden Impacts to Report"); + else { + pthread_mutex_lock(&impactMutex); + //check + + if( + totalImpacts < *xSize || + totalImpacts < *ySize || + totalImpacts < *zSize + ) + return LE_OUT_OF_RANGE; + + for(int i = 0; i < totalImpacts; i++){ + xAcc[i] = xAccImpact[i]; + yAcc[i] = yAccImpact[i]; + zAcc[i] = zAccImpact[i]; + } + + *xSize = *ySize = *zSize = totalImpacts; - //check - if( - totalImpacts < *xSize || - totalImpacts < *ySize || - totalImpacts < *zSize - ) - return LE_OUT_OF_RANGE; + totalImpacts = 0; - for(int i = 0; i < totalImpacts; i++){ - xAcc[i] = xAccImpact[i]; - yAcc[i] = yAccImpact[i]; - zAcc[i] = zAccImpact[i]; + pthread_mutex_unlock(&impactMutex); } - - *xSize = *ySize = *zSize = totalImpacts; - - - totalImpacts = 0; return LE_OK; } @@ -170,4 +174,4 @@ void initThread(){ COMPONENT_INIT { initThread(); -}
\ No newline at end of file +} |