linux/drivers/tty/tty_ldsem.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Ldisc rw semaphore
 *
 * The ldisc semaphore is semantically a rw_semaphore but which enforces
 * an alternate policy, namely:
 *   1) Supports lock wait timeouts
 *   2) Write waiter has priority
 *   3) Downgrading is not supported
 *
 * Implementation notes:
 *   1) Upper half of semaphore count is a wait count (differs from rwsem
 *	in that rwsem normalizes the upper half to the wait bias)
 *   2) Lacks overflow checking
 *
 * The generic counting was copied and modified from include/asm-generic/rwsem.h
 * by Paul Mackerras <[email protected]>.
 *
 * The scheduling policy was copied and modified from lib/rwsem.c
 * Written by David Howells ([email protected]).
 *
 * This implementation incorporates the write lock stealing work of
 * Michel Lespinasse <[email protected]>.
 *
 * Copyright (C) 2013 Peter Hurley <[email protected]>
 */

#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/atomic.h>
#include <linux/tty.h>
#include <linux/sched.h>
#include <linux/sched/debug.h>
#include <linux/sched/task.h>


#if BITS_PER_LONG == 64
#define LDSEM_ACTIVE_MASK
#else
#define LDSEM_ACTIVE_MASK
#endif

#define LDSEM_UNLOCKED
#define LDSEM_ACTIVE_BIAS
#define LDSEM_WAIT_BIAS
#define LDSEM_READ_BIAS
#define LDSEM_WRITE_BIAS

struct ldsem_waiter {};

/*
 * Initialize an ldsem:
 */
void __init_ldsem(struct ld_semaphore *sem, const char *name,
		  struct lock_class_key *key)
{}

static void __ldsem_wake_readers(struct ld_semaphore *sem)
{}

static inline int writer_trylock(struct ld_semaphore *sem)
{}

static void __ldsem_wake_writer(struct ld_semaphore *sem)
{}

/*
 * handle the lock release when processes blocked on it that can now run
 * - if we come here from up_xxxx(), then:
 *   - the 'active part' of count (&0x0000ffff) reached 0 (but may have changed)
 *   - the 'waiting part' of count (&0xffff0000) is -ve (and will still be so)
 * - the spinlock must be held by the caller
 * - woken process blocks are discarded from the list after having task zeroed
 */
static void __ldsem_wake(struct ld_semaphore *sem)
{}

static void ldsem_wake(struct ld_semaphore *sem)
{}

/*
 * wait for the read lock to be granted
 */
static struct ld_semaphore __sched *
down_read_failed(struct ld_semaphore *sem, long count, long timeout)
{}

/*
 * wait for the write lock to be granted
 */
static struct ld_semaphore __sched *
down_write_failed(struct ld_semaphore *sem, long count, long timeout)
{}



static int __ldsem_down_read_nested(struct ld_semaphore *sem,
					   int subclass, long timeout)
{}

static int __ldsem_down_write_nested(struct ld_semaphore *sem,
					    int subclass, long timeout)
{}


/*
 * lock for reading -- returns 1 if successful, 0 if timed out
 */
int __sched ldsem_down_read(struct ld_semaphore *sem, long timeout)
{}

/*
 * trylock for reading -- returns 1 if successful, 0 if contention
 */
int ldsem_down_read_trylock(struct ld_semaphore *sem)
{}

/*
 * lock for writing -- returns 1 if successful, 0 if timed out
 */
int __sched ldsem_down_write(struct ld_semaphore *sem, long timeout)
{}

/*
 * trylock for writing -- returns 1 if successful, 0 if contention
 */
int ldsem_down_write_trylock(struct ld_semaphore *sem)
{}

/*
 * release a read lock
 */
void ldsem_up_read(struct ld_semaphore *sem)
{}

/*
 * release a write lock
 */
void ldsem_up_write(struct ld_semaphore *sem)
{}


#ifdef CONFIG_DEBUG_LOCK_ALLOC

int ldsem_down_read_nested(struct ld_semaphore *sem, int subclass, long timeout)
{}

int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
			    long timeout)
{}

#endif