Skip to content

Commit c78ef02

Browse files
authored
Merge pull request #215 from sy-c/master
v2.9.2
2 parents 4e8b5f6 + adc1d22 commit c78ef02

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

doc/releaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,6 @@ This file describes the main feature changes for each readout.exe released versi
436436
- DB improvements: occ.getRole() workaround for source id, logging.
437437
- Added logging of some EOR stats (TF number, etc) as for bookkeeping.
438438
- o2-readout-monitor: indexing by source for correct rates computation.
439+
440+
## v2.9.2 - 31/03/2022
441+
- Cosmetics improvements related to threads cleanup order on exit.

src/ReadoutEquipment.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,7 @@ int ReadoutEquipment::processRdh(DataBlockContainerReference& block)
826826
return 0;
827827
}
828828

829+
void ReadoutEquipment::abortThread() {
830+
// ensure thread is stopped
831+
readoutThread = nullptr;
832+
}

src/ReadoutEquipment.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class ReadoutEquipment
5858
// get current memory pool usage (available and total)
5959
int getMemoryUsage(size_t& numberOfPagesAvailable, size_t& numberOfPagesInPool);
6060

61+
// this should be called first in derived classes destructor
62+
// to ensure the associated thread is stopped before releasing resources
63+
void abortThread();
64+
6165
private:
6266
std::unique_ptr<Thread> readoutThread;
6367
static Thread::CallbackResult threadCallback(void* arg);

src/ReadoutStats.cxx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ ReadoutStats::ReadoutStats() {
3838
}
3939

4040
ReadoutStats::~ReadoutStats() {
41-
stopPublish();
42-
4341
if (publishThread != nullptr) {
4442
shutdownThread = 1;
4543
publishThread->join();
4644
publishThread = nullptr;
4745
}
46+
zmqCleanup();
4847
}
4948

5049
void ReadoutStats::reset()
@@ -220,17 +219,18 @@ void ReadoutStats::threadLoop() {
220219
void ReadoutStats::publishNow() {
221220
#ifdef WITH_ZMQ
222221
if (zmqEnabled) {
223-
fflush(stdout);
224222
uint64_t newUpdate = counters.notify.load();
225223
ReadoutStatsCounters snapshot;
226224
memcpy((void *)&snapshot, (void *)&gReadoutStats.counters, sizeof(snapshot));
227225
snapshot.timestamp = ((std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch())).count())/1000000.0;
228226
publishMutex.lock();
229-
if ((newUpdate != lastUpdate) || (snapshot.timestamp.load()-lastPublishTimestamp > publishInterval - 0.1)) {
230-
zmq_send(zmqHandle, &snapshot, sizeof(snapshot), ZMQ_DONTWAIT);
231-
lastUpdate = newUpdate;
232-
lastPublishTimestamp = snapshot.timestamp;
233-
}
227+
if (zmqHandle != nullptr) {
228+
if ((newUpdate != lastUpdate) || (snapshot.timestamp.load()-lastPublishTimestamp > publishInterval - 0.1)) {
229+
zmq_send(zmqHandle, &snapshot, sizeof(snapshot), ZMQ_DONTWAIT);
230+
lastUpdate = newUpdate;
231+
lastPublishTimestamp = snapshot.timestamp;
232+
}
233+
}
234234
publishMutex.unlock();
235235
}
236236
#endif

src/ReadoutVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define READOUT_VERSION "2.9.1"
12+
#define READOUT_VERSION "2.9.2"
1313

src/mainReadout.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,11 @@ Readout::~Readout() {
13261326
dataConsumers.clear();
13271327
agg = nullptr;
13281328
agg_output = nullptr;
1329-
readoutDevices.clear();
1329+
// ensure readout equipment threads stopped before releasing resources
1330+
for (const auto &d : readoutDevices) {
1331+
d->abortThread();
1332+
}
1333+
readoutDevices.clear(); // after aggregator, because they own the data blocks
13301334
}
13311335

13321336
#ifdef WITH_OCC
@@ -1764,6 +1768,7 @@ int main(int argc, char* argv[])
17641768

17651769
gReadoutStats.counters.state = stringToUint64("> exit");
17661770
gReadoutStats.counters.notify++;
1771+
gReadoutStats.stopPublish();
17671772

17681773
theReadout = nullptr;
17691774

0 commit comments

Comments
 (0)