Motr  M0
rwlock.c File Reference
#include "ut/ut.h"
#include "lib/thread.h"
#include "lib/rwlock.h"
#include "lib/assert.h"
#include "lib/semaphore.h"
Include dependency graph for rwlock.c:

Go to the source code of this file.

Enumerations

enum  { NR = 255, S = 8, C = 3 }
 

Functions

 M0_BASSERT (S+C<=NR)
 
static void writer (int n)
 
static void reader (int n)
 
static void wstarver (int x)
 
static void rstarver (int x)
 
static void rcheck (int x)
 
static void wcheck (int x)
 
static void test_rw_writers (void)
 
static void test_rw_readers (void)
 
static void test_rw_excl (void)
 
static void test_rw_rstarve (void)
 
static void test_rw_wstarve (void)
 
void test_rw (void)
 

Variables

static int counter
 
static struct m0_thread t [NR]
 
static struct m0_rwlock m
 
static int sum
 
static struct m0_semaphore p
 
static struct m0_semaphore q
 
static int stop
 
static int i
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NR 

Definition at line 33 of file rwlock.c.

Function Documentation

◆ M0_BASSERT()

M0_BASSERT ( S+C<=  NR)

◆ rcheck()

static void rcheck ( int  x)
static

Definition at line 100 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reader()

static void reader ( int  n)
static

Definition at line 70 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rstarver()

static void rstarver ( int  x)
static

Definition at line 89 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_rw()

void test_rw ( void  )

Definition at line 263 of file rwlock.c.

Here is the call graph for this function:

◆ test_rw_excl()

static void test_rw_excl ( void  )
static

Unit test: test that readers exclude writers.

Definition at line 164 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_rw_readers()

static void test_rw_readers ( void  )
static

Unit test: test that multiple readers are allowed.

Definition at line 139 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_rw_rstarve()

static void test_rw_rstarve ( void  )
static

Unit test: readers are not starved.

Note
Careful: rwlocks are not, in fact, fair. If S is increased, the starvation tests might become too slow.

Definition at line 200 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_rw_writers()

static void test_rw_writers ( void  )
static

Unit test: mutual exclusion of writers is provided.

Definition at line 115 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_rw_wstarve()

static void test_rw_wstarve ( void  )
static

Unit test: writers are not starved.

Definition at line 234 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wcheck()

static void wcheck ( int  x)
static

Definition at line 106 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writer()

static void writer ( int  n)
static

Definition at line 59 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wstarver()

static void wstarver ( int  x)
static

Definition at line 79 of file rwlock.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ counter

int counter
static

Definition at line 50 of file rwlock.c.

◆ i

int i
static

Definition at line 57 of file rwlock.c.

◆ m

struct m0_rwlock m
static

Definition at line 52 of file rwlock.c.

◆ p

struct m0_semaphore p
static

Definition at line 54 of file rwlock.c.

◆ q

struct m0_semaphore q
static

Definition at line 55 of file rwlock.c.

◆ stop

int stop
static

Definition at line 56 of file rwlock.c.

◆ sum

int sum
static

Definition at line 53 of file rwlock.c.

◆ t

struct m0_thread t[NR]
static

Definition at line 51 of file rwlock.c.