[Orxonox-commit 5894] r10553 - code/branches/core7/src/libraries/core/module

landauf at orxonox.net landauf at orxonox.net
Fri Aug 28 22:35:51 CEST 2015


Author: landauf
Date: 2015-08-28 22:35:51 +0200 (Fri, 28 Aug 2015)
New Revision: 10553

Modified:
   code/branches/core7/src/libraries/core/module/Plugin.cc
Log:
fixed reference counting in unload() - unsigned int cannot be < 0

Modified: code/branches/core7/src/libraries/core/module/Plugin.cc
===================================================================
--- code/branches/core7/src/libraries/core/module/Plugin.cc	2015-08-27 21:05:18 UTC (rev 10552)
+++ code/branches/core7/src/libraries/core/module/Plugin.cc	2015-08-28 20:35:51 UTC (rev 10553)
@@ -51,38 +51,34 @@
 
     void Plugin::load()
     {
-        if (this->referenceCounter_ == 0)
+        this->referenceCounter_++;
+        if (this->referenceCounter_ == 1) // increased from 0 to 1 -> load plugin
         {
             orxout(internal_info) << "Loading plugin " << this->name_ << "..." << endl;
             this->moduleInstance_ = new ModuleInstance(this->libraryName_);
             Core::getInstance().loadModule(this->moduleInstance_);
         }
         else
-        {
-            orxout(internal_info) << "Plugin " << this->name_ << " is already referenced" << endl;
-        }
-
-        this->referenceCounter_++;
+            orxout(internal_info) << "Increased reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
     }
 
     void Plugin::unload()
     {
-        this->referenceCounter_--;
         if (this->referenceCounter_ == 0)
         {
+            orxout(internal_warning) << "Tried to dereference plugin " << this->name_ << " more often than it was referenced" << endl;
+            return;
+        }
+
+        this->referenceCounter_--;
+        if (this->referenceCounter_ == 0) // reduced from 1 to 0 -> load plugin
+        {
             orxout(internal_info) << "Unloading plugin " << this->name_ << "..." << endl;
             Core::getInstance().unloadModule(this->moduleInstance_);
             delete this->moduleInstance_;
             this->moduleInstance_ = NULL;
         }
-        else if (this->referenceCounter_ > 0)
-        {
-            orxout(internal_info) << "Plugin " << this->name_ << " is still referenced" << endl;
-        }
         else
-        {
-            orxout(internal_warning) << "Plugin " << this->name_ << " was dereferenced more often than it was reference" << endl;
-            this->referenceCounter_ = 0;
-        }
+            orxout(internal_info) << "Reduced reference count for plugin " << this->name_ << " to " << this->referenceCounter_ << endl;
     }
 }




More information about the Orxonox-commit mailing list