From 3eaab01ff3aaf3b8addf247073237c5891f485d4 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 28 Jun 2017 10:51:54 +0200 Subject: [PATCH] please sonar and simplify simcalls (before killing them) --- src/include/surf/surf.h | 2 -- src/simix/popping_accessors.h | 3 --- src/simix/popping_bodies.cpp | 9 ++++++--- src/simix/popping_generated.cpp | 23 ++++++++++++++--------- src/simix/simcalls.in | 6 +++--- src/simix/smx_io.cpp | 24 ++++-------------------- src/simix/smx_io_private.h | 6 +++--- src/surf/FileImpl.hpp | 17 +++++++++++++++++ src/surf/HostImpl.cpp | 17 ----------------- src/surf/HostImpl.hpp | 14 -------------- src/surf/surf_c_bindings.cpp | 5 ----- 11 files changed, 47 insertions(+), 79 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 144c096c22..30066f40af 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -52,7 +52,6 @@ typedef simgrid::surf::NetworkModel surf_NetworkModel; typedef simgrid::surf::StorageImpl surf_Storage; typedef simgrid::surf::StorageModel surf_StorageModel; typedef simgrid::surf::Resource surf_Resource; -typedef simgrid::surf::HostImpl surf_Host; typedef simgrid::surf::Action surf_Action; typedef simgrid::surf::FileImpl surf_File; @@ -83,7 +82,6 @@ typedef surf_CpuModel *surf_cpu_model_t; typedef surf_HostModel *surf_host_model_t; typedef surf_NetworkModel *surf_network_model_t; typedef surf_StorageModel *surf_storage_model_t; -typedef surf_Storage* surf_storage_t; typedef surf_File* surf_file_t; /** @ingroup SURF_c_bindings diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 1b5db257b9..e89a5657b2 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -1772,8 +1772,5 @@ XBT_PRIVATE void simcall_HANDLER_file_read(smx_simcall_t simcall, smx_file_t fd, XBT_PRIVATE void simcall_HANDLER_file_write(smx_simcall_t simcall, smx_file_t fd, sg_size_t size, sg_host_t host); XBT_PRIVATE void simcall_HANDLER_file_open(smx_simcall_t simcall, const char* mount, const char* path, sg_storage_t st); XBT_PRIVATE void simcall_HANDLER_file_close(smx_simcall_t simcall, smx_file_t fd, sg_host_t host); -XBT_PRIVATE sg_size_t simcall_HANDLER_file_get_size(smx_simcall_t simcall, smx_file_t fd); -XBT_PRIVATE sg_size_t simcall_HANDLER_file_tell(smx_simcall_t simcall, smx_file_t fd); -XBT_PRIVATE int simcall_HANDLER_file_seek(smx_simcall_t simcall, smx_file_t fd, sg_offset_t offset, int origin); XBT_PRIVATE int simcall_HANDLER_file_move(smx_simcall_t simcall, smx_file_t fd, const char* fullpath); XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max); \ No newline at end of file diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 02f679ab76..79b16f1081 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -365,19 +365,22 @@ inline static int simcall_BODY_file_unlink(smx_file_t fd, sg_host_t host) { inline static sg_size_t simcall_BODY_file_get_size(smx_file_t fd) { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_file_get_size(&SIMIX_process_self()->simcall, fd); + if (0) + SIMIX_file_get_size(fd); return simcall(SIMCALL_FILE_GET_SIZE, fd); } inline static sg_size_t simcall_BODY_file_tell(smx_file_t fd) { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_file_tell(&SIMIX_process_self()->simcall, fd); + if (0) + SIMIX_file_tell(fd); return simcall(SIMCALL_FILE_TELL, fd); } inline static int simcall_BODY_file_seek(smx_file_t fd, sg_offset_t offset, int origin) { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_file_seek(&SIMIX_process_self()->simcall, fd, offset, origin); + if (0) + SIMIX_file_seek(fd, offset, origin); return simcall(SIMCALL_FILE_SEEK, fd, offset, origin); } diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 1fc2e8a1a2..ff4bb3854f 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -362,19 +362,24 @@ case SIMCALL_FILE_UNLINK: break; case SIMCALL_FILE_GET_SIZE: - simgrid::simix::marshal(simcall->result, simcall_HANDLER_file_get_size(simcall, simgrid::simix::unmarshal(simcall->args[0]))); - SIMIX_simcall_answer(simcall); - break; + simgrid::simix::marshal(simcall->result, + SIMIX_file_get_size(simgrid::simix::unmarshal(simcall->args[0]))); + SIMIX_simcall_answer(simcall); + break; case SIMCALL_FILE_TELL: - simgrid::simix::marshal(simcall->result, simcall_HANDLER_file_tell(simcall, simgrid::simix::unmarshal(simcall->args[0]))); - SIMIX_simcall_answer(simcall); - break; + simgrid::simix::marshal(simcall->result, + SIMIX_file_tell(simgrid::simix::unmarshal(simcall->args[0]))); + SIMIX_simcall_answer(simcall); + break; case SIMCALL_FILE_SEEK: - simgrid::simix::marshal(simcall->result, simcall_HANDLER_file_seek(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1]), simgrid::simix::unmarshal(simcall->args[2]))); - SIMIX_simcall_answer(simcall); - break; + simgrid::simix::marshal(simcall->result, + SIMIX_file_seek(simgrid::simix::unmarshal(simcall->args[0]), + simgrid::simix::unmarshal(simcall->args[1]), + simgrid::simix::unmarshal(simcall->args[2]))); + SIMIX_simcall_answer(simcall); + break; case SIMCALL_FILE_MOVE: simgrid::simix::marshal(simcall->result, simcall_HANDLER_file_move(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1]))); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index a7879aac34..fe851a0c26 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -90,9 +90,9 @@ sg_size_t file_write(smx_file_t fd, sg_size_t size, sg_host_t host) [[block]]; smx_file_t file_open(const char* mount, const char* path, sg_storage_t st) [[block]]; int file_close(smx_file_t fd, sg_host_t host) [[block]]; int file_unlink(smx_file_t fd, sg_host_t host) [[nohandler]]; -sg_size_t file_get_size(smx_file_t fd); -sg_size_t file_tell(smx_file_t fd); -int file_seek(smx_file_t fd, sg_offset_t offset, int origin); +sg_size_t file_get_size(smx_file_t fd) [[nohandler]]; +sg_size_t file_tell(smx_file_t fd) [[nohandler]]; +int file_seek(smx_file_t fd, sg_offset_t offset, int origin) [[nohandler]]; int file_move(smx_file_t fd, const char* fullpath); int mc_random(int min, int max); diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index ee23b9d95a..91690a9836 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -121,35 +121,19 @@ int SIMIX_file_unlink(smx_file_t fd, sg_host_t host) return surf_host_unlink(host, fd->surf_file); } -sg_size_t simcall_HANDLER_file_get_size(smx_simcall_t simcall, smx_file_t fd) -{ - return SIMIX_file_get_size(simcall->issuer, fd); -} - -sg_size_t SIMIX_file_get_size(smx_actor_t process, smx_file_t fd) +sg_size_t SIMIX_file_get_size(smx_file_t fd) { return fd->surf_file->size(); } -sg_size_t simcall_HANDLER_file_tell(smx_simcall_t simcall, smx_file_t fd) -{ - return SIMIX_file_tell(simcall->issuer, fd); -} - -sg_size_t SIMIX_file_tell(smx_actor_t process, smx_file_t fd) +sg_size_t SIMIX_file_tell(smx_file_t fd) { return fd->surf_file->tell(); } -int simcall_HANDLER_file_seek(smx_simcall_t simcall, smx_file_t fd, sg_offset_t offset, int origin) +int SIMIX_file_seek(smx_file_t fd, sg_offset_t offset, int origin) { - return SIMIX_file_seek(simcall->issuer, fd, offset, origin); -} - -int SIMIX_file_seek(smx_actor_t process, smx_file_t fd, sg_offset_t offset, int origin) -{ - sg_host_t host = process->host; - return surf_host_file_seek(host, fd->surf_file, offset, origin); + return fd->surf_file->seek(offset, origin); } int simcall_HANDLER_file_move(smx_simcall_t simcall, smx_file_t file, const char* fullpath) diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 70e553d19e..a63e7e14e6 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -16,9 +16,9 @@ XBT_PRIVATE smx_activity_t SIMIX_file_write(smx_file_t fd, sg_size_t size, sg_ho XBT_PRIVATE smx_activity_t SIMIX_file_open(const char* mount, const char* path, sg_storage_t st); XBT_PRIVATE smx_activity_t SIMIX_file_close(smx_file_t fd, sg_host_t host); XBT_PRIVATE int SIMIX_file_unlink(smx_file_t fd, sg_host_t host); -XBT_PRIVATE sg_size_t SIMIX_file_get_size(smx_actor_t process, smx_file_t fd); -XBT_PRIVATE sg_size_t SIMIX_file_tell(smx_actor_t process, smx_file_t fd); -XBT_PRIVATE int SIMIX_file_seek(smx_actor_t process, smx_file_t fd, sg_offset_t offset, int origin); +XBT_PRIVATE sg_size_t SIMIX_file_get_size(smx_file_t fd); +XBT_PRIVATE sg_size_t SIMIX_file_tell(smx_file_t fd); +XBT_PRIVATE int SIMIX_file_seek(smx_file_t fd, sg_offset_t offset, int origin); XBT_PRIVATE int SIMIX_file_move(smx_actor_t process, smx_file_t fd, const char* fullpath); XBT_PRIVATE void SIMIX_io_destroy(smx_activity_t synchro); diff --git a/src/surf/FileImpl.hpp b/src/surf/FileImpl.hpp index e8ae85bb1d..b50fa8f262 100644 --- a/src/surf/FileImpl.hpp +++ b/src/surf/FileImpl.hpp @@ -26,6 +26,23 @@ public: void setPosition(sg_size_t size) { current_position_ = size; } void incrPosition(sg_size_t incr) { current_position_ += incr; } sg_size_t tell() { return current_position_; } + int seek(sg_offset_t offset, int origin) + { + switch (origin) { + case SEEK_SET: + current_position_ = offset; + return 0; + case SEEK_CUR: + current_position_ += offset; + return 0; + case SEEK_END: + current_position_ = size_ + offset; + return 0; + default: + return -1; + } + } + private: std::string path_; std::string mount_point_; diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index b636340529..48679307f8 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -158,23 +158,6 @@ int HostImpl::unlink(surf_file_t fd) } } -int HostImpl::fileSeek(surf_file_t fd, sg_offset_t offset, int origin) -{ - switch (origin) { - case SEEK_SET: - fd->setPosition(offset); - return 0; - case SEEK_CUR: - fd->incrPosition(offset); - return 0; - case SEEK_END: - fd->setPosition(fd->size() + offset); - return 0; - default: - return -1; - } -} - int HostImpl::fileMove(surf_file_t fd, const char* fullpath) { /* Check if the new full path is on the same mount point */ diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index d57d51926f..6fe57552f2 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -107,20 +107,6 @@ public: */ virtual Action* write(surf_file_t fd, sg_size_t size); - /** - * @brief Set the position indicator associated with the file descriptor to a new position - * @details [long description] - * - * @param fd The file descriptor - * @param offset The offset from the origin - * @param origin Position used as a reference for the offset - * - SEEK_SET: beginning of the file - * - SEEK_CUR: current position indicator - * - SEEK_END: end of the file - * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED - */ - virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin); - /** * @brief Move a file to another location on the *same mount point*. * @details [long description] diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 9e2e4c5548..07be1f94a8 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -181,11 +181,6 @@ surf_action_t surf_host_write(sg_host_t host, surf_file_t fd, sg_size_t size){ return host->pimpl_->write(fd, size); } -int surf_host_file_seek(sg_host_t host, surf_file_t fd, - sg_offset_t offset, int origin){ - return host->pimpl_->fileSeek(fd, offset, origin); -} - int surf_host_file_move(sg_host_t host, surf_file_t fd, const char* fullpath){ return host->pimpl_->fileMove(fd, fullpath); } -- 2.20.1