Files
wlan-cloud-lib-poco/Foundation/include/Poco/AtomicFlag.h
Aleksandar Fabijanic 4efaa99fff Add WeakRefPtr to Foundation #2246 (#2247)
* Logger & Channel classes now using AutoPtr<Channel> instead of Channel* (API improvement)

* fix CachingChannel

* more fixes

* Configuration: remove raw pointers from interfaces #2077

* Add WeakPtr to Foundation #2246

* Add WeakPtr to Foundation #2246 (buildsystems files)

* Add WeakPtr to Foundation #2246 (x64 VS project files)

* backtrace and Event fixes

* add ordered map

* add ordered set

* add sanitize makefiles

* update RefPtr doc

* fix AtomicCounter includes

* add ordered containers tests

* fix xml test compile error

* remove operator bool rom smart pointers

* Poco::strToInt<> fails for values right above the type's boundary / limit #2250

* add g++ -ftrapv config

* remove Version.h includes (now included from Config.h)

* comment out offending SQLite test (TODO)

* add AtomicFlag and SpinlockMutex

* remove RefCountedObject include from RefPtr and WeakRefPtr mutex template param

* add WeakRef SpinLockMutex threading test

* WeakRefPtr, backtrace, NDC, refcount DC fixes

* SQL fixes

* update RCO documentation

* XML/DOM: Remove raw pointers from public interfaces #2075

* few fixes

* PocoDoc - make logger non-static reference member

* remove path char array initialization

* Fix failing unit test, adding d in debug mode for TestApp and TestLibrary

* fix application config pointer

* fix some crypto warnings

* fix Process tests and consolidate TestApp name building

* define PathImpl::selfImpl for WinCE

* restore WinCE test app name extension

* attempt to passify 32 bit clang

* fix failing Active* tests

* Add POCO_OS_ANDROID support for Path::self()

* Add build dependencies between Foundation-testrunner and TestApp, TestLibrary in cmake build

* Remove to set LD_LIBRARY_PATH on foundation test

* revert to develop XML

* fix VS150 env not found (hardcode it)

* undef min/max
2018-05-02 16:04:39 -06:00

118 lines
2.2 KiB
C++

//
// AtomicFlag.h
//
// Library: Foundation
// Package: Core
// Module: AtomicFlag
//
// Definition of the AtomicFlag class.
//
// Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Foundation_AtomicFlag_INCLUDED
#define Foundation_AtomicFlag_INCLUDED
#include "Poco/Foundation.h"
#include <atomic>
namespace Poco {
class AtomicFlag
/// This class implements an atomic boolean flag by wrapping
/// the std::atomic_flag. It is guaranteed to be thread-safe
/// and lock-free.
///
/// Only default-construction is allowed, objects of this
/// class are not copyable, assignable or movable.
///
/// Note that this class is not a replacement for (atomic)
/// bool type because its value can not be read without also
/// being set to true. However, after being set (either
/// explicitly, through the set() call or implicitly, via
/// operator bool()), it can be reset and reused.
///
/// The class is useful in scenarios such as busy-wait or
/// one-off code blocks, e.g.:
///
/// class MyClass
/// {
/// public:
/// void myFunc()
/// {
/// if (!_beenHere) doOnce();
/// doMany();
/// }
///
/// void doOnce() { /* executed once */ }
///
/// void doMany() { /* executed multiple times */ }
///
/// private:
/// AtomicFlag _beenHere;
/// }
///
/// MyClass myClass;
/// int i = 0;
/// while (++i < 10) myClass.myFunc();
{
public:
AtomicFlag() {}
~AtomicFlag() {}
bool set();
/// Sets the flag to true and returns previously
/// held value.
void reset();
/// Resets the flag to false.
operator bool ();
/// Sets the flag to true and returns previously
/// held value.
private:
AtomicFlag(const AtomicFlag&) = delete;
AtomicFlag& operator = (const AtomicFlag&) = delete;
AtomicFlag(AtomicFlag&&) = delete;
AtomicFlag& operator = (AtomicFlag&&) = delete;
std::atomic_flag _flag = ATOMIC_FLAG_INIT;
};
//
// inlines
//
inline bool AtomicFlag::set()
{
return _flag.test_and_set(std::memory_order_acquire);
}
inline void AtomicFlag::reset()
{
_flag.clear(std::memory_order_release);
}
inline AtomicFlag::operator bool ()
{
return set();
}
} // namespace Poco
#endif // Foundation_AtomicFlag_INCLUDED