mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
4 years ago
|
/**
|
||
5 years ago
|
*
|
||
4 years ago
|
* \section COPYRIGHT
|
||
5 years ago
|
*
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
5 years ago
|
*
|
||
4 years ago
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
5 years ago
|
*
|
||
|
*/
|
||
|
|
||
4 years ago
|
#ifndef SRSRAN_RWLOCK_GUARD_H
|
||
|
#define SRSRAN_RWLOCK_GUARD_H
|
||
5 years ago
|
|
||
|
#include <pthread.h>
|
||
|
|
||
4 years ago
|
namespace srsran {
|
||
5 years ago
|
|
||
|
class rwlock_write_guard
|
||
|
{
|
||
|
public:
|
||
|
rwlock_write_guard(pthread_rwlock_t& rwlock_) : rwlock(&rwlock_) { pthread_rwlock_wrlock(rwlock); }
|
||
|
rwlock_write_guard(const rwlock_write_guard&) = delete;
|
||
|
rwlock_write_guard(rwlock_write_guard&&) = delete;
|
||
|
rwlock_write_guard& operator=(const rwlock_write_guard&) = delete;
|
||
|
rwlock_write_guard& operator=(rwlock_write_guard&&) = delete;
|
||
|
~rwlock_write_guard() { pthread_rwlock_unlock(rwlock); }
|
||
|
|
||
|
private:
|
||
|
pthread_rwlock_t* rwlock;
|
||
|
};
|
||
|
|
||
|
// Shared lock guard that automatically unlocks rwlock on exit
|
||
|
class rwlock_read_guard
|
||
|
{
|
||
|
public:
|
||
|
rwlock_read_guard(pthread_rwlock_t& rwlock_) : rwlock(&rwlock_) { pthread_rwlock_rdlock(rwlock); }
|
||
|
rwlock_read_guard(const rwlock_read_guard&) = delete;
|
||
|
rwlock_read_guard(rwlock_read_guard&&) = delete;
|
||
|
rwlock_read_guard& operator=(const rwlock_read_guard&) = delete;
|
||
|
rwlock_read_guard& operator=(rwlock_read_guard&&) = delete;
|
||
|
~rwlock_read_guard() { pthread_rwlock_unlock(rwlock); }
|
||
|
|
||
|
private:
|
||
|
pthread_rwlock_t* rwlock;
|
||
|
};
|
||
|
|
||
4 years ago
|
} // namespace srsran
|
||
5 years ago
|
|
||
4 years ago
|
#endif // SRSRAN_RWLOCK_GUARD_H
|