Skip to content

iceoryx_utils/internal/posix_wrapper/mutex.hpp🔗

Source code🔗

// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_UTILS_POSIX_WRAPPER_MUTEX_HPP
#define IOX_UTILS_POSIX_WRAPPER_MUTEX_HPP

#include "iceoryx_utils/cxx/optional.hpp"
#include "iceoryx_utils/platform/pthread.hpp"

#if defined(__QNX__) || defined(__APPLE__)
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_NORMAL
#endif

namespace iox
{
namespace posix
{
class mutex
{
  public:
    mutex(const bool f_isRecursive);

    ~mutex();

    mutex(const mutex&) = delete;
    mutex(mutex&&) = delete;
    mutex& operator=(const mutex&) = delete;
    mutex& operator=(mutex&&) = delete;

    bool lock();
    bool unlock();

    bool try_lock();

    pthread_mutex_t get_native_handle() const noexcept;

    pthread_mutex_t m_handle;
};
} // namespace posix
} // namespace iox

#endif // IOX_UTILS_POSIX_WRAPPER_MUTEX_HPP

Updated on 26 April 2021 at 15:31:01 CEST