Contributors: 12
Author Tokens Token Proportion Commits Commit Proportion
Matthew Wilcox 61 29.19% 5 22.73%
Chris Zankel 45 21.53% 2 9.09%
Linus Torvalds (pre-git) 27 12.92% 3 13.64%
Lance Yang 26 12.44% 1 4.55%
David Howells 20 9.57% 2 9.09%
Thomas Gleixner 9 4.31% 3 13.64%
Andi Kleen 5 2.39% 1 4.55%
Peter Zijlstra 5 2.39% 1 4.55%
David S. Miller 4 1.91% 1 4.55%
Alan Cox 3 1.44% 1 4.55%
Masami Hiramatsu 3 1.44% 1 4.55%
Adrian Bunk 1 0.48% 1 4.55%
Total 209 22


/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2008 Intel Corporation
 * Author: Matthew Wilcox <willy@linux.intel.com>
 *
 * Please see kernel/locking/semaphore.c for documentation of these functions
 */
#ifndef __LINUX_SEMAPHORE_H
#define __LINUX_SEMAPHORE_H

#include <linux/list.h>
#include <linux/spinlock.h>

/* Please don't access any members of this structure directly */
struct semaphore {
	raw_spinlock_t		lock;
	unsigned int		count;
	struct list_head	wait_list;

#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
	unsigned long		last_holder;
#endif
};

#ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER
#define __LAST_HOLDER_SEMAPHORE_INITIALIZER				\
	, .last_holder = 0UL
#else
#define __LAST_HOLDER_SEMAPHORE_INITIALIZER
#endif

#define __SEMAPHORE_INITIALIZER(name, n)				\
{									\
	.lock		= __RAW_SPIN_LOCK_UNLOCKED((name).lock),	\
	.count		= n,						\
	.wait_list	= LIST_HEAD_INIT((name).wait_list)		\
	__LAST_HOLDER_SEMAPHORE_INITIALIZER				\
}

/*
 * Unlike mutexes, binary semaphores do not have an owner, so up() can
 * be called in a different thread from the one which called down().
 * It is also safe to call down_trylock() and up() from interrupt
 * context.
 */
#define DEFINE_SEMAPHORE(_name, _n)	\
	struct semaphore _name = __SEMAPHORE_INITIALIZER(_name, _n)

static inline void sema_init(struct semaphore *sem, int val)
{
	static struct lock_class_key __key;
	*sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
	lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
}

extern void down(struct semaphore *sem);
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 void up(struct semaphore *sem);
extern unsigned long sem_last_holder(struct semaphore *sem);

#endif /* __LINUX_SEMAPHORE_H */