![]() |
|
|||
File indexing completed on 2025-02-22 09:54:43
0001 //----------------------------------*-C++-*----------------------------------// 0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers. 0003 // See the top-level COPYRIGHT file for details. 0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0005 //---------------------------------------------------------------------------// 0006 //! \file accel/detail/OffloadWriter.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <memory> 0011 #include <mutex> 0012 0013 #include "celeritas/io/EventIOInterface.hh" 0014 0015 namespace celeritas 0016 { 0017 namespace detail 0018 { 0019 //---------------------------------------------------------------------------// 0020 /*! 0021 * Dump primaries to a shared file, one event per flush. 0022 * 0023 * This thin class simply adds a mutex to the output writer for thread safety. 0024 */ 0025 class OffloadWriter 0026 { 0027 public: 0028 //!@{ 0029 //! \name Type aliases 0030 using UPWriter = std::unique_ptr<EventWriterInterface>; 0031 using argument_type = EventWriterInterface::argument_type; 0032 //!@} 0033 0034 public: 0035 // Construct from a writer interface 0036 inline explicit OffloadWriter(UPWriter&& writer); 0037 0038 // Write primaries 0039 inline void operator()(argument_type); 0040 0041 private: 0042 std::mutex write_mutex_; 0043 UPWriter write_event_; 0044 }; 0045 0046 //---------------------------------------------------------------------------// 0047 // INLINE DEFINITIONS 0048 //---------------------------------------------------------------------------// 0049 /*! 0050 * Construct from a writer. 0051 */ 0052 OffloadWriter::OffloadWriter(UPWriter&& writer) 0053 : write_event_{std::move(writer)} 0054 { 0055 } 0056 0057 //---------------------------------------------------------------------------// 0058 /*! 0059 * Write primaries using a mutex. 0060 */ 0061 void OffloadWriter::operator()(argument_type primaries) 0062 { 0063 std::lock_guard scoped_lock{write_mutex_}; 0064 (*write_event_)(primaries); 0065 } 0066 0067 //---------------------------------------------------------------------------// 0068 } // namespace detail 0069 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |