2121#include " ExceptionInternal.h"
2222#include " Utilities/SmartPointer.h"
2323
24- namespace AliceO2 {
25- namespace roc {
24+ namespace AliceO2
25+ {
26+ namespace roc
27+ {
2628
2729namespace b = boost;
2830namespace bip = boost::interprocess;
2931namespace bfs = boost::filesystem;
3032
31- struct MemoryMappedFileInternal
32- {
33- std::string fileName;
34- boost::interprocess::file_mapping fileMapping;
35- boost::interprocess::mapped_region mappedRegion;
36- bool deleteFileOnDestruction;
33+ struct MemoryMappedFileInternal {
34+ std::string fileName;
35+ boost::interprocess::file_mapping fileMapping;
36+ boost::interprocess::mapped_region mappedRegion;
37+ bool deleteFileOnDestruction;
3738};
3839
3940MemoryMappedFile::MemoryMappedFile ()
@@ -42,26 +43,26 @@ MemoryMappedFile::MemoryMappedFile()
4243}
4344
4445MemoryMappedFile::MemoryMappedFile (const std::string& fileName, size_t fileSize, bool deleteFileOnDestruction,
45- bool lockMap)
46- : MemoryMappedFile()
46+ bool lockMap)
47+ : MemoryMappedFile()
4748{
4849 mInternal ->fileName = fileName;
4950 mInternal ->deleteFileOnDestruction = deleteFileOnDestruction;
5051
5152 if (lockMap) {
5253 // Try to acquire the lock on the file
53- try {
54+ try {
5455 Utilities::resetSmartPtr (mInterprocessLock , " Alice_O2_RoC_MMF_" + fileName + " _lock" );
5556 } catch (const boost::exception& e) {
5657 BOOST_THROW_EXCEPTION (LockException ()
57- << ErrorInfo::Message (" Couldn't lock Memory Mapped File; " + boost::diagnostic_information (e)));
58+ << ErrorInfo::Message (" Couldn't lock Memory Mapped File; " + boost::diagnostic_information (e)));
5859 }
5960
6061 try {
6162 mMapAcquired = map (fileName, fileSize);
6263 } catch (const boost::exception& e) {
6364 BOOST_THROW_EXCEPTION (MemoryMapException ()
64- << ErrorInfo::Message (boost::diagnostic_information (e)));
65+ << ErrorInfo::Message (boost::diagnostic_information (e)));
6566 }
6667 }
6768}
@@ -96,11 +97,11 @@ bool MemoryMappedFile::map(const std::string& fileName, size_t fileSize)
9697 auto dir = bfs::path (fileName.c_str ()).parent_path ();
9798 if (!(bfs::is_directory (dir) && bfs::exists (dir))) {
9899 BOOST_THROW_EXCEPTION (MemoryMapException ()
99- << ErrorInfo::Message (" Failed to open memory map file, parent directory does not exist" ));
100+ << ErrorInfo::Message (" Failed to open memory map file, parent directory does not exist" ));
100101 }
101102 }
102103
103- // We don't care if the file exists.
104+ // We don't care if the file exists.
104105 // Locks are in place that make sure we don't get here unless we're allowed to
105106 // Check the file exists
106107 /* {
@@ -113,38 +114,35 @@ bool MemoryMappedFile::map(const std::string& fileName, size_t fileSize)
113114 // Similar operation to calling "touch" command, making sure the file exists
114115 try {
115116 std::ofstream ofs (fileName.c_str (), std::ios::app);
116- }
117- catch (const std::exception& e) {
117+ } catch (const std::exception& e) {
118118 BOOST_THROW_EXCEPTION (MemoryMapException ()
119- << ErrorInfo::Message (std::string (" Failed to open memory map file: " ) + e.what ()));
119+ << ErrorInfo::Message (std::string (" Failed to open memory map file: " ) + e.what ()));
120120 }
121121
122122 // Resize and map file to memory
123123 try {
124124 bfs::resize_file (fileName.c_str (), fileSize);
125- }
126- catch (const std::exception& e) {
125+ } catch (const std::exception& e) {
127126 BOOST_THROW_EXCEPTION (MemoryMapException ()
128- << ErrorInfo::Message (std::string (" Failed to resize memory map file: " ) + e.what ())
129- << ErrorInfo::PossibleCauses ({
130- " Size not a multiple of page size " ,
131- " Not enough memory available " ,
132- " Not enough memory available (check 'hugeadm --pool-list') " ,
133- " Insufficient permissions " }));
127+ << ErrorInfo::Message (std::string (" Failed to resize memory map file: " ) + e.what ())
128+ << ErrorInfo::PossibleCauses ({ " Size not a multiple of page size " ,
129+ " Not enough memory available " ,
130+ " Not enough hugepages allocated (check 'hugeadm --pool-list') " ,
131+ " Insufficient permissions " ,
132+ " Stale hugepage / uio_pci_dma resources (run 'roc-cleanup') " }));
134133 }
135134
136135 try {
137136 mInternal ->fileMapping = bip::file_mapping (fileName.c_str (), bip::read_write);
138137 mInternal ->mappedRegion = bip::mapped_region (mInternal ->fileMapping , bip::read_write, 0 , fileSize);
139138 } catch (const std::exception& e) {
140139 BOOST_THROW_EXCEPTION (MemoryMapException ()
141- << ErrorInfo::Message (std::string (" Failed to memory map file: " ) + e.what ())
142- << ErrorInfo::PossibleCauses ({
143- " Not enough memory available " ,
144- " Not enough hugepages allocated (check 'hugeadm --pool-list ')" }));
140+ << ErrorInfo::Message (std::string (" Failed to memory map file: " ) + e.what ())
141+ << ErrorInfo::PossibleCauses ({ " Not enough memory available " ,
142+ " Not enough hugepages allocated (check 'hugeadm --pool-list') " ,
143+ " Stale hugepage / uio_pci_dma resources (run 'roc-cleanup ')" }));
145144 }
146- }
147- catch (MemoryMapException& e) {
145+ } catch (MemoryMapException& e) {
148146 e << ErrorInfo::FileName (fileName) << ErrorInfo::FileSize (fileSize);
149147 throw ;
150148 }
0 commit comments