mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 23:10:54 +01:00
ircd::ctx: Move unlock_guard from util:: to ctx::.
This commit is contained in:
parent
1a02642aef
commit
4760d36847
3 changed files with 47 additions and 20 deletions
|
@ -67,6 +67,7 @@ namespace ircd::ctx
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "shared_mutex.h"
|
#include "shared_mutex.h"
|
||||||
|
#include "unlock_guard.h"
|
||||||
#include "peek.h"
|
#include "peek.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
#include "shared_state.h"
|
#include "shared_state.h"
|
||||||
|
|
46
include/ircd/ctx/unlock_guard.h
Normal file
46
include/ircd/ctx/unlock_guard.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// Matrix Construct
|
||||||
|
//
|
||||||
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||||
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice is present in all copies. The
|
||||||
|
// full license for this software is available in the LICENSE file.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#define HAVE_IRCD_UTIL_H
|
||||||
|
|
||||||
|
namespace ircd::ctx
|
||||||
|
{
|
||||||
|
template<class lockable> struct unlock_guard;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inverse of std::lock_guard<>
|
||||||
|
template<class lockable>
|
||||||
|
struct ircd::ctx::unlock_guard
|
||||||
|
{
|
||||||
|
lockable &l;
|
||||||
|
|
||||||
|
unlock_guard(lockable &l);
|
||||||
|
~unlock_guard() noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace ircd
|
||||||
|
{
|
||||||
|
using ctx::unlock_guard;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class lockable>
|
||||||
|
ircd::ctx::unlock_guard<lockable>::unlock_guard(lockable &l)
|
||||||
|
:l{l}
|
||||||
|
{
|
||||||
|
l.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class lockable>
|
||||||
|
ircd::ctx::unlock_guard<lockable>::~unlock_guard()
|
||||||
|
noexcept
|
||||||
|
{
|
||||||
|
l.lock();
|
||||||
|
}
|
|
@ -444,24 +444,6 @@ until(it_a a,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inverse of std::lock_guard<>
|
|
||||||
template<class lockable>
|
|
||||||
struct unlock_guard
|
|
||||||
{
|
|
||||||
lockable &l;
|
|
||||||
|
|
||||||
unlock_guard(lockable &l)
|
|
||||||
:l{l}
|
|
||||||
{
|
|
||||||
l.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
~unlock_guard() noexcept
|
|
||||||
{
|
|
||||||
l.lock();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr bool
|
constexpr bool
|
||||||
is_powerof2(const long long v)
|
is_powerof2(const long long v)
|
||||||
{
|
{
|
||||||
|
@ -498,7 +480,6 @@ pointers(input_container&& ic,
|
||||||
return pointers(begin(ic), end(ic), begin(oc));
|
return pointers(begin(ic), end(ic), begin(oc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Get what() from exception_ptr
|
/// Get what() from exception_ptr
|
||||||
///
|
///
|
||||||
inline ircd::string_view
|
inline ircd::string_view
|
||||||
|
@ -519,6 +500,5 @@ catch(...)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace ircd
|
} // namespace ircd
|
||||||
|
|
Loading…
Reference in a new issue