Skip to content

Commit 4da3b2f

Browse files
committed
Optimize read frames
- Remove excess GenericScopedLock calls, these are handled internally by the Array - Remove extra calls to port controllers to process frames - Stop acquiring data before clearing individual device arrays to prevent any data being added after clearing the arrays
1 parent 3be08ec commit 4da3b2f

File tree

10 files changed

+3
-40
lines changed

10 files changed

+3
-40
lines changed

Source/Devices/AnalogIO.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,17 @@ void AnalogIO::stopAcquisition()
199199
{
200200
while (!frameArray.isEmpty())
201201
{
202-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
203202
oni_destroy_frame(frameArray.removeAndReturn(0));
204203
}
205204
}
206205

207206
void AnalogIO::addFrame(oni_frame_t* frame)
208207
{
209-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
210208
frameArray.add(frame);
211209
}
212210

213211
int AnalogIO::getNumberOfFrames()
214212
{
215-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
216213
return frameArray.size();
217214
}
218215

@@ -224,7 +221,6 @@ void AnalogIO::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
224221

225222
void AnalogIO::processFrame(uint64_t eventWord)
226223
{
227-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
228224
oni_frame_t* frame = frameArray.removeAndReturn(0);
229225

230226
int16_t* dataPtr = (int16_t*)frame->data;

Source/Devices/Bno055.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ void Bno055::stopAcquisition()
157157
{
158158
while (!frameArray.isEmpty())
159159
{
160-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
161160
oni_destroy_frame(frameArray.removeAndReturn(0));
162161
}
163162

@@ -167,7 +166,6 @@ void Bno055::stopAcquisition()
167166

168167
void Bno055::addFrame(oni_frame_t* frame)
169168
{
170-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
171169
frameArray.add(frame);
172170
}
173171

@@ -181,7 +179,6 @@ void Bno055::processFrames()
181179
{
182180
while (!frameArray.isEmpty())
183181
{
184-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
185182
oni_frame_t* frame = frameArray.removeAndReturn(0);
186183

187184
int16_t* dataPtr = ((int16_t*)frame->data) + 4;

Source/Devices/DigitalIO.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ void DigitalIO::stopAcquisition()
7070
{
7171
while (!frameArray.isEmpty())
7272
{
73-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
7473
oni_destroy_frame(frameArray.removeAndReturn(0));
7574
}
7675
}
@@ -91,22 +90,18 @@ EventChannel::Settings DigitalIO::getEventChannelSettings(DataStream* stream)
9190

9291
void DigitalIO::addFrame(oni_frame_t* frame)
9392
{
94-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
9593
frameArray.add(frame);
9694
}
9795

9896
int DigitalIO::getNumberOfWords()
9997
{
100-
const GenericScopedLock<CriticalSection> frameLock(eventWords.getLock());
10198
return eventWords.size();
10299
}
103100

104101
void DigitalIO::processFrames()
105102
{
106103
while (!frameArray.isEmpty())
107104
{
108-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
109-
const GenericScopedLock<CriticalSection> digitalInputsLock(eventWords.getLock());
110105
oni_frame_t* frame = frameArray.removeAndReturn(0);
111106

112107
uint16_t* dataPtr = (uint16_t*)frame->data;
@@ -126,8 +121,6 @@ void DigitalIO::processFrames()
126121

127122
uint64_t DigitalIO::getEventWord()
128123
{
129-
const GenericScopedLock<CriticalSection> digitalInputsLock(eventWords.getLock());
130-
131124
if (eventWords.size() != 0)
132125
return eventWords.removeAndReturn(0);
133126

@@ -136,7 +129,5 @@ uint64_t DigitalIO::getEventWord()
136129

137130
bool DigitalIO::hasEventWord()
138131
{
139-
const GenericScopedLock<CriticalSection> digitalInputsLock(eventWords.getLock());
140-
141132
return eventWords.size() > 0;
142133
}

Source/Devices/HarpSyncInput.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,12 @@ void HarpSyncInput::stopAcquisition()
7676
{
7777
while (!frameArray.isEmpty())
7878
{
79-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
8079
oni_destroy_frame(frameArray.removeAndReturn(0));
8180
}
8281
}
8382

8483
void HarpSyncInput::addFrame(oni_frame_t* frame)
8584
{
86-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
8785
frameArray.add(frame);
8886
}
8987

@@ -97,7 +95,6 @@ void HarpSyncInput::processFrames()
9795
{
9896
while (!frameArray.isEmpty())
9997
{
100-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
10198
oni_frame_t* frame = frameArray.removeAndReturn(0);
10299

103100
uint32_t* dataPtr = (uint32_t*)frame->data;

Source/Devices/MemoryMonitor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,12 @@ void MemoryMonitor::stopAcquisition()
126126
{
127127
while (!frameArray.isEmpty())
128128
{
129-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
130129
oni_destroy_frame(frameArray.removeAndReturn(0));
131130
}
132131
}
133132

134133
void MemoryMonitor::addFrame(oni_frame_t* frame)
135134
{
136-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
137135
frameArray.add(frame);
138136
}
139137

@@ -152,7 +150,6 @@ void MemoryMonitor::processFrames()
152150
{
153151
while (!frameArray.isEmpty())
154152
{
155-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
156153
oni_frame_t* frame = frameArray.removeAndReturn(0);
157154

158155
uint32_t* dataPtr = (uint32_t*)frame->data;

Source/Devices/Neuropixels1e.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ void Neuropixels1e::stopAcquisition()
268268

269269
while (!frameArray.isEmpty())
270270
{
271-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
272271
oni_destroy_frame(frameArray.removeAndReturn(0));
273272
}
274273
}
@@ -288,7 +287,6 @@ void Neuropixels1e::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
288287

289288
void Neuropixels1e::addFrame(oni_frame_t* frame)
290289
{
291-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
292290
frameArray.add(frame);
293291
}
294292

@@ -299,7 +297,6 @@ void Neuropixels1e::processFrames()
299297

300298
while (!frameArray.isEmpty())
301299
{
302-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
303300
oni_frame_t* frame = frameArray.removeAndReturn(0);
304301

305302
uint16_t* dataPtr = (uint16_t*)frame->data;

Source/Devices/Neuropixels1f.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ void Neuropixels1f::stopAcquisition()
223223

224224
while (!frameArray.isEmpty())
225225
{
226-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
227226
oni_destroy_frame(frameArray.removeAndReturn(0));
228227
}
229228
}
@@ -243,7 +242,6 @@ void Neuropixels1f::addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers)
243242

244243
void Neuropixels1f::addFrame(oni_frame_t* frame)
245244
{
246-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
247245
frameArray.add(frame);
248246
}
249247

@@ -254,7 +252,6 @@ void Neuropixels1f::processFrames()
254252

255253
while (!frameArray.isEmpty())
256254
{
257-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
258255
oni_frame_t* frame = frameArray.removeAndReturn(0);
259256

260257
uint16_t* dataPtr = (uint16_t*)frame->data;

Source/Devices/Neuropixels2e.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,12 @@ void Neuropixels2e::stopAcquisition()
493493

494494
while (!frameArray.isEmpty())
495495
{
496-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
497496
oni_destroy_frame(frameArray.removeAndReturn(0));
498497
}
499498
}
500499

501500
void Neuropixels2e::addFrame(oni_frame_t* frame)
502501
{
503-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
504502
frameArray.add(frame);
505503
}
506504

@@ -527,7 +525,6 @@ void Neuropixels2e::processFrames()
527525
{
528526
while (!frameArray.isEmpty())
529527
{
530-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
531528
oni_frame_t* frame = frameArray.removeAndReturn(0);
532529

533530
uint16_t* dataPtr = (uint16_t*)frame->data;

Source/Devices/PortController.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,19 @@ void PortController::stopAcquisition()
4646
{
4747
while (!frameArray.isEmpty())
4848
{
49-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
5049
oni_destroy_frame(frameArray.removeAndReturn(0));
5150
}
5251
}
5352

5453
void PortController::addFrame(oni_frame_t* frame)
5554
{
56-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
5755
frameArray.add(frame);
5856
}
5957

6058
void PortController::processFrames()
6159
{
6260
while (!frameArray.isEmpty())
6361
{
64-
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
6562
oni_frame_t* frame = frameArray.removeAndReturn(0);
6663

6764
int8_t* dataPtr = (int8_t*)frame->data;

Source/OnixSource.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,14 @@ bool OnixSource::stopAcquisition()
10511051
if (!portA->getErrorFlag() && !portB->getErrorFlag())
10521052
waitForThreadToExit(2000);
10531053

1054+
oni_size_t reg = 0;
1055+
context->setOption(ONI_OPT_RUNNING, reg);
1056+
10541057
for (const auto& source : enabledSources)
10551058
{
10561059
source->stopAcquisition();
10571060
}
10581061

1059-
oni_size_t reg = 0;
1060-
context->setOption(ONI_OPT_RUNNING, reg);
1061-
10621062
for (auto buffers : sourceBuffers)
10631063
buffers->clear();
10641064

@@ -1093,8 +1093,5 @@ bool OnixSource::updateBuffer()
10931093
if (threadShouldExit()) return true;
10941094
}
10951095

1096-
portA->processFrames();
1097-
portB->processFrames();
1098-
10991096
return !portA->getErrorFlag() && !portB->getErrorFlag();
11001097
}

0 commit comments

Comments
 (0)