Skip to content

Commit 54f8fc8

Browse files
Added lock for sensor readings
1 parent 306613a commit 54f8fc8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

trikControl/src/linux/rangeSensorWorker.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ void RangeSensorWorker::readFile()
116116

117117
int RangeSensorWorker::read()
118118
{
119-
return mDistance;
119+
mLock.lockForRead();
120+
int const result = mDistance;
121+
mLock.unlock();
122+
return result;
120123
}
121124

122125
int RangeSensorWorker::readRawData()
123126
{
124-
return mRawDistance;
127+
mLock.lockForRead();
128+
int const result = mRawDistance;
129+
mLock.unlock();
130+
return result;
125131
}

0 commit comments

Comments
 (0)