Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2 dynar less (but this code is ... improvable)
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 18 Aug 2016 07:57:03 +0000 (09:57 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 18 Aug 2016 07:57:03 +0000 (09:57 +0200)
src/surf/storage_interface.cpp
src/surf/storage_interface.hpp
src/surf/storage_n11.cpp

index df30827..452b993 100644 (file)
@@ -35,16 +35,13 @@ simgrid::xbt::signal<void(StorageAction*, Action::State, Action::State)> storage
  * Model *
  *********/
 
  * Model *
  *********/
 
-StorageModel::StorageModel()
-  : Model()
+StorageModel::StorageModel(): Model()
 {
 {
-  p_storageList = nullptr;
 }
 
 StorageModel::~StorageModel(){
   lmm_system_free(maxminSystem_);
   surf_storage_model = nullptr;
 }
 
 StorageModel::~StorageModel(){
   lmm_system_free(maxminSystem_);
   surf_storage_model = nullptr;
-  xbt_dynar_free(&p_storageList);
 }
 
 /************
 }
 
 /************
@@ -59,7 +56,7 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
  , p_contentType(xbt_strdup(content_type))
  , m_size(size), m_usedSize(0)
  , p_typeId(xbt_strdup(type_id))
  , p_contentType(xbt_strdup(content_type))
  , m_size(size), m_usedSize(0)
  , p_typeId(xbt_strdup(type_id))
- , p_writeActions(xbt_dynar_new(sizeof(Action*),nullptr))
+ , p_writeActions(std::vector<StorageAction*>())
 {
   p_content = parseContent(content_name);
   turnOn();
 {
   p_content = parseContent(content_name);
   turnOn();
@@ -74,7 +71,7 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
  , p_contentType(xbt_strdup(content_type))
  , m_size(size), m_usedSize(0)
  , p_typeId(xbt_strdup(type_id))
  , p_contentType(xbt_strdup(content_type))
  , m_size(size), m_usedSize(0)
  , p_typeId(xbt_strdup(type_id))
- , p_writeActions(xbt_dynar_new(sizeof(Action*),nullptr))
+ , p_writeActions(std::vector<StorageAction*>())
 {
   p_content = parseContent(content_name);
   p_attach = xbt_strdup(attach);
 {
   p_content = parseContent(content_name);
   p_attach = xbt_strdup(attach);
@@ -87,7 +84,6 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
 Storage::~Storage(){
   storageDestructedCallbacks(this);
   xbt_dict_free(&p_content);
 Storage::~Storage(){
   storageDestructedCallbacks(this);
   xbt_dict_free(&p_content);
-  xbt_dynar_free(&p_writeActions);
   free(p_typeId);
   free(p_contentType);
   free(p_attach);
   free(p_typeId);
   free(p_contentType);
   free(p_attach);
index e00bd45..e8879f9 100644 (file)
@@ -74,16 +74,13 @@ public:
    * @param attach [description]
    * @return The created Storage
    */
    * @param attach [description]
    * @return The created Storage
    */
-  virtual Storage *createStorage(const char* id,
-                                    const char* type_id,
-                                    const char* content_name,
-                                    const char* content_type,
-                                    xbt_dict_t properties,
-                                    const char *attach) = 0;
+  virtual Storage *createStorage(const char* id, const char* type_id,
+                                 const char* content_name, const char* content_type,
+                                 xbt_dict_t properties, const char *attach) = 0;
 
   bool next_occuring_event_isIdempotent() {return true;}
 
 
   bool next_occuring_event_isIdempotent() {return true;}
 
-  xbt_dynar_t p_storageList;
+  std::vector<Storage*> p_storageList;
 };
 
 /************
 };
 
 /************
@@ -217,7 +214,7 @@ public:
 
   xbt_dict_t parseContent(const char *filename);
 
 
   xbt_dict_t parseContent(const char *filename);
 
-  xbt_dynar_t p_writeActions;
+  std::vector<StorageAction*> p_writeActions;
 
   lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
   lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
 
   lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
   lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
@@ -301,5 +298,4 @@ typedef struct surf_file {
   sg_size_t current_position;
 } s_surf_file_t;
 
   sg_size_t current_position;
 } s_surf_file_t;
 
-
 #endif /* STORAGE_INTERFACE_HPP_ */
 #endif /* STORAGE_INTERFACE_HPP_ */
index 92eacad..c43bfc5 100644 (file)
@@ -103,14 +103,9 @@ Storage *StorageN11Model::createStorage(const char* id, const char* type_id,
   xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage);
 
   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tproperties '%p'\n\t\tBread '%f'\n",
   xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage);
 
   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tproperties '%p'\n\t\tBread '%f'\n",
-      id,
-      type_id,
-      properties,
-      Bread);
+      id, type_id, properties, Bread);
 
 
-  if(!p_storageList)
-    p_storageList = xbt_dynar_new(sizeof(char *),nullptr);
-  xbt_dynar_push(p_storageList, &storage);
+  p_storageList.push_back(storage);
 
   return storage;
 }
 
   return storage;
 }
@@ -118,20 +113,15 @@ Storage *StorageN11Model::createStorage(const char* id, const char* type_id,
 double StorageN11Model::next_occuring_event(double /*now*/)
 {
   XBT_DEBUG("storage_share_resources");
 double StorageN11Model::next_occuring_event(double /*now*/)
 {
   XBT_DEBUG("storage_share_resources");
-  unsigned int i, j;
-  Storage *storage;
-  void *_write_action;
-  StorageAction *write_action;
 
   double min_completion = shareResourcesMaxMin(getRunningActionSet(), maxminSystem_, lmm_solve);
 
   double rate;
   // Foreach disk
 
   double min_completion = shareResourcesMaxMin(getRunningActionSet(), maxminSystem_, lmm_solve);
 
   double rate;
   // Foreach disk
-  xbt_dynar_foreach(p_storageList,i,storage) {
+  for(auto storage: p_storageList) {
     rate = 0;
     // Foreach write action on disk
     rate = 0;
     // Foreach write action on disk
-    xbt_dynar_foreach(storage->p_writeActions, j, _write_action) {
-      write_action = static_cast<StorageAction*>(_write_action);
+    for (auto write_action: storage->p_writeActions) {
       rate += lmm_variable_getvalue(write_action->getVariable());
     }
     if(rate > 0)
       rate += lmm_variable_getvalue(write_action->getVariable());
     }
     if(rate > 0)
@@ -151,8 +141,7 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta)
     ++itNext;
     action = static_cast<StorageAction*>(&*it);
 
     ++itNext;
     action = static_cast<StorageAction*>(&*it);
 
-    if(action->m_type == WRITE)
-    {
+    if(action->m_type == WRITE){
       // Update the disk usage
       // Update the file size
       // For each action of type write
       // Update the disk usage
       // Update the file size
       // For each action of type write
@@ -246,17 +235,15 @@ StorageAction *StorageN11::open(const char* mount, const char* path)
 
 StorageAction *StorageN11::close(surf_file_t fd)
 {
 
 StorageAction *StorageN11::close(surf_file_t fd)
 {
-  char *filename = fd->name;
-  XBT_DEBUG("\tClose file '%s' size '%llu'", filename, fd->size);
+  XBT_DEBUG("\tClose file '%s' size '%llu'", fd->name, fd->size);
   // unref write actions from storage
   // unref write actions from storage
-  void *_write_action;
-  StorageAction *write_action;
-  unsigned int i;
-  xbt_dynar_foreach(p_writeActions, i, _write_action) {
-    write_action = static_cast<StorageAction*>(_write_action);
+  for (auto it = p_writeActions.cbegin(); it != p_writeActions.cend();) {
+    StorageAction *write_action = *it;
     if ((write_action->p_file) == fd) {
     if ((write_action->p_file) == fd) {
-      xbt_dynar_cursor_rm(p_writeActions, &i);
       write_action->unref();
       write_action->unref();
+      it = p_writeActions.erase(it);
+    } else {
+      ++it;
     }
   }
   free(fd->name);
     }
   }
   free(fd->name);
@@ -317,16 +304,14 @@ StorageN11Action::StorageN11Action(Model *model, double cost, bool failed, Stora
   case STAT:
     break;
   case READ:
   case STAT:
     break;
   case READ:
-    lmm_expand(model->getMaxminSystem(), storage->p_constraintRead,
-        getVariable(), 1.0);
+    lmm_expand(model->getMaxminSystem(), storage->p_constraintRead, getVariable(), 1.0);
     break;
   case WRITE:
     break;
   case WRITE:
-    lmm_expand(model->getMaxminSystem(), storage->p_constraintWrite,
-        getVariable(), 1.0);
+    lmm_expand(model->getMaxminSystem(), storage->p_constraintWrite, getVariable(), 1.0);
 
     //TODO there is something annoying with what's below. Have to sort it out...
     //    Action *action = this;
 
     //TODO there is something annoying with what's below. Have to sort it out...
     //    Action *action = this;
-    //    xbt_dynar_push(storage->p_writeActions, &action);
+    //    storage->p_writeActions->push_back(action);
     //    ref();
     break;
   }
     //    ref();
     break;
   }