From: Alexander Holler <holler@ahsoftware.de>
To: linux-kernel@vger.kernel.org
Cc: linux-fbdev@vger.kernel.org,
Florian Tobias Schandinat <FlorianSchandinat@gmx.de>,
Bernie Thompson <bernie@plugable.com>,
Steve Glendinning <steve.glendinning@shawell.net>,
Alexander Holler <holler@ahsoftware.de>
Subject: [PATCH 1/3] semaphore: introduce down_timeout_killable()
Date: Fri, 25 Jan 2013 18:49:26 +0000 [thread overview]
Message-ID: <1359139768-32294-1-git-send-email-holler@ahsoftware.de> (raw)
In-Reply-To: <50F2A310.5010006@ahsoftware.de>
The name says it all, it's like down_timeout() but returns on fatal signals
too.
Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
include/linux/semaphore.h | 2 ++
kernel/semaphore.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
index dc368b8..b508d4d 100644
--- a/include/linux/semaphore.h
+++ b/include/linux/semaphore.h
@@ -41,6 +41,8 @@ extern int __must_check down_interruptible(struct semaphore *sem);
extern int __must_check down_killable(struct semaphore *sem);
extern int __must_check down_trylock(struct semaphore *sem);
extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
+extern int __must_check down_timeout_killable(struct semaphore *sem,
+ long jiffies);
extern void up(struct semaphore *sem);
#endif /* __LINUX_SEMAPHORE_H */
diff --git a/kernel/semaphore.c b/kernel/semaphore.c
index 4567fc0..4a5e823 100644
--- a/kernel/semaphore.c
+++ b/kernel/semaphore.c
@@ -37,6 +37,8 @@ static noinline void __down(struct semaphore *sem);
static noinline int __down_interruptible(struct semaphore *sem);
static noinline int __down_killable(struct semaphore *sem);
static noinline int __down_timeout(struct semaphore *sem, long jiffies);
+static noinline int __down_timeout_killable(struct semaphore *sem,
+ long jiffies);
static noinline void __up(struct semaphore *sem);
/**
@@ -169,6 +171,35 @@ int down_timeout(struct semaphore *sem, long jiffies)
EXPORT_SYMBOL(down_timeout);
/**
+ * down_timeout_killable - acquire the semaphore within a specified time or
+ * until a fatal signal arrives.
+ * @sem: the semaphore to be acquired
+ * @jiffies: how long to wait before failing
+ *
+ * Attempts to acquire the semaphore. If no more tasks are allowed to
+ * acquire the semaphore, calling this function will put the task to sleep.
+ * If the semaphore is not released within the specified number of jiffies,
+ * this function returns -ETIME. If the sleep is interrupted by a fatal signal,
+ * this function will return -EINTR. If the semaphore is successfully acquired,
+ * this function returns 0.
+ */
+int down_timeout_killable(struct semaphore *sem, long jiffies)
+{
+ unsigned long flags;
+ int result = 0;
+
+ raw_spin_lock_irqsave(&sem->lock, flags);
+ if (likely(sem->count > 0))
+ sem->count--;
+ else
+ result = __down_timeout_killable(sem, jiffies);
+ raw_spin_unlock_irqrestore(&sem->lock, flags);
+
+ return result;
+}
+EXPORT_SYMBOL(down_timeout_killable);
+
+/**
* up - release the semaphore
* @sem: the semaphore to release
*
@@ -253,6 +284,12 @@ static noinline int __sched __down_timeout(struct semaphore *sem, long jiffies)
return __down_common(sem, TASK_UNINTERRUPTIBLE, jiffies);
}
+static noinline int __sched __down_timeout_killable(struct semaphore *sem,
+ long jiffies)
+{
+ return __down_common(sem, TASK_KILLABLE, jiffies);
+}
+
static noinline void __sched __up(struct semaphore *sem)
{
struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list,
--
1.7.11.7
next prev parent reply other threads:[~2013-01-25 18:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-12 13:20 [PATCH] fb: udlfb: fix hang at disconnect Alexander Holler
2013-01-12 22:22 ` Bernie Thompson
2013-01-13 12:05 ` Alexander Holler
2013-01-13 12:24 ` Alexander Holler
2013-01-25 18:49 ` Alexander Holler [this message]
2013-01-25 18:49 ` [PATCH 2/3 v2] " Alexander Holler
2013-01-29 0:22 ` Andrew Morton
2013-01-29 0:56 ` Alexander Holler
2013-01-29 10:35 ` Alexander Holler
2013-01-29 11:11 ` Alexander Holler
2013-01-29 15:51 ` Alexander Holler
2013-01-29 20:35 ` Alexander Holler
2013-01-29 20:56 ` Alexander Holler
2013-02-04 1:14 ` Greg KH
2013-02-04 12:05 ` Alexander Holler
2013-02-04 19:17 ` Alexander Holler
2013-02-04 19:25 ` Greg KH
2013-02-05 7:08 ` Alexander Holler
2013-02-05 17:22 ` Greg KH
2013-02-05 17:36 ` Alexander Holler
2013-02-08 4:07 ` Dave Airlie
2013-02-08 9:53 ` Alexander Holler
2013-01-25 18:49 ` [PATCH 3/3] fb: smscufx: " Alexander Holler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359139768-32294-1-git-send-email-holler@ahsoftware.de \
--to=holler@ahsoftware.de \
--cc=FlorianSchandinat@gmx.de \
--cc=bernie@plugable.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=steve.glendinning@shawell.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).