aboutsummaryrefslogtreecommitdiffstats
path: root/plpa-1.1/src/plpa_runtime.c
diff options
context:
space:
mode:
authorEugene V. Lyubimkin <jackyf.devel@gmail.com>2008-11-16 20:36:18 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:23 +0200
commitbcb965d78ae0b4599fe77a2d641b3ff035658fc9 (patch)
tree59066e7fa5473b02eefaea37ac015cfaea7cd7c6 /plpa-1.1/src/plpa_runtime.c
parent2eabf3432b05b93ce4de9af283ae549d0f7c18c8 (diff)
parentc74c38760df69bb87e93dff18cf91464e5d02f37 (diff)
downloaddebian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.tar.gz
debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.tar.bz2
debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.zip
Imported Debian patch 0.8.1-1debian/0.8.1-1
Diffstat (limited to 'plpa-1.1/src/plpa_runtime.c')
-rw-r--r--plpa-1.1/src/plpa_runtime.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/plpa-1.1/src/plpa_runtime.c b/plpa-1.1/src/plpa_runtime.c
new file mode 100644
index 0000000..b5a8c05
--- /dev/null
+++ b/plpa-1.1/src/plpa_runtime.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
+ */
+
+#include "plpa_config.h"
+#include "plpa.h"
+#include "plpa_internal.h"
+
+#include <errno.h>
+#include <pthread.h>
+
+/* Global variables */
+int PLPA_NAME(initialized) = 0;
+
+/* Local variables */
+static int refcount = 0;
+static pthread_mutex_t mutex;
+
+
+/* Central clearing point for all parts of PLPA that need to be
+ initialized. It is erroneous to call this function by more than
+ one thread simultaneously. */
+int PLPA_NAME(init)(void)
+{
+ int ret;
+
+ /* If we're already initialized, simply increase the refcount */
+ if (PLPA_NAME(initialized)) {
+ pthread_mutex_lock(&mutex);
+ ++refcount;
+ pthread_mutex_unlock(&mutex);
+ return 0;
+ }
+
+ /* Otherwise, initialize all the sybsystems */
+ if (0 != (ret = pthread_mutex_init(&mutex, NULL)) ||
+ 0 != (ret = PLPA_NAME(api_probe_init)()) ||
+ 0 != (ret = PLPA_NAME(map_init)())) {
+ return ret;
+ }
+
+ PLPA_NAME(initialized) = 1;
+ refcount = 1;
+ return 0;
+}
+
+
+/* Central clearing point for all parts of PLPA that need to be
+ shutdown. */
+int PLPA_NAME(finalize)(void)
+{
+ int val;
+
+ /* If we're not initialized, return an error */
+ if (!PLPA_NAME(initialized)) {
+ return ENOENT;
+ }
+
+ /* Decrement and check the refcount. If it's nonzero, then simply
+ return success. */
+ pthread_mutex_lock(&mutex);
+ val = --refcount;
+ pthread_mutex_unlock(&mutex);
+ if (0 != val) {
+ return 0;
+ }
+
+ /* Ok, we're the last one. Cleanup. */
+ PLPA_NAME(map_finalize)();
+ pthread_mutex_destroy(&mutex);
+ PLPA_NAME(initialized) = 0;
+ return 0;
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy