X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a55753238274cb77d9a28dd98176eb95119eaa27..222e031aa69b85a660b37e558115375d44ec3f68:/include/simgrid/s4u/Mailbox.hpp diff --git a/include/simgrid/s4u/Mailbox.hpp b/include/simgrid/s4u/Mailbox.hpp index 79a9c15672..f42bd58038 100644 --- a/include/simgrid/s4u/Mailbox.hpp +++ b/include/simgrid/s4u/Mailbox.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2021. 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. */ @@ -8,9 +8,11 @@ #include #include +#include #include #include +#include #include namespace simgrid { @@ -94,30 +96,50 @@ public: /** Creates (but don't start) a data reception onto that mailbox */ CommPtr get_init(); /** Creates and start an async data reception to that mailbox */ - CommPtr get_async(void** data); - template CommPtr get_async(T** data) { return get_async(reinterpret_cast(data)); } + XBT_ATTRIB_DEPRECATED_v331("Please use typed template Mailbox::get_async<>()") CommPtr get_async(void** data); + template CommPtr get_async(T** data); /** Blocking data reception */ - void* get(); - template T* get() { return static_cast(get()); } + template T* get(); + XBT_ATTRIB_DEPRECATED_v331("Please use typed template Mailbox::get<>()") void* get(); + template std::unique_ptr get_unique() { return std::unique_ptr(get()); } + /** Blocking data reception with timeout */ - void* get(double timeout); - template T* get(double timeout) { return static_cast(get(timeout)); } + template T* get(double timeout); + XBT_ATTRIB_DEPRECATED_v331("Please use typed template Mailbox::get<>()") void* get(double timeout); + template std::unique_ptr get_unique(double timeout) { return std::unique_ptr(get(timeout)); } }; -template <> CommPtr Mailbox::get_async(void** data); -template <> void* Mailbox::get(); -template <> void* Mailbox::get(double timeout); +template CommPtr Mailbox::get_async(T** data) +{ + CommPtr res = get_init()->set_dst_data(reinterpret_cast(data), sizeof(void*)); + res->vetoable_start(); + return res; +} + +template T* Mailbox::get() +{ + T* res = nullptr; + get_async(&res)->wait(); + return res; +} + +template T* Mailbox::get(double timeout) +{ + T* res = nullptr; + get_async(&res)->wait_for(timeout); + return res; +} -inline CommPtr Mailbox::get_async(void** data) +inline CommPtr Mailbox::get_async(void** data) // XBT_ATTRIB_DEPRECATED_v331 { return get_async(data); } -inline void* Mailbox::get() +inline void* Mailbox::get() // XBT_ATTRIB_DEPRECATED_v331 { return get(); } -inline void* Mailbox::get(double timeout) +inline void* Mailbox::get(double timeout) // XBT_ATTRIB_DEPRECATED_v331 { return get(timeout); }