File: lock.h

package info (click to toggle)
multipath-tools 0.5.0-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,800 kB
  • sloc: ansic: 26,772; sh: 844; makefile: 374
file content (33 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef _LOCK_H
#define _LOCK_H

#include <signal.h>

/*
 * Wrapper for the mutex. Includes a ref-count to keep
 * track of how many there are out-standing threads blocking
 * on a mutex. */
struct mutex_lock {
	pthread_mutex_t *mutex;
	int depth;
};

#ifdef LCKDBG
#define lock(a) \
		fprintf(stderr, "%s:%s(%i) lock %p depth: %d (%ld)\n", __FILE__, __FUNCTION__, __LINE__, a.mutex, a.depth, pthread_self()); \
		a.depth++; pthread_mutex_lock(a.mutex)
#define unlock(a) \
		fprintf(stderr, "%s:%s(%i) unlock %p depth: %d (%ld)\n", __FILE__, __FUNCTION__, __LINE__, a.mutex, a.depth, pthread_self()); \
	a.depth--; pthread_mutex_unlock(a.mutex)
#define lock_cleanup_pop(a) \
		fprintf(stderr, "%s:%s(%i) unlock %p depth: %d (%ld)\n", __FILE__, __FUNCTION__, __LINE__, a.mutex, a.depth, pthread_self()); \
	pthread_cleanup_pop(1);
#else
#define lock(a) a.depth++; pthread_mutex_lock(a.mutex)
#define unlock(a) a.depth--; pthread_mutex_unlock(a.mutex)
#define lock_cleanup_pop(a) pthread_cleanup_pop(1);
#endif

void cleanup_lock (void * data);

#endif /* _LOCK_H */