unbound 0.1
lock_verify.c File Reference

This file checks the lock traces generated by checklock.c. More...

#include "config.h"
#include "util/log.h"
#include "util/rbtree.h"
#include "util/locks.h"
#include "util/fptr_wlist.h"

Data Structures

struct  order_id
 keep track of lock id in lock-verify application More...
struct  order_lock
 a lock More...
struct  lock_ref
 reference to a lock in a rbtree set More...

Macros

#define STRMAX   1024
 max length of strings: filenames and function names.

Functions

static void usage (void)
 print program usage help
static int read_header (FILE *in)
 read header entry.
static int readup_str (char **str, FILE *in)
 read a string from file, false on error
static void read_create (rbtree_type *all, FILE *in)
 read creation entry
static struct order_lock * insert_lock (rbtree_type *all, struct order_id *id)
 insert lock entry (empty) into list
static void read_lock (rbtree_type *all, FILE *in, int val)
 read lock entry
static void readinput (rbtree_type *all, char *file)
 read input file
static void found_cycle (struct lock_ref *visit, int level)
 print cycle message
static int detect_cycle (struct lock_ref *visit, struct lock_ref *from)
 Detect cycle by comparing visited now with all (unvisited) bigger nodes.
static void search_cycle (struct lock_ref *visit, int level, struct lock_ref *from)
 recursive function to depth first search for cycles.
static void check_order_lock (struct order_lock *lock)
 Check ordering of one lock.
static void check_order (rbtree_type *all_locks)
 Check ordering of locks.
static void dellockref (rbnode_type *node, void *ATTR_UNUSED(arg))
 delete lock ref
static void delnode (rbnode_type *node, void *ATTR_UNUSED(arg))
 delete lock node
static void locks_free (rbtree_type *all_locks)
 delete allocated memory
int main (int argc, char *argv[])
 main program to verify all traces passed

Variables

static int errors_detected = 0
 count of errors detected
static int verb = 0
 verbose?

Detailed Description

This file checks the lock traces generated by checklock.c.

Checks if locks are consistently locked in the same order. If not, this can lead to deadlock if threads execute the different ordering at the same time.

Macro Definition Documentation

◆ STRMAX

#define STRMAX   1024

max length of strings: filenames and function names.

Referenced by readup_str().

Function Documentation

◆ usage()

void usage ( void )
static

print program usage help

References usage().

◆ read_header()

int read_header ( FILE * in)
static

read header entry.

Parameters
infile to read header of.
Returns
: False if it does not belong to the rest.

References fatal_exit(), and read_header().

Referenced by read_header(), and readinput().

◆ readup_str()

int readup_str ( char ** str,
FILE * in )
static

read a string from file, false on error

References fatal_exit(), readup_str(), and STRMAX.

Referenced by read_create(), read_lock(), and readup_str().

◆ read_create()

◆ insert_lock()

struct order_lock * insert_lock ( rbtree_type * all,
struct order_id * id )
static

◆ read_lock()

◆ readinput()

void readinput ( rbtree_type * all,
char * file )
static

read input file

References read_create(), read_header(), read_lock(), and readinput().

Referenced by main(), and readinput().

◆ found_cycle()

◆ detect_cycle()

int detect_cycle ( struct lock_ref * visit,
struct lock_ref * from )
static

Detect cycle by comparing visited now with all (unvisited) bigger nodes.

References detect_cycle(), order_lock::dfs_next, and lock_ref::lock.

Referenced by detect_cycle(), and search_cycle().

◆ search_cycle()

void search_cycle ( struct lock_ref * visit,
int level,
struct lock_ref * from )
static

recursive function to depth first search for cycles.

Parameters
visitthe lock visited at this step. its dfs_next pointer gives the visited lock up in recursion. same as lookfor at level 0.
leveldepth of recursion. 0 is start.
fromsearch for matches from unvisited node upwards.

References order_lock::create_file, order_lock::create_line, detect_cycle(), order_lock::dfs_next, fatal_exit(), found_cycle(), order_lock::id, order_id::instance, lock_ref::lock, RBTREE_FOR, search_cycle(), order_lock::smaller, order_id::thr, verb, and order_lock::visited.

Referenced by check_order_lock(), and search_cycle().

◆ check_order_lock()

◆ check_order()

void check_order ( rbtree_type * all_locks)
static

◆ dellockref()

void dellockref ( rbnode_type * node,
void * ATTR_UNUSEDarg )
static

delete lock ref

References dellockref(), lock_ref::file, and lock_ref::node.

Referenced by dellockref(), and delnode().

◆ delnode()

void delnode ( rbnode_type * node,
void * ATTR_UNUSEDarg )
static

◆ locks_free()

void locks_free ( rbtree_type * all_locks)
static

delete allocated memory

References delnode(), locks_free(), and traverse_postorder().

Referenced by locks_free(), and main().

◆ main()

int main ( int argc,
char * argv[] )

Variable Documentation

◆ errors_detected

int errors_detected = 0
static

count of errors detected

Referenced by found_cycle(), and main().