summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2019-10-28 03:45:34 +0000
committermidipix <writeonce@midipix.org>2019-10-28 03:45:34 +0000
commit564b3cebdb1c8fffd078822e1971b9cfc8b29f23 (patch)
tree9507fb552307372c7fcafdd455138c6c19d7eee0 /src
parentf706466f0a2a67d893511a21a56f80af2d2b0973 (diff)
downloadsltdl-564b3cebdb1c8fffd078822e1971b9cfc8b29f23.tar.bz2
sltdl-564b3cebdb1c8fffd078822e1971b9cfc8b29f23.tar.xz
core: added lt_dlinit(), lt_dlexit() [global reference-counting].
Diffstat (limited to 'src')
-rw-r--r--src/core/lt_core.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/core/lt_core.c b/src/core/lt_core.c
new file mode 100644
index 0000000..b0c3952
--- /dev/null
+++ b/src/core/lt_core.c
@@ -0,0 +1,40 @@
+/*******************************************************************/
+/* sltdl: a surrogate ltdl implementation */
+/* Copyright (C) 2019 Z. Gilboa */
+/* Released under the Standard MIT License; see COPYING.SLTDL. */
+/*******************************************************************/
+
+#include <limits.h>
+#include <pthread.h>
+#include <sltdl/sltdl.h>
+
+static int lt_refs = 0;
+static pthread_mutex_t lt_lock = PTHREAD_MUTEX_INITIALIZER;
+
+int lt_dlinit(void)
+{
+ if (pthread_mutex_lock(&lt_lock))
+ return 1;
+
+ lt_refs++;
+ pthread_mutex_unlock(&lt_lock);
+
+ return 0;
+}
+
+int lt_dlexit(void)
+{
+ if (pthread_mutex_lock(&lt_lock))
+ return 1;
+
+ if (!lt_refs) {
+ pthread_mutex_unlock(&lt_lock);
+ return 1;
+ }
+
+ lt_refs--;
+
+ pthread_mutex_unlock(&lt_lock);
+
+ return 0;
+}