1 /* Copyright (c) 2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_KERNEL_ACTIVITY_MESSAGEQUEUE_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_MESSAGEQUEUE_HPP
9 #include "simgrid/s4u/Engine.hpp"
10 #include "simgrid/s4u/MessageQueue.hpp"
11 #include "src/kernel/activity/MessImpl.hpp"
13 namespace simgrid::kernel::activity {
15 /** @brief Implementation of the s4u::MessageQueue */
17 class MessageQueueImpl {
18 s4u::MessageQueue piface_;
20 std::deque<MessImplPtr> queue_;
23 friend s4u::MessageQueue;
24 friend s4u::MessageQueue* s4u::Engine::message_queue_by_name_or_create(const std::string& name) const;
25 friend s4u::MessageQueue* s4u::MessageQueue::by_name(const std::string& name);
27 static unsigned next_id_; // Next ID to be given
28 const unsigned id_ = next_id_++;
29 explicit MessageQueueImpl(const std::string& name) : piface_(this), name_(name) {}
30 MessageQueueImpl(const MailboxImpl&) = delete;
31 MessageQueueImpl& operator=(const MailboxImpl&) = delete;
36 /** @brief Public interface */
37 unsigned get_id() const { return id_; }
39 const s4u::MessageQueue* get_iface() const { return &piface_; }
40 s4u::MessageQueue* get_iface() { return &piface_; }
42 const std::string& get_name() const { return name_; }
43 const char* get_cname() const { return name_.c_str(); }
44 void push(const MessImplPtr& mess);
45 void remove(const MessImplPtr& mess);
47 bool empty() const { return queue_.empty(); }
48 size_t size() const { return queue_.size(); }
49 const MessImplPtr& front() const { return queue_.front(); }
51 MessImplPtr find_matching_message(MessImplType type);
53 } // namespace simgrid::kernel::activity