What can I help you with?
NVIDIA Holoscan SDK v3.3.0

Program Listing for File file_fifo_mutex.hpp

Return to documentation for file (include/holoscan/core/file_fifo_mutex.hpp)

Copy
Copied!
            

/* * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HOLOSCAN_CORE_FILE_FIFO_MUTEX_HPP #define HOLOSCAN_CORE_FILE_FIFO_MUTEX_HPP #include <sys/types.h> #include <memory> #include <string> #include <utility> namespace holoscan { constexpr int DEFAULT_FIFOMUTEX_WAIT_TIME_MS = 10; class ScopedFlock { public: // Deleting default constructors ScopedFlock() = delete; ScopedFlock(const ScopedFlock&) = delete; ScopedFlock& operator=(const ScopedFlock&) = delete; ScopedFlock(int fd, int lock_type, int unlock_type); ~ScopedFlock(); bool locked() const { return locked_; } private: int fd_ = -1; int unlock_type_; bool locked_ = false; }; class ScopedWaitedFlock { public: // Deleting default constructors ScopedWaitedFlock() = delete; ScopedWaitedFlock(const ScopedWaitedFlock&) = delete; ScopedWaitedFlock& operator=(const ScopedWaitedFlock&) = delete; ScopedWaitedFlock(int fd, int lock_type, int unlock_type, int wait_time_ms = DEFAULT_FIFOMUTEX_WAIT_TIME_MS); ~ScopedWaitedFlock() = default; bool locked() const { return scoped_lock_ && scoped_lock_->locked(); } private: std::unique_ptr<ScopedFlock> scoped_lock_; }; class FileFIFOMutex { public: // Delete default, copy and assignment constructors FileFIFOMutex(const FileFIFOMutex&) = delete; FileFIFOMutex& operator=(const FileFIFOMutex&) = delete; FileFIFOMutex() = delete; explicit FileFIFOMutex(std::string file_path); ~FileFIFOMutex(); void set_wait_time_ms(int wait_time_ms); void lock(); void unlock(); bool locked() const; private: std::unique_ptr<ScopedFlock> main_lock_; int fd_ = -1; int queue_fd_ = -1; pid_t pid_; bool locked_ = false; int wait_time_ms_ = DEFAULT_FIFOMUTEX_WAIT_TIME_MS; }; } // namespace holoscan #endif/* HOLOSCAN_CORE_FILE_FIFO_MUTEX_HPP */

© Copyright 2022-2025, NVIDIA. Last updated on May 29, 2025.