mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-20 08:38:00 +02:00
rxr: switched to threads for threadObject (from pthread), moved priorities to threadObject, mutex
This commit is contained in:
@ -13,7 +13,6 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
pthread_mutex_t HDF5File::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
H5File* HDF5File::masterfd = 0;
|
||||
hid_t HDF5File::virtualfd = 0;
|
||||
|
||||
@ -142,19 +141,14 @@ void HDF5File::CreateFile() {
|
||||
uint64_t framestosave = ((*maxFramesPerFile == 0) ? *numImages : // infinite images
|
||||
(((extNumImages - subFileIndex) > (*maxFramesPerFile)) ? // save up to maximum at a time
|
||||
(*maxFramesPerFile) : (extNumImages-subFileIndex)));
|
||||
pthread_mutex_lock(&Mutex);
|
||||
try{
|
||||
HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
|
||||
subFileIndex, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
datatype, filefd, dataspace, dataset,
|
||||
HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES,
|
||||
dataspace_para, dataset_para,
|
||||
parameterNames, parameterDataTypes);
|
||||
} catch(const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << *udpPortNumber << ": HDF5 File created: " << currentFileName;
|
||||
@ -163,9 +157,10 @@ void HDF5File::CreateFile() {
|
||||
|
||||
|
||||
void HDF5File::CloseCurrentFile() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
}
|
||||
for (unsigned int i = 0; i < dataset_para.size(); ++i)
|
||||
delete dataset_para[i];
|
||||
dataset_para.clear();
|
||||
@ -178,14 +173,14 @@ void HDF5File::CloseCurrentFile() {
|
||||
|
||||
void HDF5File::CloseAllFiles() {
|
||||
numFilesinAcquisition = 0;
|
||||
pthread_mutex_lock(&Mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
if (master && (*detIndex==0)) {
|
||||
HDF5FileStatic::CloseMasterDataFile(masterfd);
|
||||
HDF5FileStatic::CloseVirtualDataFile(virtualfd);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
if (master && (*detIndex==0)) {
|
||||
HDF5FileStatic::CloseMasterDataFile(masterfd);
|
||||
HDF5FileStatic::CloseVirtualDataFile(virtualfd);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
|
||||
for (unsigned int i = 0; i < dataset_para.size(); ++i)
|
||||
delete dataset_para[i];
|
||||
dataset_para.clear();
|
||||
@ -206,9 +201,9 @@ void HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
|
||||
}
|
||||
numFramesInFile++;
|
||||
numActualPacketsInFile += nump;
|
||||
pthread_mutex_lock(&Mutex);
|
||||
|
||||
try {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
// extend dataset (when receiver start followed by many status starts (jungfrau)))
|
||||
if (fnum >= extNumImages) {
|
||||
HDF5FileStatic::ExtendDataset(index, dataspace, dataset,
|
||||
@ -231,11 +226,6 @@ void HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
|
||||
((*maxFramesPerFile == 0) ? fnum : fnum%(*maxFramesPerFile)),
|
||||
dataset_para, (sls_receiver_header*) (buffer),
|
||||
parameterDataTypes);
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
|
||||
|
||||
@ -253,15 +243,10 @@ void HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << "Master File: " << masterFileName;
|
||||
}
|
||||
pthread_mutex_lock(&Mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
attr.version = HDF5_WRITER_VERSION;
|
||||
try{
|
||||
HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
*overWriteEnable, attr);
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,14 +273,13 @@ void HDF5File::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
|
||||
|
||||
// called only by the one maser receiver
|
||||
void HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
std::string vname = HDF5FileStatic::CreateVirtualFileName(*filePath, *fileNamePrefix, *fileIndex);
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << "Virtual File: " << vname;
|
||||
}
|
||||
try {
|
||||
HDF5FileStatic::CreateVirtualDataFile(vname,
|
||||
HDF5FileStatic::CreateVirtualDataFile(vname,
|
||||
virtualfd, masterFileName,
|
||||
*filePath, *fileNamePrefix, *fileIndex, (*numImages > 1),
|
||||
*detIndex, *numUnitsPerDetector,
|
||||
@ -306,11 +290,6 @@ void HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
numDetY, numDetX, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
HDF5_WRITER_VERSION,
|
||||
parameterNames, parameterDataTypes);
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
|
||||
// called only by the one maser receiver
|
||||
@ -321,13 +300,7 @@ void HDF5File::LinkVirtualFileinMasterFile() {
|
||||
if ((*numImages > 1)) osfn << "_f" << std::setfill('0') << std::setw(12) << 0;
|
||||
std::string dsetname = osfn.str();
|
||||
|
||||
pthread_mutex_lock(&Mutex);
|
||||
try {
|
||||
HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName,
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName,
|
||||
dsetname, parameterNames);
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
|
Reference in New Issue
Block a user