2018-11-11 23:13:37 +01:00
|
|
|
// 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_CTX_CRITICAL_INDICATOR_H
|
|
|
|
|
2019-06-23 08:08:46 +02:00
|
|
|
namespace ircd::ctx {
|
|
|
|
inline namespace this_ctx
|
2018-11-11 23:13:37 +01:00
|
|
|
{
|
2018-11-30 01:12:33 +01:00
|
|
|
struct critical_indicator; // Indicates if yielding happened for a section
|
2019-06-23 08:08:46 +02:00
|
|
|
}}
|
2018-11-11 23:13:37 +01:00
|
|
|
|
|
|
|
/// An instance of critical_indicator reports if context switching happened.
|
|
|
|
///
|
|
|
|
/// A critical_indicator remains true after construction until a context switch
|
|
|
|
/// has occurred. It then becomes false. This is not an assertion and is
|
|
|
|
/// available in optimized builds for real use. For example, a context may
|
|
|
|
/// want to recompute some value after a context switch and opportunistically
|
|
|
|
/// skip this effort when this indicator shows no switch occurred.
|
|
|
|
///
|
|
|
|
class ircd::ctx::this_ctx::critical_indicator
|
|
|
|
{
|
|
|
|
uint64_t state;
|
|
|
|
|
|
|
|
public:
|
2019-05-26 11:18:14 +02:00
|
|
|
uint64_t count() const { return epoch(cur()) - state; }
|
|
|
|
operator bool() const { return epoch(cur()) == state; }
|
2018-11-11 23:13:37 +01:00
|
|
|
|
|
|
|
critical_indicator()
|
2019-05-26 11:18:14 +02:00
|
|
|
:state(epoch(cur()))
|
2018-11-11 23:13:37 +01:00
|
|
|
{}
|
|
|
|
};
|