From 2fcc135ed60645b200d4d865b826cc0ba71e65f2 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 7 Feb 2020 09:13:55 +0100 Subject: [PATCH] Pursue deprecation of xbt/synchro.h. --- MANIFEST.in | 1 - include/simgrid/simix.h | 4 +- include/xbt/synchro.h | 87 +++++++++++++------ src/simix/libsmx.cpp | 4 +- src/smpi/include/smpi_actor.hpp | 1 - src/smpi/include/smpi_win.hpp | 1 - src/xbt/xbt_os_synchro.cpp | 71 --------------- .../mc/mutex-handling/mutex-handling.cpp | 1 - tools/cmake/DefinePackages.cmake | 1 - 9 files changed, 64 insertions(+), 107 deletions(-) delete mode 100644 src/xbt/xbt_os_synchro.cpp diff --git a/MANIFEST.in b/MANIFEST.in index 2416d0e6ad..8063c6779f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2663,7 +2663,6 @@ include src/xbt/xbt_log_layout_format.cpp include src/xbt/xbt_log_layout_simple.cpp include src/xbt/xbt_main.cpp include src/xbt/xbt_os_file.cpp -include src/xbt/xbt_os_synchro.cpp include src/xbt/xbt_os_time.c include src/xbt/xbt_replay.cpp include src/xbt/xbt_str.cpp diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index e56b0a8b2d..24fbc8e61c 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -198,12 +198,12 @@ XBT_ATTRIB_DEPRECATED_v330("Please use a ActivityImpl* for first parameter") inl /************************** Synchro simcalls **********************************/ SG_BEGIN_DECL -XBT_PUBLIC smx_mutex_t simcall_mutex_init(); +XBT_ATTRIB_DEPRECATED_v330("Please use sg_mutex_init()") XBT_PUBLIC smx_mutex_t simcall_mutex_init(); XBT_PUBLIC void simcall_mutex_lock(smx_mutex_t mutex); XBT_PUBLIC int simcall_mutex_trylock(smx_mutex_t mutex); XBT_PUBLIC void simcall_mutex_unlock(smx_mutex_t mutex); -XBT_PUBLIC smx_cond_t simcall_cond_init(); +XBT_ATTRIB_DEPRECATED_v330("Please use sg_cond_init()") XBT_PUBLIC smx_cond_t simcall_cond_init(); XBT_PUBLIC void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex); XBT_PUBLIC int simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double max_duration); diff --git a/include/xbt/synchro.h b/include/xbt/synchro.h index d882899237..f1b87220d7 100644 --- a/include/xbt/synchro.h +++ b/include/xbt/synchro.h @@ -5,13 +5,15 @@ /* 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. */ -#ifndef XBT_THREAD_H -#define XBT_THREAD_H +#ifndef XBT_SYNCHRO_H +#define XBT_SYNCHRO_H -#include "simgrid/forward.h" -#include +#include "simgrid/cond.h" +#include "simgrid/mutex.h" #include /* SG_BEGIN_DECL */ +#warning xbt/synchro.h is deprecated and will be removed in v3.28. + SG_BEGIN_DECL /** @addtogroup XBT_synchro @@ -27,17 +29,19 @@ SG_BEGIN_DECL /** @brief Thread mutex data type (opaque object) * @hideinitializer */ -#ifdef __cplusplus -typedef simgrid::kernel::activity::MutexImpl* xbt_mutex_t; -#else -typedef struct s_smx_mutex_* xbt_mutex_t; -#endif +typedef sg_mutex_t xbt_mutex_t; /** @brief Creates a new mutex variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_init") XBT_PUBLIC xbt_mutex_t xbt_mutex_init(void); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_init") static inline xbt_mutex_t xbt_mutex_init(void) +{ + return sg_mutex_init(); +} /** @brief Blocks onto the given mutex variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_lock") XBT_PUBLIC void xbt_mutex_acquire(xbt_mutex_t mutex); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_lock") static inline void xbt_mutex_acquire(xbt_mutex_t mutex) +{ + sg_mutex_lock(mutex); +} /** @brief Tries to block onto the given mutex variable * Tries to lock a mutex, return 1 if the mutex is unlocked, else 0. @@ -45,40 +49,69 @@ XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_lock") XBT_PUBLIC void xbt_mutex * @param mutex The mutex * @return 1 - mutex free, 0 - mutex used */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_try_lock") XBT_PUBLIC int xbt_mutex_try_acquire(xbt_mutex_t mutex); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_try_lock") static inline int xbt_mutex_try_acquire(xbt_mutex_t mutex) +{ + return sg_mutex_try_lock(mutex); +} /** @brief Releases the given mutex variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_unlock") XBT_PUBLIC void xbt_mutex_release(xbt_mutex_t mutex); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_unlock") static inline void xbt_mutex_release(xbt_mutex_t mutex) +{ + sg_mutex_unlock(mutex); +} /** @brief Destroys the given mutex variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_destroy") XBT_PUBLIC void xbt_mutex_destroy(xbt_mutex_t mutex); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_destroy") static inline void xbt_mutex_destroy(xbt_mutex_t mutex) +{ + sg_mutex_destroy(mutex); +} /** @brief Thread condition data type (opaque object) * @hideinitializer */ -#ifdef __cplusplus -typedef simgrid::kernel::activity::ConditionVariableImpl* xbt_cond_t; -#else -typedef struct s_smx_cond_* xbt_cond_t; -#endif +typedef sg_cond_t xbt_cond_t; /** @brief Creates a condition variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_init") XBT_PUBLIC xbt_cond_t xbt_cond_init(void); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_init") static inline xbt_cond_t xbt_cond_init(void) +{ + return sg_cond_init(); +} /** @brief Blocks onto the given condition variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_wait") XBT_PUBLIC void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_wait") static inline void xbt_cond_wait(xbt_cond_t cond, + xbt_mutex_t mutex) +{ + sg_cond_wait(cond, mutex); +} + /** @brief Blocks onto the given condition variable, but only for the given amount of time. * @return 0 on success, 1 on timeout */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_wait_for") XBT_PUBLIC - int xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_wait_for") static inline int xbt_cond_timedwait(xbt_cond_t cond, + xbt_mutex_t mutex, + double delay) +{ + return sg_cond_wait_for(cond, mutex, delay); +} + /** @brief Signals the given mutex variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_notify_one") XBT_PUBLIC void xbt_cond_signal(xbt_cond_t cond); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_notify_one") static inline void xbt_cond_signal(xbt_cond_t cond) +{ + sg_cond_notify_one(cond); +} + /** @brief Broadcasts the given mutex variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_notify_all") XBT_PUBLIC void xbt_cond_broadcast(xbt_cond_t cond); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_notify_all") static inline void xbt_cond_broadcast(xbt_cond_t cond) +{ + sg_cond_notify_all(cond); +} + /** @brief Destroys the given mutex variable */ -XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_destroy") XBT_PUBLIC void xbt_cond_destroy(xbt_cond_t cond); +XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_destroy") static inline void xbt_cond_destroy(xbt_cond_t cond) +{ + sg_cond_destroy(cond); +} /** @} */ SG_END_DECL -#endif /* _XBT_THREAD_H */ +#endif /* XBT_SYNCHRO_H */ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 2e4dc45070..e66028a699 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -222,7 +222,7 @@ bool simcall_comm_test(simgrid::kernel::activity::ActivityImpl* comm) * @ingroup simix_synchro_management * */ -smx_mutex_t simcall_mutex_init() +smx_mutex_t simcall_mutex_init() // XBT_ATTRIB_DEPRECATED_v330 { if (simix_global == nullptr) { fprintf(stderr, "You must initialize the SimGrid engine before using it\n"); // We can't use xbt_die since we may @@ -263,7 +263,7 @@ void simcall_mutex_unlock(smx_mutex_t mutex) * @ingroup simix_synchro_management * */ -smx_cond_t simcall_cond_init() +smx_cond_t simcall_cond_init() // XBT_ATTRIB_DEPRECATED_v330 { return simgrid::kernel::actor::simcall([] { return new simgrid::kernel::activity::ConditionVariableImpl(); }); } diff --git a/src/smpi/include/smpi_actor.hpp b/src/smpi/include/smpi_actor.hpp index bd78da2307..61ae4bc128 100644 --- a/src/smpi/include/smpi_actor.hpp +++ b/src/smpi/include/smpi_actor.hpp @@ -9,7 +9,6 @@ #include "private.hpp" #include "simgrid/s4u/Mailbox.hpp" #include "src/instr/instr_smpi.hpp" -#include "xbt/synchro.h" namespace simgrid { namespace smpi { diff --git a/src/smpi/include/smpi_win.hpp b/src/smpi/include/smpi_win.hpp index f9a1206884..84a3f82b53 100644 --- a/src/smpi/include/smpi_win.hpp +++ b/src/smpi/include/smpi_win.hpp @@ -11,7 +11,6 @@ #include "smpi_errhandler.hpp" #include "smpi_f2c.hpp" #include "smpi_keyvals.hpp" -#include "xbt/synchro.h" #include #include diff --git a/src/xbt/xbt_os_synchro.cpp b/src/xbt/xbt_os_synchro.cpp deleted file mode 100644 index 65829c9148..0000000000 --- a/src/xbt/xbt_os_synchro.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* Classical synchro schema, implemented on top of SimGrid */ - -/* Copyright (c) 2007-2020. 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 "simgrid/Exception.hpp" -#include "simgrid/simix.h" /* used implementation */ -#include "src/kernel/activity/ConditionVariableImpl.hpp" -#include "src/kernel/activity/MutexImpl.hpp" -#include "xbt/synchro.h" - -/****** mutex related functions ******/ -xbt_mutex_t xbt_mutex_init(void) -{ - return (xbt_mutex_t)simcall_mutex_init(); -} - -void xbt_mutex_acquire(xbt_mutex_t mutex) -{ - simcall_mutex_lock((smx_mutex_t)mutex); -} - -int xbt_mutex_try_acquire(xbt_mutex_t mutex) -{ - return simcall_mutex_trylock((smx_mutex_t)mutex); -} - -void xbt_mutex_release(xbt_mutex_t mutex) -{ - simcall_mutex_unlock((smx_mutex_t)mutex); -} - -void xbt_mutex_destroy(xbt_mutex_t mutex) -{ - if (mutex != nullptr) - mutex->unref(); -} - -/***** condition related functions *****/ -xbt_cond_t xbt_cond_init(void) -{ - return (xbt_cond_t)simcall_cond_init(); -} - -void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex) -{ - simcall_cond_wait((smx_cond_t)cond, (smx_mutex_t)mutex); -} - -int xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay) -{ - return simcall_cond_wait_timeout((smx_cond_t)cond, (smx_mutex_t)mutex, delay); -} - -void xbt_cond_signal(xbt_cond_t cond) -{ - cond->get_iface()->notify_one(); -} - -void xbt_cond_broadcast(xbt_cond_t cond) -{ - cond->get_iface()->notify_all(); -} - -void xbt_cond_destroy(xbt_cond_t cond) -{ - delete cond; -} diff --git a/teshsuite/mc/mutex-handling/mutex-handling.cpp b/teshsuite/mc/mutex-handling/mutex-handling.cpp index 4e00e3dd73..fe63b5affd 100644 --- a/teshsuite/mc/mutex-handling/mutex-handling.cpp +++ b/teshsuite/mc/mutex-handling/mutex-handling.cpp @@ -23,7 +23,6 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Mailbox.hpp" #include "simgrid/s4u/Mutex.hpp" -#include XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index a0fe3ef0fd..7b922bca9e 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -293,7 +293,6 @@ set(XBT_SRC src/xbt/xbt_log_layout_simple.cpp src/xbt/xbt_main.cpp src/xbt/xbt_os_file.cpp - src/xbt/xbt_os_synchro.cpp src/xbt/xbt_os_time.c src/xbt/xbt_replay.cpp src/xbt/xbt_str.cpp -- 2.20.1