From: suter Date: Wed, 17 Jul 2013 11:29:28 +0000 (+0200) Subject: Allow users to attach arbitrary data to opened files X-Git-Tag: v3_9_90~128^2~68 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/61a837a60b668d9cd79a445eb5f99fd4fd77effc Allow users to attach arbitrary data to opened files --- diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index 53a3c8ce5a..c0baaf3a82 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -113,7 +113,6 @@ typedef struct s_file_info { typedef struct msg_file { char *fullname; /**< @brief file full name (path+name)*/ simdata_file_t simdata; /**< @brief simulator data */ - void *data; /**< @brief user data */ msg_file_info_t info; } s_msg_file_t; diff --git a/include/msg/msg.h b/include/msg/msg.h index 578e222c32..c118a7501f 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -80,7 +80,10 @@ XBT_PUBLIC(xbt_dynar_t) MSG_environment_as_get_hosts(msg_as_t as); /************************** File handling ***********************************/ XBT_PUBLIC(size_t) MSG_file_read(size_t size, msg_file_t fd); XBT_PUBLIC(size_t) MSG_file_write(size_t size, msg_file_t fd); -XBT_PUBLIC(msg_file_t) MSG_file_open(const char* mount, const char* path); +XBT_PUBLIC(msg_file_t) MSG_file_open(const char* mount, const char* path, + void* data); +XBT_PUBLIC(void*) MSG_file_get_data(msg_file_t fd); +XBT_PUBLIC(msg_error_t) MSG_file_set_data(msg_file_t fd, void * data); XBT_PUBLIC(int) MSG_file_close(msg_file_t fd); XBT_PUBLIC(size_t) MSG_file_get_size(msg_file_t fd); XBT_PUBLIC(void) MSG_file_dump(msg_file_t fd); diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 4a521c55e2..5c3d41b1a0 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -285,6 +285,10 @@ XBT_PUBLIC(int) SIMIX_comm_has_send_match(smx_rdv_t rdv, int (*match_fun)(void*, XBT_PUBLIC(int) SIMIX_comm_has_recv_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data); XBT_PUBLIC(void) SIMIX_comm_finish(smx_action_t action); +/*********************************** File *************************************/ +XBT_PUBLIC(void*) SIMIX_file_get_data(smx_file_t fd); +XBT_PUBLIC(void) SIMIX_file_set_data(smx_file_t fd, void *data); + /******************************************************************************/ /* SIMIX simcalls */ /******************************************************************************/ @@ -473,6 +477,8 @@ XBT_PUBLIC(void) simcall_sem_acquire_timeout(smx_sem_t sem, XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem); /***************************** File **********************************/ +XBT_PUBLIC(void *) simcall_file_get_data(smx_file_t fd); +XBT_PUBLIC(void) simcall_file_set_data(smx_file_t fd, void *data); XBT_PUBLIC(size_t) simcall_file_read(size_t size, smx_file_t fd); XBT_PUBLIC(size_t) simcall_file_write(size_t size, smx_file_t fd); XBT_PUBLIC(smx_file_t) simcall_file_open(const char* storage, const char* path); diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index 80e48e8750..bd56338dbc 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -28,6 +28,33 @@ void __MSG_file_get_info(msg_file_t fd){ xbt_dynar_free_container(&info); } + +/** \ingroup msg_file_management + * + * \brief Set the user data of a #msg_file_t. + * + * This functions checks whether some data has already been associated to \a file + or not and attach \a data to \a file if it is possible. + */ +msg_error_t MSG_file_set_data(msg_file_t fd, void *data) +{ + SIMIX_file_set_data(fd->simdata->smx_file,data); + + return MSG_OK; +} + +/** \ingroup msg_file_management + * + * \brief Return the user data of a #msg_file_t. + * + * This functions checks whether \a file is a valid pointer or not and return + the user data associated to \a file if it is possible. + */ +void *MSG_file_get_data(msg_file_t fd) +{ + return SIMIX_file_get_data(fd->simdata->smx_file); +} + /** \ingroup msg_file_management * \brief Display information related to a file descriptor * @@ -77,13 +104,15 @@ size_t MSG_file_write(size_t size, msg_file_t fd) * * \return An #msg_file_t associated to the file */ -msg_file_t MSG_file_open(const char* mount, const char* fullname) +msg_file_t MSG_file_open(const char* mount, const char* fullname, void* data) { msg_file_t file = xbt_new(s_msg_file_t,1); file->fullname = xbt_strdup(fullname); file->simdata = xbt_new0(s_simdata_file_t,1); file->info = xbt_new0(s_file_info_t,1); file->simdata->smx_file = simcall_file_open(mount, fullname); + SIMIX_file_set_data(file->simdata->smx_file, data); + return file; } diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index dd52bf1d47..e572e3a5bb 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -15,6 +15,26 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)"); +void* SIMIX_pre_file_get_data(smx_simcall_t simcall,smx_file_t fd){ + return SIMIX_file_get_data(fd); +} + +void* SIMIX_file_get_data(smx_file_t fd){ + xbt_assert((fd != NULL), "Invalid parameters (simix file is NULL)"); + + return fd->data; +} + +void SIMIX_pre_file_set_data(smx_simcall_t simcall, smx_file_t fd, void *data) { + SIMIX_file_set_data(fd, data); +} + +void SIMIX_file_set_data(smx_file_t fd, void *data){ + xbt_assert((fd != NULL), "Invalid parameter"); + + fd->data = data; +} + //SIMIX FILE READ void SIMIX_pre_file_read(smx_simcall_t simcall, size_t size, smx_file_t fd) diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 8b3be6af63..76396fa695 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -10,6 +10,8 @@ #include "simgrid/simix.h" #include "smx_smurf_private.h" +void* SIMIX_pre_file_get_data(smx_simcall_t simcall,smx_file_t fd); +void SIMIX_pre_file_set_data(smx_simcall_t simcall, smx_file_t fd, void *data); void SIMIX_pre_file_read(smx_simcall_t simcall, size_t size, smx_file_t fd); void SIMIX_pre_file_write(smx_simcall_t simcall, size_t size, smx_file_t fd); void SIMIX_pre_file_open(smx_simcall_t simcall, const char* mount, @@ -21,6 +23,8 @@ void SIMIX_pre_file_ls(smx_simcall_t simcall, size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd); xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd); +void* SIMIX_file_get_data(smx_file_t fd); +void SIMIX_file_set_data(smx_file_t fd, void *data); smx_action_t SIMIX_file_read(smx_process_t process, size_t size, smx_file_t fd); smx_action_t SIMIX_file_write(smx_process_t process, size_t size, diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index 1875079000..ef7416900b 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -73,6 +73,7 @@ extern xbt_dict_t watched_hosts_lib; /* ******************************** File ************************************ */ typedef struct s_smx_file { surf_file_t surf_file; + void* data; /**< @brief user data */ } s_smx_file_t; /* ******************************** Storage ************************************ */ diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index 9e6bc2f40e..44f3524a13 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -347,6 +347,8 @@ ACTION(SIMCALL_SEM_WOULD_BLOCK, sem_would_block, WITH_ANSWER, TINT(result), TSPE ACTION(SIMCALL_SEM_ACQUIRE, sem_acquire, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \ ACTION(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem_acquire_timeout, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t), TDOUBLE(timeout)) sep \ ACTION(SIMCALL_SEM_GET_CAPACITY, sem_get_capacity, WITH_ANSWER, TINT(result), TSPEC(sem, smx_sem_t)) sep \ +ACTION(SIMCALL_FILE_GET_DATA, file_get_data, WITH_ANSWER, TPTR(result), TSPEC(fd, smx_file_t)) sep \ +ACTION(SIMCALL_FILE_SET_DATA, file_set_data, WITH_ANSWER, TVOID(result), TSPEC(fd, smx_file_t), TPTR(data)) sep \ ACTION(SIMCALL_FILE_READ, file_read, WITHOUT_ANSWER, TSIZE(result), TSIZE(size), TSPEC(fd, smx_file_t)) sep \ ACTION(SIMCALL_FILE_WRITE, file_write, WITHOUT_ANSWER, TSIZE(result), TSIZE(size), TSPEC(fd, smx_file_t)) sep \ ACTION(SIMCALL_FILE_OPEN, file_open, WITHOUT_ANSWER, TSPEC(result, smx_file_t), TSTRING(mount), TSTRING(path)) sep \ diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 3e0c130ee0..a990f4799d 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1174,6 +1174,30 @@ int simcall_sem_get_capacity(smx_sem_t sem) return simcall_BODY_sem_get_capacity(sem); } +/** + * \ingroup simix_file_management + * \brief Returns the user data associated to a file. + * + * \param fd A simix file + * \return the user data of this file + */ +void* simcall_file_get_data(smx_file_t fd) +{ + return simcall_BODY_file_get_data(fd); +} + +/** + * \ingroup simix_file_management + * \brief Sets the user data associated to a file. + * + * \param fd A SIMIX file + * \param data The user data to set + */ +void simcall_file_set_data(smx_file_t fd, void *data) +{ + simcall_file_set_data(fd, data); +} + /** * \ingroup simix_file_management *