#include <DLL_Manager.h>
Collaboration diagram for ACE_DLL_Manager:

Public Types | |
| enum | { DEFAULT_SIZE = ACE_DEFAULT_DLL_MANAGER_SIZE } |
Public Methods | |
| ACE_DLL_Handle * | open_dll (const ACE_TCHAR *dll_name, int openmode, ACE_SHLIB_HANDLE handle) |
| Factory for ACE_DLL_Handle objects. If one already exits, its refcount is incremented. More... | |
| int | close_dll (const ACE_TCHAR *dll_name) |
| Close the underlying dll. Decrements the refcount. More... | |
| u_long | unload_policy (void) const |
| Returns the current per-process UNLOAD_POLICY. More... | |
| void | unload_policy (u_long unload_policy) |
| Set the per-process UNLOAD_POLICY. If the policy is changed from LAZY to EAGER, then it will also unload any dlls with zero refcounts. More... | |
Static Public Methods | |
| ACE_DLL_Manager * | instance (int size=ACE_DLL_Manager::DEFAULT_SIZE) |
| Return a unique instance. More... | |
Protected Methods | |
| int | open (int size) |
| int | close (void) |
| ACE_DLL_Handle * | find_dll (const ACE_TCHAR *dll_name) const |
| int | unload_dll (ACE_DLL_Handle *dll_handle, int force_unload=0) |
Private Methods | |
| ACE_DLL_Manager (int size=ACE_DLL_Manager::DEFAULT_SIZE) | |
| Default constructor. More... | |
| ~ACE_DLL_Manager (void) | |
| Destructor. More... | |
| ACE_DLL_Manager (const ACE_DLL_Manager &) | |
| void | operator= (const ACE_DLL_Manager &) |
Static Private Methods | |
| void | close_singleton (void) |
| Close the singleton instance. More... | |
Private Attributes | |
| ACE_DLL_Handle ** | handle_vector_ |
| Vector containing all loaded handle objects. More... | |
| int | current_size_ |
| Current number of handles. More... | |
| int | total_size_ |
| Maximum number of handles. More... | |
| u_long | unload_policy_ |
| Unload strategy. More... | |
Static Private Attributes | |
| ACE_DLL_Manager * | instance_ = 0 |
| Pointer to a process-wide <ACE_DLL_Manager>. More... | |
Friends | |
| class | ACE_Framework_Repository |
This class is a singleton whose lifetime is managed by the ACE_Framework_Repository. Although it is normally meant to be used directly only by ACE_DLL, applications can call the unload_policy() methods in order get/set the the dll unload policy. Unload policies include per_process/per-dll and eager/lazy. Dlls can export set their own policy by using the ACE_DLL_UNLOAD_POLICY macro found in config-all.h. If a dll choses to set an unload policy, it will be used when the per-dll policy (the default) is in effect. If the per-dll policy is in effect and a dll has not chosen to set a policy, the current per-process policy will be used.
The following policy macros are provided in config-all.h:
ACE_DLL_UNLOAD_POLICY_PER_PROCESS - Per-process policy that unloads dlls eagerly.
ACE_DLL_UNLOAD_POLICY_PER_DLL - Apply policy on a per-dll basis. If the dll doesn't use one of the macros below, the current per-process policy will be used.
ACE_DLL_UNLOAD_POLICY_LAZY - Don't unload dll when refcount reaches zero, i.e., wait for either an explicit unload request or program exit.
ACE_DLL_UNLOAD_POLICY_DEFAULT - Default policy allows dlls to control their own destinies, but will unload those that don't make a choice eagerly.
Definition at line 167 of file DLL_Manager.h.
|
|
Definition at line 174 of file DLL_Manager.h.
00175 {
00176 DEFAULT_SIZE = ACE_DEFAULT_DLL_MANAGER_SIZE
00177 };
|
|
|
Default constructor.
Definition at line 276 of file DLL_Manager.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.
00277 : handle_vector_ (0), 00278 current_size_ (0), 00279 total_size_ (0), 00280 unload_policy_ (ACE_DLL_UNLOAD_POLICY_PER_DLL) 00281 { 00282 ACE_TRACE ("ACE_DLL_Manager::ACE_DLL_Manager"); 00283 00284 if (this->open (size) != 0) 00285 ACE_ERROR ((LM_ERROR, 00286 ACE_LIB_TEXT ("ACE_DLL_Manager ctor failed to allocate ") 00287 ACE_LIB_TEXT ("handle_vector_.\n"))); 00288 } |
|
|
Destructor.
Definition at line 290 of file DLL_Manager.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, close, and LM_ERROR.
00291 {
00292 ACE_TRACE ("ACE_DLL_Manager::~ACE_DLL_Manager");
00293
00294 if (this->close () != 0)
00295 ACE_ERROR ((LM_ERROR,
00296 ACE_LIB_TEXT ("ACE_DLL_Manager dtor failed to close ")
00297 ACE_LIB_TEXT ("properly.\n")));
00298 }
|
|
|
|
|
|
Definition at line 404 of file DLL_Manager.cpp. References ACE_TRACE, current_size_, handle_vector_, and unload_dll. Referenced by ~ACE_DLL_Manager.
00405 {
00406 ACE_TRACE ("ACE_DLL_Manager::close");
00407
00408 int force_close = 1;
00409
00410 if (this->handle_vector_ != 0)
00411 {
00412 // Delete components in reverse order.
00413 for (int i = this->current_size_ - 1; i >= 0; i--)
00414 {
00415 if (this->handle_vector_[i])
00416 {
00417 ACE_DLL_Handle *s = ACE_const_cast (ACE_DLL_Handle *,
00418 this->handle_vector_[i]);
00419 this->handle_vector_[i] = 0;
00420 this->unload_dll (s, force_close);
00421 delete s;
00422 }
00423 }
00424
00425 delete [] this->handle_vector_;
00426 this->handle_vector_ = 0;
00427 this->current_size_ = 0;
00428 }
00429 return 0;
00430 }
|
|
|
Close the underlying dll. Decrements the refcount.
Definition at line 338 of file DLL_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TCHAR, ACE_TRACE, find_dll, and unload_dll. Referenced by ACE_DLL::close.
00339 {
00340 ACE_TRACE ("ACE_DLL_Manager::close_dll");
00341 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
00342
00343 ACE_DLL_Handle *handle = this->find_dll (dll_name);
00344 if (handle)
00345 {
00346 return this->unload_dll (handle, 0);
00347 }
00348
00349 return -1;
00350 }
|
|
|
Close the singleton instance.
Definition at line 265 of file DLL_Manager.cpp. References ACE_GUARD, ACE_MT, ACE_TRACE, ACE_Static_Object_Lock::instance, and instance_. Referenced by ACE_Framework_Repository::close.
00266 {
00267 ACE_TRACE ("ACE_DLL_Manager::close_singleton");
00268
00269 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00270 *ACE_Static_Object_Lock::instance ()));
00271
00272 delete ACE_DLL_Manager::instance_;
00273 ACE_DLL_Manager::instance_ = 0;
00274 }
|
|
|
Definition at line 433 of file DLL_Manager.cpp. References ACE_TCHAR, ACE_TRACE, current_size_, handle_vector_, and ACE_OS_String::strcmp. Referenced by close_dll, and open_dll.
00434 {
00435 ACE_TRACE ("ACE_DLL_Manager::find_dll");
00436
00437 int i;
00438 for (i = 0; i < this->current_size_; i++)
00439 if (this->handle_vector_[i] &&
00440 ACE_OS_String::strcmp (this->handle_vector_[i]->dll_name (), dll_name) == 0)
00441 {
00442 return this->handle_vector_[i];
00443 }
00444
00445 return 0;
00446 }
|
|
|
Return a unique instance.
Definition at line 244 of file DLL_Manager.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_NEW_RETURN, ACE_TRACE, ACE_Static_Object_Lock::instance, and instance_. Referenced by ACE_DLL::close, and ACE_DLL::open_i.
00245 {
00246 ACE_TRACE ("ACE_DLL_Manager::instance");
00247
00248 if (ACE_DLL_Manager::instance_ == 0)
00249 {
00250 // Perform Double-Checked Locking Optimization.
00251 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00252 *ACE_Static_Object_Lock::instance (), 0));
00253 if (ACE_DLL_Manager::instance_ == 0)
00254 {
00255 ACE_NEW_RETURN (ACE_DLL_Manager::instance_,
00256 ACE_DLL_Manager (size),
00257 0);
00258 }
00259 }
00260
00261 return ACE_DLL_Manager::instance_;
00262 }
|
|
|
Definition at line 388 of file DLL_Manager.cpp. References ACE_NEW_RETURN, ACE_TRACE, handle_vector_, and total_size_. Referenced by ACE_DLL_Manager.
00389 {
00390 ACE_TRACE ("ACE_DLL_Manager::open");
00391
00392 ACE_DLL_Handle **temp;
00393
00394 ACE_NEW_RETURN (temp,
00395 ACE_DLL_Handle *[size],
00396 -1);
00397
00398 this->handle_vector_ = temp;
00399 this->total_size_ = size;
00400 return 0;
00401 }
|
|
||||||||||||||||
|
Factory for ACE_DLL_Handle objects. If one already exits, its refcount is incremented.
Definition at line 301 of file DLL_Manager.cpp. References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_NEW_RETURN, ACE_SHLIB_HANDLE, ACE_TCHAR, ACE_TRACE, current_size_, find_dll, handle_vector_, LM_ERROR, ACE_DLL_Handle::open, and total_size_. Referenced by ACE_DLL::open_i.
00304 {
00305 ACE_TRACE ("ACE_DLL_Manager::open_dll");
00306 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
00307
00308 ACE_DLL_Handle *dll_handle = this->find_dll (dll_name);
00309 if (!dll_handle)
00310 {
00311 if (this->current_size_ < this->total_size_)
00312 {
00313 ACE_NEW_RETURN (dll_handle,
00314 ACE_DLL_Handle,
00315 0);
00316
00317 this->handle_vector_[this->current_size_] = dll_handle;
00318 this->current_size_++;
00319 }
00320 }
00321
00322 if (dll_handle)
00323 {
00324 if (dll_handle->open (dll_name, open_mode, handle) != 0)
00325 {
00326 // Don't worry about freeing the memory right now, since
00327 // the handle_vector_ will be cleaned up automatically later.
00328 ACE_ERROR_RETURN ((LM_ERROR,
00329 ACE_LIB_TEXT ("ACE_DLL_Manager::open_dll: Could not ")
00330 ACE_LIB_TEXT ("open dll.\n")),
00331 0);
00332 }
00333 }
00334 return dll_handle;
00335 }
|
|
|
|
|
||||||||||||
|
Definition at line 449 of file DLL_Manager.cpp. References ACE_BIT_DISABLED, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TEXT, ACE_TRACE, ACE_DLL_Handle::close, LM_ERROR, and ACE_DLL_Handle::symbol. Referenced by close, and close_dll.
00450 {
00451 ACE_TRACE ("ACE_DLL_Manager::unload_dll");
00452
00453 if (dll_handle)
00454 {
00455 int unload = force_unload;
00456 if (unload == 0)
00457 {
00458 // apply strategy
00459 if (ACE_BIT_DISABLED (this->unload_policy_,
00460 ACE_DLL_UNLOAD_POLICY_PER_DLL))
00461 {
00462 unload = ACE_BIT_DISABLED (this->unload_policy_,
00463 ACE_DLL_UNLOAD_POLICY_LAZY);
00464 }
00465 else
00466 {
00467 // Declare the type of the symbol:
00468 typedef int (*dll_unload_policy)(void);
00469 dll_unload_policy the_policy = 0;
00470 void *unload_policy_ptr =
00471 dll_handle->symbol (ACE_TEXT ("_get_dll_unload_policy"), 1);
00472 ptrdiff_t temp_p =
00473 ACE_reinterpret_cast (ptrdiff_t, unload_policy_ptr);
00474 the_policy =
00475 ACE_reinterpret_cast (dll_unload_policy, temp_p);
00476 if (the_policy != 0)
00477 unload = ACE_BIT_DISABLED (the_policy (),
00478 ACE_DLL_UNLOAD_POLICY_LAZY);
00479 else
00480 unload = ACE_BIT_DISABLED (this->unload_policy_,
00481 ACE_DLL_UNLOAD_POLICY_LAZY);
00482 }
00483 }
00484
00485 if (dll_handle->close (unload) != 0)
00486 ACE_ERROR_RETURN ((LM_ERROR,
00487 ACE_LIB_TEXT ("ACE_DLL_Manager::unload error.\n")),
00488 -1);
00489 }
00490 else
00491 ACE_ERROR_RETURN ((LM_ERROR,
00492 ACE_LIB_TEXT ("ACE_DLL_Manager::unload_dll called with ")
00493 ACE_LIB_TEXT ("null pointer.\n")),
00494 -1);
00495
00496 return 0;
00497 }
|
|
|
Set the per-process UNLOAD_POLICY. If the policy is changed from LAZY to EAGER, then it will also unload any dlls with zero refcounts.
Definition at line 360 of file DLL_Manager.cpp. References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_GUARD, ACE_MT, ACE_TRACE, ACE_DLL_Handle::close, current_size_, handle_vector_, ACE_DLL_Handle::refcount, unload_policy, and unload_policy_.
00361 {
00362 ACE_TRACE ("ACE_DLL_Manager::unload_policy");
00363 ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->lock_));
00364
00365 u_long old_policy = this->unload_policy_;
00366 this->unload_policy_ = unload_policy;
00367
00368 // If going from LAZY to EAGER or from PER_DLL to PER_PROCESS|EAGER,
00369 // call close(1) on all the ACE_DLL_Handle objects with refcount == 0
00370 // which will force those that are still loaded to be unloaded.
00371 if (this->handle_vector_)
00372 if (( ACE_BIT_ENABLED (old_policy, ACE_DLL_UNLOAD_POLICY_LAZY) &&
00373 ACE_BIT_DISABLED (this->unload_policy_, ACE_DLL_UNLOAD_POLICY_LAZY) ) ||
00374 ( ACE_BIT_DISABLED (this->unload_policy_, ACE_DLL_UNLOAD_POLICY_LAZY) &&
00375 ACE_BIT_ENABLED (old_policy, ACE_DLL_UNLOAD_POLICY_PER_DLL) &&
00376 ACE_BIT_DISABLED (this->unload_policy_, ACE_DLL_UNLOAD_POLICY_PER_DLL) ))
00377 {
00378 for (int i = this->current_size_ - 1; i >= 0; i--)
00379 {
00380 if (this->handle_vector_[i] &&
00381 this->handle_vector_[i]->refcount () == 0)
00382 this->handle_vector_[i]->close (1);
00383 }
00384 }
00385 }
|
|
|
Returns the current per-process UNLOAD_POLICY.
Definition at line 353 of file DLL_Manager.cpp. References ACE_TRACE, and unload_policy_. Referenced by unload_policy.
00354 {
00355 ACE_TRACE ("ACE_DLL_Manager::unload_policy");
00356 return this->unload_policy_;
00357 }
|
|
|
Definition at line 172 of file DLL_Manager.h. |
|
|
Current number of handles.
Definition at line 226 of file DLL_Manager.h. Referenced by close, find_dll, open_dll, and unload_policy. |
|
|
Vector containing all loaded handle objects.
Definition at line 223 of file DLL_Manager.h. Referenced by close, find_dll, open, open_dll, and unload_policy. |
|
|
Pointer to a process-wide <ACE_DLL_Manager>.
Definition at line 240 of file DLL_Manager.cpp. Referenced by close_singleton, and instance. |
|
|
Maximum number of handles.
Definition at line 229 of file DLL_Manager.h. |
|
|
Unload strategy.
Definition at line 232 of file DLL_Manager.h. Referenced by unload_policy. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002