From e04e3ae8fec7cb28eef7705e4aebf2370e6fdd6a Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 12 Dec 2019 21:54:17 +0100 Subject: [PATCH] Make mailbox matching functions return a bool. --- include/simgrid/s4u/Comm.hpp | 2 +- include/simgrid/s4u/Mailbox.hpp | 2 +- include/simgrid/simix.h | 10 +++++----- src/kernel/activity/CommImpl.cpp | 11 ++++++----- src/kernel/activity/CommImpl.hpp | 2 +- src/kernel/activity/MailboxImpl.cpp | 4 ++-- src/kernel/activity/MailboxImpl.hpp | 4 ++-- src/s4u/s4u_Mailbox.cpp | 2 +- src/simix/libsmx.cpp | 10 +++++----- src/simix/popping_private.hpp | 2 +- src/smpi/include/smpi_request.hpp | 4 ++-- src/smpi/mpi/smpi_request.cpp | 15 ++++++++------- 12 files changed, 35 insertions(+), 33 deletions(-) diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 153be7e069..1b3668298a 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -30,7 +30,7 @@ class XBT_PUBLIC Comm : public Activity_T { std::string tracing_category_ = ""; /* FIXME: expose these elements in the API */ bool detached_ = false; - int (*match_fun_)(void*, void*, kernel::activity::CommImpl*) = nullptr; + bool (*match_fun_)(void*, void*, kernel::activity::CommImpl*) = nullptr; void (*clean_fun_)(void*) = nullptr; void (*copy_data_function_)(kernel::activity::CommImpl*, void*, size_t) = nullptr; diff --git a/include/simgrid/s4u/Mailbox.hpp b/include/simgrid/s4u/Mailbox.hpp index 989ae54d3c..94a58bc4b6 100644 --- a/include/simgrid/s4u/Mailbox.hpp +++ b/include/simgrid/s4u/Mailbox.hpp @@ -80,7 +80,7 @@ public: /** Creates and start a data transmission to that mailbox */ CommPtr put_async(void* data, uint64_t simulated_size_in_bytes); - smx_activity_t iprobe(int type, int (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data); + smx_activity_t iprobe(int type, bool (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data); /** Blocking data transmission */ void put(void* payload, uint64_t simulated_size_in_bytes); /** Blocking data transmission with timeout */ diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 4adb5c061d..382682fbc8 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -138,30 +138,30 @@ SG_END_DECL #ifdef __cplusplus XBT_PUBLIC void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout); XBT_PUBLIC smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*clean_fun)(void*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, bool detached); XBT_PUBLIC void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout, double rate); XBT_PUBLIC smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double rate); XBT_PUBLIC smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* data); /* FIXME: waitany is going to be a vararg function, and should take a timeout */ diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index e6cc960d2b..63aeb0213b 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related syn XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t src, smx_mailbox_t mbox, double task_size, double rate, unsigned char* src_buff, size_t src_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout) { @@ -32,7 +32,8 @@ XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t sr XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend( smx_simcall_t /*simcall*/, smx_actor_t src_proc, smx_mailbox_t mbox, double task_size, double rate, - unsigned char* src_buff, size_t src_buff_size, int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + unsigned char* src_buff, size_t src_buff_size, + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), // used to copy data if not default one void* data, bool detached) @@ -98,7 +99,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend( XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout, double rate) { @@ -110,8 +111,8 @@ XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t re XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv( smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size, - simix_match_func_t match_fun, void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), - void* data, double rate) + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double rate) { simgrid::kernel::activity::CommImplPtr this_synchro = simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl()); diff --git a/src/kernel/activity/CommImpl.hpp b/src/kernel/activity/CommImpl.hpp index 7c0691aece..82368ff370 100644 --- a/src/kernel/activity/CommImpl.hpp +++ b/src/kernel/activity/CommImpl.hpp @@ -58,7 +58,7 @@ public: #endif void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */ - int (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when + bool (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when looking if a given communication matches my needs. For that, myself must match the expectations of the other side, too. See */ void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr; diff --git a/src/kernel/activity/MailboxImpl.cpp b/src/kernel/activity/MailboxImpl.cpp index 3137c62f3e..8915ec71de 100644 --- a/src/kernel/activity/MailboxImpl.cpp +++ b/src/kernel/activity/MailboxImpl.cpp @@ -85,7 +85,7 @@ void MailboxImpl::remove(const CommImplPtr& comm) xbt_die("Comm %p not found in mailbox %s", comm.get(), this->get_cname()); } -CommImplPtr MailboxImpl::iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data) +CommImplPtr MailboxImpl::iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data) { XBT_DEBUG("iprobe from %p %p", this, &comm_queue_); @@ -122,7 +122,7 @@ CommImplPtr MailboxImpl::iprobe(int type, int (*match_fun)(void*, void*, CommImp * @param remove_matching whether or not to clean the found object from the queue * @return The communication activity if found, nullptr otherwise */ -CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, int (*match_fun)(void*, void*, CommImpl*), +CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, bool (*match_fun)(void*, void*, CommImpl*), void* this_user_data, const CommImplPtr& my_synchro, bool done, bool remove_matching) { diff --git a/src/kernel/activity/MailboxImpl.hpp b/src/kernel/activity/MailboxImpl.hpp index ac05e6688e..5cb5a9f95e 100644 --- a/src/kernel/activity/MailboxImpl.hpp +++ b/src/kernel/activity/MailboxImpl.hpp @@ -42,8 +42,8 @@ public: void set_receiver(s4u::ActorPtr actor); void push(CommImplPtr comm); void remove(const CommImplPtr& comm); - CommImplPtr iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data); - CommImplPtr find_matching_comm(CommImpl::Type type, int (*match_fun)(void*, void*, CommImpl*), void* this_user_data, + CommImplPtr iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data); + CommImplPtr find_matching_comm(CommImpl::Type type, bool (*match_fun)(void*, void*, CommImpl*), void* this_user_data, const CommImplPtr& my_synchro, bool done, bool remove_matching); actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached diff --git a/src/s4u/s4u_Mailbox.cpp b/src/s4u/s4u_Mailbox.cpp index 95c0ab097f..0ab6de72a2 100644 --- a/src/s4u/s4u_Mailbox.cpp +++ b/src/s4u/s4u_Mailbox.cpp @@ -150,7 +150,7 @@ void* Mailbox::get(double timeout) return res; } -smx_activity_t Mailbox::iprobe(int type, int (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data) +smx_activity_t Mailbox::iprobe(int type, bool (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data) { return kernel::actor::simcall([this, type, match_fun, data] { return pimpl_->iprobe(type, match_fun, data); }); } diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 42988e9c0e..9410c2fcd1 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -65,7 +65,7 @@ e_smx_state_t simcall_process_sleep(double duration) // XBT_DEPRECATED_v329 * @ingroup simix_comm_management */ void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, - size_t src_buff_size, int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + size_t src_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout) { @@ -95,7 +95,7 @@ void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, */ smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*clean_fun)(void*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, bool detached) @@ -114,7 +114,7 @@ smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double * @ingroup simix_comm_management */ void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout, double rate) { @@ -138,7 +138,7 @@ void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, * @ingroup simix_comm_management */ smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double rate) { @@ -152,7 +152,7 @@ smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void * @ingroup simix_comm_management */ smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type, - int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* data) + bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* data) { xbt_assert(mbox, "No rendez-vous point defined for iprobe"); diff --git a/src/simix/popping_private.hpp b/src/simix/popping_private.hpp index 26a3cbc7da..1a7ce1c50e 100644 --- a/src/simix/popping_private.hpp +++ b/src/simix/popping_private.hpp @@ -16,7 +16,7 @@ XBT_PUBLIC_DATA const char* simcall_names[]; /* Name of each simcall */ -typedef int (*simix_match_func_t)(void*, void*, simgrid::kernel::activity::CommImpl*); +typedef bool (*simix_match_func_t)(void*, void*, simgrid::kernel::activity::CommImpl*); typedef void (*simix_copy_data_func_t)(simgrid::kernel::activity::CommImpl*, void*, size_t); typedef void (*simix_clean_func_t)(void*); typedef void (*FPtr)(void); // Hide the ugliness diff --git a/src/smpi/include/smpi_request.hpp b/src/smpi/include/smpi_request.hpp index cc6458393c..62d1ae2fdd 100644 --- a/src/smpi/include/smpi_request.hpp +++ b/src/smpi/include/smpi_request.hpp @@ -111,8 +111,8 @@ public: static int waitall(int count, MPI_Request requests[], MPI_Status status[]); static int waitsome(int incount, MPI_Request requests[], int* indices, MPI_Status status[]); - static int match_send(void* a, void* b, kernel::activity::CommImpl* ignored); - static int match_recv(void* a, void* b, kernel::activity::CommImpl* ignored); + static bool match_send(void* a, void* b, kernel::activity::CommImpl* ignored); + static bool match_recv(void* a, void* b, kernel::activity::CommImpl* ignored); static int grequest_start( MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn, MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request); static int grequest_complete( MPI_Request request); diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index c9071556cf..6011cd72e6 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -108,7 +108,7 @@ void Request::unref(MPI_Request* request) } } -int Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*) +bool Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*) { MPI_Request ref = static_cast(a); MPI_Request req = static_cast(b); @@ -131,11 +131,12 @@ int Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*) if(req->cancelled_==0) req->cancelled_ = -1; // mark as uncancelable XBT_DEBUG("match succeeded"); - return 1; - }else return 0; + return true; + } + return false; } -int Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*) +bool Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*) { MPI_Request ref = static_cast(a); MPI_Request req = static_cast(b); @@ -157,9 +158,9 @@ int Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*) if(req->cancelled_==0) req->cancelled_ = -1; // mark as uncancelable XBT_DEBUG("match succeeded"); - return 1; - } else - return 0; + return true; + } + return false; } void Request::print_request(const char *message) -- 2.20.1