lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <45D23E87.2030805@nortel.com>
Date:	Tue, 13 Feb 2007 16:41:11 -0600
From:	"Chris Friesen" <cfriesen@...tel.com>
To:	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: whatever happened to down_timeout()?


There has been some discussion on lkml about a function that would 
either down a semaphore or else abort if it couldn't get the semaphore 
in a certain amount of time.  Something along the lines of:

down_timeout(struct semaphore *sem, long timeout);


Does something like this exist?  Does anyone have a working 
implementation?  Does anyone see anything obviously wrong with the 
following version (that I loosely based on one by Rupert Eibauer)?



semaphore.h:

extern int __down_timeout(struct semaphore * sem, unsigned int timeout);


/* "timeout" is the number of jiffies to wait.
  * Returns -ETIME if timeout period expires.
  */
static inline int down_timeout(struct semaphore * sem, unsigned int timeout)
{
	int ret = down_trylock(sem);
	if (!ret)
		ret = __down_timeout(sem, timeout);
	return ret;
}




kernel/timer.c

int __down_timeout(struct semaphore * sem, int timeout)
{
	int ret;
	unsigned long expire;
	struct timer_list timer;

	expire = jiffies + timeout;
	init_timer(&timer);
	timer.expires = expire;
	timer.data = (unsigned long) current;
	timer.function = process_timeout;
	add_timer(&timer);

	ret = down_interruptible(sema);
	if (ret && (jiffies > expire))
		ret = -ETIME;
	 else
		del_timer_sync(&timer);

         return ret;
}


Thanks,
Chris
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ