Changeset 50:f4866c53abd0 in finroc_core


Ignore:
Timestamp:
01.12.2010 01:19:08 (9 years ago)
Author:
Max Reichardt <reichardt@…>
Branch:
default
Phase:
public
Convert:
svn:b083a55c-8fa7-4c4f-93b4-8bdc53b56238/trunk@51
Message:

Added code that calls dlclose() for all dlopen-ed libraries when program ends

Location:
plugin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • plugin/tConstructorCreateModuleAction.hpp

    r42 r50  
    5555  while (names.Size() < 12) 
    5656  { 
    57     names.Add(cPARAMETER + name); 
     57    names.Add(cPARAMETER + names.Size()); 
    5858  } 
    5959 
  • plugin/tPlugins.cpp

    r46 r50  
    2020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
    2121 */ 
     22#include "core/tRuntimeEnvironment.h" 
     23 
    2224#include "core/plugin/tPlugins.h" 
    2325#include "core/plugin/tCreateExternalConnectionAction.h" 
     
    2729namespace core 
    2830{ 
     31tPlugins::tDLCloser::~tDLCloser() 
     32{ 
     33  tRuntimeEnvironment::Shutdown(); 
     34  for (size_t i = 0; i < loaded.Size(); i++) 
     35  { 
     36    dlclose(loaded.Get(i)); 
     37  } 
     38} 
     39 
    2940void tPlugins::FindAndLoadPlugins() 
    3041{ 
     
    4354  // dynamically loaded .so files 
    4455  static util::tSimpleList<util::tString> loaded; 
     56  static tDLCloser dlcloser; 
    4557 
    4658  // try to find module among existing modules 
     
    6981  { 
    7082    loaded.Add(group); 
    71     if (dlopen(group.GetCString(), RTLD_NOW | RTLD_GLOBAL)) 
     83    void* handle = dlopen(group.GetCString(), RTLD_NOW | RTLD_GLOBAL); 
     84    if (handle) 
    7285    { 
     86      dlcloser.loaded.Add(handle); 
    7387      return LoadModuleType(group, name); 
    7488    } 
  • plugin/tPlugins.h

    r45 r50  
    133133  } 
    134134 
     135  // closes dlopen-ed libraries 
     136  class tDLCloser 
     137  { 
     138  public: 
     139    util::tSimpleList<void*> loaded; 
     140 
     141    tDLCloser() : loaded() {} 
     142    ~tDLCloser(); 
     143  }; 
     144 
    135145  /*! 
    136146   * Returns/loads CreateModuleAction with specified name and specified .so file. 
Note: See TracChangeset for help on using the changeset viewer.