#ifndef SIMGRID_S4U_ACTOR_HPP
#define SIMGRID_S4U_ACTOR_HPP
-#include <atomic>
-#include <chrono>
-#include <functional>
-#include <memory>
-#include <stdexcept>
-#include <string>
-#include <type_traits>
-#include <utility>
-#include <vector>
-
+#include <simgrid/chrono.hpp>
#include <xbt/Extendable.hpp>
#include <xbt/functional.hpp>
-#include <xbt/string.hpp>
#include <xbt/signal.hpp>
-
-#include <simgrid/chrono.hpp>
-#include <simgrid/s4u/forward.hpp>
+#include <xbt/string.hpp>
namespace simgrid {
namespace s4u {
#ifndef SIMGRID_S4U_COMM_HPP
#define SIMGRID_S4U_COMM_HPP
-#include <xbt/asserts.h>
-#include <xbt/base.h>
-#include <xbt/dynar.h>
-
#include <simgrid/forward.h>
#include <simgrid/s4u/Activity.hpp>
-#include <simgrid/s4u/forward.hpp>
-#include <simgrid/simix.h>
#include <atomic>
#include <vector>
* The return value is the rank of the first finished CommPtr. */
static int wait_any(std::vector<CommPtr> * comms) { return wait_any_for(comms, -1); }
/*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/
- static int wait_any_for(std::vector<CommPtr> * comms_in, double timeout)
- {
- // Map to dynar<Synchro*>:
- xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), [](void*ptr){
- intrusive_ptr_release(*(simgrid::kernel::activity::ActivityImpl**)ptr);
- });
- for (auto const& comm : *comms_in) {
- if (comm->state_ == Activity::State::inited)
- comm->start();
- xbt_assert(comm->state_ == Activity::State::started);
- simgrid::kernel::activity::ActivityImpl* ptr = comm->pimpl_.get();
- intrusive_ptr_add_ref(ptr);
- xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, ptr);
- }
- // Call the underlying simcall:
- int idx = simcall_comm_waitany(comms, timeout);
- xbt_dynar_free(&comms);
- return idx;
- }
+ static int wait_any_for(std::vector<CommPtr>* comms_in, double timeout);
/*! take a vector s4u::CommPtr and return when all of them is finished. */
- static void wait_all(std::vector<CommPtr> * comms)
- {
- // TODO: this should be a simcall or something
- // TODO: we are missing a version with timeout
- for (CommPtr comm : *comms) {
- comm->wait();
- }
- }
+ static void wait_all(std::vector<CommPtr>* comms);
/*! take a vector s4u::CommPtr and return the rank of the first finished one (or -1 if none is done). */
static int test_any(std::vector<CommPtr> * comms);
/** Start the comm, and ignore its result. It can be completely forgotten after that. */
Activity* detach(void (*cleanFunction)(void*))
{
- cleanFunction_ = cleanFunction;
+ clean_fun_ = cleanFunction;
return detach();
}
private:
double rate_ = -1;
- void* dstBuff_ = nullptr;
- size_t dstBuffSize_ = 0;
- void* srcBuff_ = nullptr;
- size_t srcBuffSize_ = sizeof(void*);
+ void* dst_buff_ = nullptr;
+ size_t dst_buff_size_ = 0;
+ void* src_buff_ = nullptr;
+ size_t src_buff_size_ = sizeof(void*);
/* FIXME: expose these elements in the API */
int detached_ = 0;
- int (*matchFunction_)(void*, void*, simgrid::kernel::activity::CommImpl*) = nullptr;
- void (*cleanFunction_)(void*) = nullptr;
- void (*copyDataFunction_)(smx_activity_t, void*, size_t) = nullptr;
+ int (*match_fun_)(void*, void*, simgrid::kernel::activity::CommImpl*) = nullptr;
+ void (*clean_fun_)(void*) = nullptr;
+ void (*copy_data_function_)(smx_activity_t, void*, size_t) = nullptr;
smx_actor_t sender_ = nullptr;
smx_actor_t receiver_ = nullptr;
std::atomic_int_fast32_t refcount_{0};
};
-}
-} // namespace simgrid::s4u
+} // namespace s4u
+} // namespace simgrid
#endif /* SIMGRID_S4U_COMM_HPP */
#ifndef SIMGRID_S4U_COND_VARIABLE_HPP
#define SIMGRID_S4U_COND_VARIABLE_HPP
-#include <chrono>
-#include <condition_variable>
-#include <future>
-#include <mutex>
-#include <utility> // std::swap
-
-#include <boost/intrusive_ptr.hpp>
-
-#include <xbt/base.h>
-
#include <simgrid/chrono.hpp>
#include <simgrid/s4u/Mutex.hpp>
-#include <simgrid/simix.h>
+
+#include <future>
namespace simgrid {
namespace s4u {
#include <simgrid/forward.h>
#include <simgrid/s4u/Activity.hpp>
-#include <simgrid/s4u/forward.hpp>
#include <atomic>
#ifndef SIMGRID_S4U_MUTEX_HPP
#define SIMGRID_S4U_MUTEX_HPP
-#include <mutex>
-#include <utility>
-
-#include <boost/intrusive_ptr.hpp>
-
-#include <simgrid/simix.h>
-#include <xbt/base.h>
+#include <simgrid/forward.h>
+#include <xbt/asserts.h>
namespace simgrid {
namespace s4u {
simgrid::kernel::activity::MutexImpl* mutex_;
explicit Mutex(simgrid::kernel::activity::MutexImpl * mutex) : mutex_(mutex) {}
- /* refcounting of the intrusive_ptr is delegated to the implementation object */
- friend void intrusive_ptr_add_ref(Mutex* mutex)
- {
- xbt_assert(mutex);
- SIMIX_mutex_ref(mutex->mutex_);
- }
- friend void intrusive_ptr_release(Mutex* mutex)
- {
- xbt_assert(mutex);
- SIMIX_mutex_unref(mutex->mutex_);
- }
+ /* refcounting */
+ friend void intrusive_ptr_add_ref(Mutex* mutex);
+ friend void intrusive_ptr_release(Mutex* mutex);
+
public:
using Ptr = boost::intrusive_ptr<Mutex>;
#ifndef XBT_OS_THREAD_H
#define XBT_OS_THREAD_H
-SG_BEGIN_DECL()
-
#include <xbt/base.h>
+#include <xbt/function_types.h>
#include <pthread.h>
+SG_BEGIN_DECL()
+
typedef pthread_key_t xbt_os_thread_key_t;
/** @addtogroup XBT_thread
/* A thread pool (C++ version). */
-/* Copyright (c) 2004-2018 The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2004-2018 The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "src/internal_config.h" // HAVE_FUTEX_H
#include "src/kernel/context/Context.hpp"
-#include <atomic>
+
#include <boost/optional.hpp>
-#include <simgrid/simix.h>
-#include <vector>
-#include <xbt/log.h>
-#include <xbt/parmap.h>
-#include <xbt/xbt_os_thread.h>
#if HAVE_FUTEX_H
-#include <limits>
#include <linux/futex.h>
#include <sys/syscall.h>
#endif
#include "Context.hpp"
#include "src/internal_config.h"
-#include "src/simix/smx_private.hpp"
namespace simgrid {
namespace kernel {
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "ContextRaw.hpp"
-
#include "mc/mc.h"
+#include "src/simix/smx_private.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
#include <functional>
#include <vector>
-#include <simgrid/simix.hpp>
#include <xbt/parmap.hpp>
#include <xbt/xbt_os_thread.h>
-#include "Context.hpp"
-#include "src/internal_config.h"
-#include "src/simix/smx_private.hpp"
-
namespace simgrid {
namespace kernel {
namespace context {
}
}
+int Comm::wait_any_for(std::vector<CommPtr>* comms_in, double timeout)
+{
+ // Map to dynar<Synchro*>:
+ xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), [](void* ptr) {
+ intrusive_ptr_release(*(simgrid::kernel::activity::ActivityImpl**)ptr);
+ });
+ for (auto const& comm : *comms_in) {
+ if (comm->state_ == Activity::State::inited)
+ comm->start();
+ xbt_assert(comm->state_ == Activity::State::started);
+ simgrid::kernel::activity::ActivityImpl* ptr = comm->pimpl_.get();
+ intrusive_ptr_add_ref(ptr);
+ xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, ptr);
+ }
+ // Call the underlying simcall:
+ int idx = simcall_comm_waitany(comms, timeout);
+ xbt_dynar_free(&comms);
+ return idx;
+}
+
+void Comm::wait_all(std::vector<CommPtr>* comms)
+{
+ // TODO: this should be a simcall or something
+ // TODO: we are missing a version with timeout
+ for (CommPtr comm : *comms) {
+ comm->wait();
+ }
+}
+
Activity* Comm::set_rate(double rate)
{
xbt_assert(state_ == State::inited);
Activity* Comm::set_src_data(void* buff)
{
xbt_assert(state_ == State::inited);
- xbt_assert(dstBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
- srcBuff_ = buff;
+ xbt_assert(dst_buff_ == nullptr, "Cannot set the src and dst buffers at the same time");
+ src_buff_ = buff;
return this;
}
Activity* Comm::set_src_data_size(size_t size)
{
xbt_assert(state_ == State::inited);
- srcBuffSize_ = size;
+ src_buff_size_ = size;
return this;
}
Activity* Comm::set_src_data(void* buff, size_t size)
{
xbt_assert(state_ == State::inited);
- xbt_assert(dstBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
- srcBuff_ = buff;
- srcBuffSize_ = size;
+ xbt_assert(dst_buff_ == nullptr, "Cannot set the src and dst buffers at the same time");
+ src_buff_ = buff;
+ src_buff_size_ = size;
return this;
}
Activity* Comm::set_dst_data(void** buff)
{
xbt_assert(state_ == State::inited);
- xbt_assert(srcBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
- dstBuff_ = buff;
+ xbt_assert(src_buff_ == nullptr, "Cannot set the src and dst buffers at the same time");
+ dst_buff_ = buff;
return this;
}
size_t Comm::get_dst_data_size()
{
xbt_assert(state_ == State::finished);
- return dstBuffSize_;
+ return dst_buff_size_;
}
Activity* Comm::set_dst_data(void** buff, size_t size)
{
xbt_assert(state_ == State::inited);
- xbt_assert(srcBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
- dstBuff_ = buff;
- dstBuffSize_ = size;
+ xbt_assert(src_buff_ == nullptr, "Cannot set the src and dst buffers at the same time");
+ dst_buff_ = buff;
+ dst_buff_size_ = size;
return this;
}
{
xbt_assert(state_ == State::inited);
- if (srcBuff_ != nullptr) { // Sender side
- pimpl_ = simcall_comm_isend(sender_, mailbox_->get_impl(), remains_, rate_, srcBuff_, srcBuffSize_, matchFunction_,
- cleanFunction_, copyDataFunction_, user_data_, detached_);
- } else if (dstBuff_ != nullptr) { // Receiver side
+ if (src_buff_ != nullptr) { // Sender side
+ pimpl_ = simcall_comm_isend(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_,
+ clean_fun_, copy_data_function_, user_data_, detached_);
+ } else if (dst_buff_ != nullptr) { // Receiver side
xbt_assert(not detached_, "Receive cannot be detached");
- pimpl_ = simcall_comm_irecv(receiver_, mailbox_->get_impl(), dstBuff_, &dstBuffSize_, matchFunction_,
- copyDataFunction_, user_data_, rate_);
+ pimpl_ = simcall_comm_irecv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_,
+ copy_data_function_, user_data_, rate_);
} else {
xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver");
return this;
case State::inited: // It's not started yet. Do it in one simcall
- if (srcBuff_ != nullptr) {
- simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, srcBuff_, srcBuffSize_, matchFunction_,
- copyDataFunction_, user_data_, timeout);
+ if (src_buff_ != nullptr) {
+ simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_,
+ copy_data_function_, user_data_, timeout);
} else { // Receiver
- simcall_comm_recv(receiver_, mailbox_->get_impl(), dstBuff_, &dstBuffSize_, matchFunction_, copyDataFunction_,
+ simcall_comm_recv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_, copy_data_function_,
user_data_, timeout, rate_);
}
state_ = State::finished;
Activity* Comm::detach()
{
xbt_assert(state_ == State::inited, "You cannot detach communications once they are started (not implemented).");
- xbt_assert(srcBuff_ != nullptr && srcBuffSize_ != 0, "You can only detach sends, not recvs");
+ xbt_assert(src_buff_ != nullptr && src_buff_size_ != 0, "You can only detach sends, not recvs");
detached_ = true;
return start();
}
{
s4u::CommPtr res = put_init();
res->set_remaining(simulatedSize);
- res->srcBuff_ = data;
- res->srcBuffSize_ = sizeof(void*);
+ res->src_buff_ = data;
+ res->src_buff_size_ = sizeof(void*);
return res;
}
s4u::CommPtr Mailbox::put_async(void* payload, uint64_t simulatedSize)
return MutexPtr(&mutex->mutex(), false);
}
+/* refcounting of the intrusive_ptr is delegated to the implementation object */
+void intrusive_ptr_add_ref(Mutex* mutex)
+{
+ xbt_assert(mutex);
+ SIMIX_mutex_ref(mutex->mutex_);
+}
+void intrusive_ptr_release(Mutex* mutex)
+{
+ xbt_assert(mutex);
+ SIMIX_mutex_unref(mutex->mutex_);
+}
}
}
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <xbt/base.h>
-
#include "cpu_interface.hpp"
+#include "xbt/base.h"
/***********
* Classes *
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/plugins/live_migration.h"
-#include "simgrid/s4u.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
-#include <map>
namespace simgrid {
namespace vm {
#include "simgrid/plugins/dvfs.h"
#include "simgrid/plugins/load.h"
-#include "simgrid/simix.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
-#include "src/surf/cpu_interface.hpp"
+#include <xbt/config.hpp>
#include <boost/algorithm/string.hpp>
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <simgrid/s4u/Engine.hpp>
-#include <string>
-#include <utility>
-#include <vector>
-#include <xbt/config.hpp>
/** @addtogroup SURF_plugin_load
#include "simgrid/plugins/energy.h"
#include "simgrid/plugins/load.h"
-#include "simgrid/simix.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
#include "src/surf/cpu_interface.hpp"
-
#include "simgrid/s4u/Engine.hpp"
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
-#include <string>
-#include <utility>
-#include <vector>
/** @addtogroup plugin_energy
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/plugins/load.h"
-#include "simgrid/simix.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
-#include "src/surf/cpu_interface.hpp"
-
-#include "simgrid/s4u/Engine.hpp"
-
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <string>
-#include <utility>
-#include <vector>
/** @addtogroup plugin_load
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
-#include <string>
/** @addtogroup SURF_plugin_energy