/usr/include/caf/abstract_channel.hpp is in libcaf-dev 0.13.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | /******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_ABSTRACT_CHANNEL_HPP
#define CAF_ABSTRACT_CHANNEL_HPP
#include <atomic>
#include "caf/fwd.hpp"
#include "caf/node_id.hpp"
#include "caf/message_id.hpp"
#include "caf/ref_counted.hpp"
namespace caf {
/**
* Interface for all message receivers. * This interface describes an
* entity that can receive messages and is implemented by {@link actor}
* and {@link group}.
*/
class abstract_channel : public ref_counted {
public:
friend class abstract_actor;
friend class abstract_group;
virtual ~abstract_channel();
/**
* Enqueues a new message to the channel.
*/
virtual void enqueue(const actor_addr& sender, message_id mid,
message content, execution_unit* host) = 0;
/**
* Enqueues a new message wrapped in a `mailbox_element` to the channel.
* This variant is used by actors whenever it is possible to allocate
* mailbox element and message on the same memory block and is thus
* more efficient. Non-actors use the default implementation which simply
* calls the pure virtual version.
*/
virtual void enqueue(mailbox_element_ptr what, execution_unit* host);
/**
* Returns the ID of the node this actor is running on.
*/
inline node_id node() const {
return m_node;
}
/**
* Returns true if {@link node_ptr} returns
*/
bool is_remote() const;
static constexpr int is_abstract_actor_flag = 0x100000;
static constexpr int is_abstract_group_flag = 0x200000;
inline bool is_abstract_actor() const {
return static_cast<bool>(flags() & is_abstract_actor_flag);
}
inline bool is_abstract_group() const {
return static_cast<bool>(flags() & is_abstract_group_flag);
}
protected:
// note: *both* operations use relaxed memory order, this is because
// only the actor itself is granted write access while all access
// from other actors or threads is always read-only; further, only
// flags that are considered constant after an actor has launched are
// read by others, i.e., there is no acquire/release semantic between
// setting and reading flags
inline int flags() const {
return m_flags.load(std::memory_order_relaxed);
}
inline void flags(int new_value) {
m_flags.store(new_value, std::memory_order_relaxed);
}
private:
// can only be called from abstract_actor and abstract_group
abstract_channel(int init_flags);
abstract_channel(int init_flags, node_id nid);
/*
* Accumulates several state and type flags. Subtypes may use only the
* first 20 bits, i.e., the bitmask 0xFFF00000 is reserved for
* channel-related flags.
*/
std::atomic<int> m_flags;
// identifies the node of this channel
node_id m_node;
};
/**
* A smart pointer to an abstract channel.
* @relates abstract_channel_ptr
*/
using abstract_channel_ptr = intrusive_ptr<abstract_channel>;
} // namespace caf
#endif // CAF_ABSTRACT_CHANNEL_HPP
|