summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Van Doorn <vandoorn.nick@gmail.com>2018-10-21 16:15:26 -0700
committerNick Van Doorn <vandoorn.nick@gmail.com>2018-10-21 16:15:26 -0700
commit8e8dbfd58038cc7c83cf163f03a6e6b69eb34ad1 (patch)
tree1c6313a4643d07797a451fe302645f5a25c16e02
parent4ed74f2d45acf41416e69a2cc7df7cfb1e87c67d (diff)
Lock shared resources whewn reading
-rw-r--r--motionMonitor/motionMonitor.c38
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
+}