diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-04-13 08:54:55 +0200 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-04-13 08:54:55 +0200 |
commit | 6dcadfb26de2ce9117f58986d543c521143df1c2 (patch) | |
tree | 92dd8efd6de0a4d9d837908caa4232ccd59bff80 /zend/module.h | |
parent | 6328204053b26585cc0a590815f912fb8b153f41 (diff) | |
parent | faa7df504380295296e3349e9360732d750554c3 (diff) |
Merge branch 'master' of https://github.com/CopernicaMarketingSoftware/PHP-CPP
Diffstat (limited to 'zend/module.h')
-rw-r--r-- | zend/module.h | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/zend/module.h b/zend/module.h index bb36810..4431355 100644 --- a/zend/module.h +++ b/zend/module.h @@ -43,7 +43,7 @@ private: * @var zend_module_entry */ zend_module_entry *_entry = nullptr; - + #ifdef ZTS /** * When in thread safety mode, we also keep track of the TSRM_LS var @@ -52,12 +52,82 @@ private: void ***tsrm_ls; #endif + /** + * Internal helper class with persistent modules + */ + class Persistent + { + private: + /** + * The set of handles + * @var std::set + */ + std::set<void*> _handles; + + public: + /** + * Constructor + */ + Persistent() {} + + /** + * Destructor + */ + virtual ~Persistent() + { + // remove all handles + while (!_handles.empty()) + { + // get first handle + auto iter = _handles.begin(); + + // remove the handle + DL_UNLOAD(*iter); + + // remove from set + _handles.erase(iter); + } + } + + /** + * Check whether a handle is already persistently opened + * @param handle + * @return bool + */ + bool contains(void *handle) const + { + return _handles.find(handle) != _handles.end(); + } + + /** + * Add a library persistently + * @param module + */ + void add(const char *module) + { + // insert the handle + _handles.insert(DL_LOAD(module)); + } + }; + + /** + * All persistent modules + * @var Persistent + */ + static Persistent _persistent; + public: /** * Constructor + * + * A module can be loaded persistently. This means that the variables in + * the module will keep in scope for as long as Apache runs, even though + * the extension is not active in other page views + * * @param module Name of the module + * @param persistent Should it be loaded persistently */ - Module(const char *module) + Module(const char *module, bool persistent) { #ifdef ZTS // fetch multi-threading thing @@ -76,6 +146,10 @@ public: // handle should be valid if (!_handle) return; + // if we have to open it persistently, we open it for a second time so that + // the refcounter always stays 1 or higher + if (persistent && !_persistent.contains(_handle)) _persistent.add(module); + // we have to call the get_module() function Symbol<zend_module_entry*()> get_module(_handle, "get_module"); |