From ef3af02ebeac16175dce8043e71bad8af393aded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ermal=20Lu=E7i?= Date: Mon, 8 Mar 2010 18:43:29 +0000 Subject: [PATCH] Use shmop module to implement reference count calls. --- etc/inc/util.inc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/etc/inc/util.inc b/etc/inc/util.inc index 7ae1eb8825..ca06a2bb5c 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)