Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4bc010f956c1e59ca341c0a3fb6d5f9216554ce5
[simgrid.git] / src / kernel / activity / MessageQueueImpl.hpp
1 /* Copyright (c) 2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_KERNEL_ACTIVITY_MESSAGEQUEUE_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_MESSAGEQUEUE_HPP
8
9 #include "simgrid/s4u/Engine.hpp"
10 #include "simgrid/s4u/MessageQueue.hpp"
11 #include "src/kernel/activity/MessImpl.hpp"
12
13 namespace simgrid::kernel::activity {
14
15 /** @brief Implementation of the s4u::MessageQueue */
16
17 class MessageQueueImpl {
18   s4u::MessageQueue piface_;
19   std::string name_;
20   std::deque<MessImplPtr> queue_;
21
22   friend s4u::Engine;
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);
26
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;
32
33 public:
34   /** @brief Public interface */
35   unsigned get_id() const { return id_; }
36
37   const s4u::MessageQueue* get_iface() const { return &piface_; }
38   s4u::MessageQueue* get_iface() { return &piface_; }
39
40   const std::string& get_name() const { return name_; }
41   const char* get_cname() const { return name_.c_str(); }
42   void push(const MessImplPtr& mess);
43   void remove(const MessImplPtr& mess);
44   bool empty() const { return queue_.empty(); }
45   size_t size() const { return queue_.size(); }
46   const MessImplPtr& front() const { return queue_.front(); }
47
48   MessImplPtr find_matching_message(MessImplType type);
49 };
50 } // namespace simgrid::kernel::activity
51
52 #endif