summaryrefslogtreecommitdiffstats
path: root/etc/inc/util.inc
diff options
context:
space:
mode:
authorErmal Luçi <eri@pfsense.org>2010-03-08 18:43:29 +0000
committerErmal Luçi <eri@pfsense.org>2010-03-08 18:43:29 +0000
commitef3af02ebeac16175dce8043e71bad8af393aded (patch)
tree56b27a5025d0e7bf2d507ec246e0652f946fc5dd /etc/inc/util.inc
parent3339fac0c4d8536aca2b1199a064197e3ef3d329 (diff)
downloadpfsense-ef3af02ebeac16175dce8043e71bad8af393aded.zip
pfsense-ef3af02ebeac16175dce8043e71bad8af393aded.tar.gz
Use shmop module to implement reference count calls.
Diffstat (limited to 'etc/inc/util.inc')
-rw-r--r--etc/inc/util.inc29
1 files changed, 29 insertions, 0 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index 7ae1eb8..ca06a2b 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -142,6 +142,35 @@ function unlock($cfglckkey = 0) {
return;
}
+function refcount_init($reference) {
+ $shmid = shmop_open(1000, "c", 0644, 10);
+ shmop_write($shmid, 0, 0);
+ shmop_close($shmid);
+}
+
+function refcount_reference($reference) {
+ $shmid = shmop_open(1000, "w", 0644, 10);
+ $shm_data = shmop_read($shmid, 0, 10);
+ $shm_data = intval($shm_data) + 1;
+ shmop_write($shmid, $shm_data, 0);
+ shmop_close($shmid);
+
+ return $shm_data;
+}
+
+function refcount_unreference($reference) {
+ /* We assume that the shared memory exists. */
+ $shmid = shmop_open(1000, "w", 0644, 10);
+ $shm_data = shmop_read($shmid, 0, 10);
+ $shm_data = intval($shm_data) - 1;
+ if ($shm_data < 0) {
+ //debug_backtrace();
+ log_error("Reference {$reference} is going negative, not doing unreference.");
+ } else
+ shmop_write($shmid, $shm_data, 0);
+ shmop_close($shmid);
+}
+
function is_module_loaded($module_name) {
$running = `/sbin/kldstat | grep {$module_name} | /usr/bin/grep -v grep | /usr/bin/wc -l`;
if (intval($running) >= 1)
OpenPOWER on IntegriCloud