summaryrefslogtreecommitdiffhomepage
path: root/include/CompilerKit/Utilities
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-09 03:07:48 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-09 03:07:48 +0100
commit0c54fbd1a74242c568749b7293f2f319c4842d44 (patch)
tree86cdac041fc0a0f4e17d839d48e5ff7cea3cc5a7 /include/CompilerKit/Utilities
parentcfa04915a4c7d77996b49279b5891d1402f439a5 (diff)
chore: codebase chore and API breaking changes.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include/CompilerKit/Utilities')
-rw-r--r--include/CompilerKit/Utilities/DLL.h53
1 files changed, 28 insertions, 25 deletions
diff --git a/include/CompilerKit/Utilities/DLL.h b/include/CompilerKit/Utilities/DLL.h
index 490017e..8e32d2b 100644
--- a/include/CompilerKit/Utilities/DLL.h
+++ b/include/CompilerKit/Utilities/DLL.h
@@ -11,52 +11,55 @@
#include <mutex>
namespace CompilerKit {
-struct DLLTraits final {
- typedef Int32 (*Entrypoint)(Int32 argc, Char const* argv[]);
- using DLL = VoidPtr;
+class DLLLoader final {
+ public:
+ typedef Int32 (*EntryT)(Int32 argc, Char const* argv[]);
+ using DLL = VoidPtr;
+ using Mutex = std::mutex;
+ EntryT fEntrypoint{nullptr};
- DLL fDylib{nullptr};
- Entrypoint fEntrypoint{nullptr};
- std::mutex fMutex;
+ private:
+ DLL mDLL{nullptr};
+ Mutex mMutex;
- explicit operator bool() { return fDylib && fEntrypoint; }
-
- DLLTraits& operator()(const Char* path, const Char* fEntrypoint) {
- std::lock_guard<std::mutex> lock(this->fMutex);
+ public:
+ explicit operator bool() { return this->mDLL && this->fEntrypoint; }
+ DLLLoader& operator()(const Char* path, const Char* fEntrypoint) {
if (!path || !fEntrypoint) return *this;
- if (this->fDylib) {
- dlclose(this->fDylib);
- this->fDylib = nullptr;
+ std::lock_guard<Mutex> lock(this->mMutex);
+
+ if (this->mDLL) {
+ this->Destroy();
}
- this->fDylib = dlopen(path, RTLD_LAZY);
+ this->mDLL = ::dlopen(path, RTLD_LAZY);
- if (!this->fDylib) {
+ if (!this->mDLL) {
return *this;
}
- this->fEntrypoint = (Entrypoint) dlsym(this->fDylib, fEntrypoint);
+ this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, fEntrypoint));
if (!this->fEntrypoint) {
- dlclose(this->fDylib);
- this->fDylib = nullptr;
-
+ this->Destroy();
return *this;
}
return *this;
}
- NECTI_COPY_DELETE(DLLTraits)
+ NECTI_COPY_DELETE(DLLLoader)
- explicit DLLTraits() = default;
+ explicit DLLLoader() = default;
+ ~DLLLoader() { this->Destroy(); }
- ~DLLTraits() {
- if (this->fDylib) {
- dlclose(this->fDylib);
- this->fDylib = nullptr;
+ private:
+ void Destroy() noexcept {
+ if (this->mDLL) {
+ ::dlclose(this->mDLL);
+ this->mDLL = nullptr;
}
this->fEntrypoint = nullptr;