summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/kernel/dynlib.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-02 22:13:15 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-02 22:13:15 +0000
commit996d5f6c4e21d3d8688674f20e6f4318e3ace607 (patch)
treebe6a3d80f2cab11cd39d0f55bd4bc55793a2e735 /sca-cpp/trunk/kernel/dynlib.hpp
parentdda9255a5c9336cd3078f85f02e88120563ad304 (diff)
Cleaned up lifecycle handling of objects that hold library and file resources. Fixed pool stack initialization concurrency issue. Re-enabled watch strings to help watch compound values in debugger.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@895305 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/kernel/dynlib.hpp50
1 files changed, 19 insertions, 31 deletions
diff --git a/sca-cpp/trunk/kernel/dynlib.hpp b/sca-cpp/trunk/kernel/dynlib.hpp
index a000653455..9f55dc4a49 100644
--- a/sca-cpp/trunk/kernel/dynlib.hpp
+++ b/sca-cpp/trunk/kernel/dynlib.hpp
@@ -48,52 +48,40 @@ const string dynlibExt(".so");
*/
class lib {
public:
- lib() : dl(NULL) {
+ lib() : h(NULL), owner(false) {
}
- lib(const string& name) : dl(new (gc_new<DynLib>()) DynLib(name)) {
+ lib(const string& name) : name(name), h(dlopen(c_str(name), RTLD_NOW)), owner(true) {
+ if (h == NULL)
+ h = mkfailure<void*>(string("Could not load library: ") + name + ": " + dlerror());
+ }
+
+ lib(const lib& l) : name(l.name), h(l.h), owner(false) {
}
~lib() {
+ if (!owner)
+ return;
+ if (!hasContent(h) || content(h) == NULL)
+ return;
+ dlclose(content(h));
}
private:
- class DynLib {
- public:
- DynLib(const string& name) : name(name), h(dlopen(c_str(name), RTLD_NOW)) {
- }
-
- ~DynLib() {
- if (h == NULL)
- return;
- dlclose(h);
- }
-
- const string name;
- void* h;
- };
-
- gc_ptr<DynLib> dl;
-
- friend const failable<lib> dynlib(const string& name);
template<typename S> friend const failable<lambda<S> > dynlambda(const string& name, const lib& l);
-};
-/**
- * Load a dynamic library.
- */
-const failable<lib> dynlib(const string& name) {
- const lib l(name);
- if (l.dl->h == NULL)
- return mkfailure<lib>(string("Could not load library: ") + name + ": " + dlerror());
- return l;
-}
+ const string name;
+ failable<void*> h;
+ bool owner;
+};
/**
* Find a lambda function in a dynamic library.
*/
template<typename S> const failable<lambda<S> > dynlambda(const string& name, const lib& l) {
- const void* s = dlsym(l.dl->h, c_str(name));
+ if (!hasContent(l.h))
+ return mkfailure<lambda<S> >(reason(l.h));
+ const void* s = dlsym(content(l.h), c_str(name));
if (s == NULL)
return mkfailure<lambda<S> >(string("Could not load symbol: ") + name);
return lambda<S>((S*)s);