lib/test_context-analysis.c

Source file repositories/reference/linux-study-clean/lib/test_context-analysis.c

File Facts

System
Linux kernel
Corpus path
lib/test_context-analysis.c
Extension
.c
Size
14898 bytes
Lines
634
Domain
Kernel Services
Bucket
lib
Inferred role
Kernel Services: implementation source
Status
source implementation candidate

Why This File Exists

Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.

Dependency Surface

Detected Declarations

Annotated Snippet

struct test_mutex_data {
	struct mutex mtx;
	int counter __guarded_by(&mtx);

	struct mutex mtx2;
	int anyread __guarded_by(&mtx, &mtx2);
	int *anyptr __pt_guarded_by(&mtx, &mtx2);
};

static void __used test_mutex_init(struct test_mutex_data *d)
{
	guard(mutex_init)(&d->mtx);
	d->counter = 0;
}

static void __used test_mutex_lock(struct test_mutex_data *d)
{
	mutex_lock(&d->mtx);
	d->counter++;
	mutex_unlock(&d->mtx);
	mutex_lock_io(&d->mtx);
	d->counter++;
	mutex_unlock(&d->mtx);
}

static void __used test_mutex_trylock(struct test_mutex_data *d, atomic_t *a)
{
	if (!mutex_lock_interruptible(&d->mtx)) {
		d->counter++;
		mutex_unlock(&d->mtx);
	}
	if (!mutex_lock_killable(&d->mtx)) {
		d->counter++;
		mutex_unlock(&d->mtx);
	}
	if (mutex_trylock(&d->mtx)) {
		d->counter++;
		mutex_unlock(&d->mtx);
	}
	if (atomic_dec_and_mutex_lock(a, &d->mtx)) {
		d->counter++;
		mutex_unlock(&d->mtx);
	}
}

static void __used test_mutex_assert(struct test_mutex_data *d)
{
	lockdep_assert_held(&d->mtx);
	d->counter++;
}

static void __used test_mutex_guard(struct test_mutex_data *d)
{
	guard(mutex)(&d->mtx);
	d->counter++;
}

static void __used test_mutex_cond_guard(struct test_mutex_data *d)
{
	scoped_cond_guard(mutex_try, return, &d->mtx) {
		d->counter++;
	}
	scoped_cond_guard(mutex_intr, return, &d->mtx) {
		d->counter++;
	}
}

static void __used test_mutex_multiguard(struct test_mutex_data *d)
{
	mutex_lock(&d->mtx);
	(void)d->anyread;
	(void)*d->anyptr;
	mutex_unlock(&d->mtx);

	mutex_lock(&d->mtx2);
	(void)d->anyread;
	(void)*d->anyptr;
	mutex_unlock(&d->mtx2);

	mutex_lock(&d->mtx);
	mutex_lock(&d->mtx2);
	d->anyread++;
	(*d->anyptr)++;
	mutex_unlock(&d->mtx2);
	mutex_unlock(&d->mtx);
}

struct test_seqlock_data {
	seqlock_t sl;
	int counter __guarded_by(&sl);

Annotation

Implementation Notes