// Matrix Construct // // Copyright (C) Matrix Construct Developers, Authors & Contributors // Copyright (C) 2016-2018 Jason Volk // // 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_SHARED_STATE_H namespace ircd::ctx { struct shared_state_base; template struct shared_state; template<> struct shared_state; template struct promise; template<> struct promise; template bool invalid(const shared_state &); template bool pending(const shared_state &); template bool ready(const shared_state &); template void set_ready(shared_state &); } struct ircd::ctx::shared_state_base { mutable dock cond; std::exception_ptr eptr; }; template struct ircd::ctx::shared_state :shared_state_base { using value_type = T; using pointer_type = T *; using reference_type = T &; promise *p {nullptr}; T val; }; template<> struct ircd::ctx::shared_state :shared_state_base { using value_type = void; promise *p {nullptr}; }; template void ircd::ctx::set_ready(shared_state &st) { st.p = reinterpret_cast *>(uintptr_t(0x42)); } template bool ircd::ctx::ready(const shared_state &st) { return st.p == reinterpret_cast *>(uintptr_t(0x42)); } template bool ircd::ctx::pending(const shared_state &st) { return st.p > reinterpret_cast *>(uintptr_t(0x42)); } template bool ircd::ctx::invalid(const shared_state &st) { return st.p == nullptr; }