tools/lib/perf/include/internal/rc_check.h

Source file repositories/reference/linux-study-clean/tools/lib/perf/include/internal/rc_check.h

File Facts

System
Linux kernel
Corpus path
tools/lib/perf/include/internal/rc_check.h
Extension
.h
Size
3507 bytes
Lines
114
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct struct_name {				\
		struct original_##struct_name *orig;	\
	};						\
	struct original_##struct_name

/* Declare a reference counted struct variable. */
#define RC_STRUCT(struct_name) struct original_##struct_name

/*
 * Interpose the indirection. Result will hold the indirection and object is the
 * reference counted struct.
 */
#define ADD_RC_CHK(result, object)					\
	(								\
		object ? (result = malloc(sizeof(*result)),		\
			result ? (result->orig = object, result)	\
			: (result = NULL, NULL))			\
		: (result = NULL, NULL)					\
		)

/* Strip the indirection layer. */
#define RC_CHK_ACCESS(object) object->orig

/* Frees the object and the indirection layer. */
#define RC_CHK_FREE(object)			\
	do {					\
		zfree(&object->orig);		\
		free(object);			\
	} while(0)

/* A get operation adding the indirection layer. */
#define RC_CHK_GET(result, object) ADD_RC_CHK(result, (object ? object->orig : NULL))

/* A put operation removing the indirection layer. */
#define RC_CHK_PUT(object)			\
	do {					\
		if (object) {			\
			object->orig = NULL;	\
			free(object);		\
		}				\
	} while(0)

/* Pointer equality when the indirection may or may not be there. */
#define RC_CHK_EQUAL(object1, object2) (object1 == object2 || \
		(object1 && object2 && object1->orig == object2->orig))

#endif

#endif /* __LIBPERF_INTERNAL_RC_CHECK_H */

Annotation

Implementation Notes