Skip to content

Commit

Permalink
__UNIQUE_ID()
Browse files Browse the repository at this point in the history
Jan Beulich points out __COUNTER__ (gcc 4.3 and above), so let's use
that to create unique ids.  This is better than __LINE__ which we use
today, so provide a wrapper.

Stanislaw Gruszka <[email protected]> reported that some module parameters
start with a digit, so we need to prepend when we for the unique id.

Signed-off-by: Rusty Russell <[email protected]>
Acked-by: Jan Beulich <[email protected]>
  • Loading branch information
rustyrussell committed Dec 14, 2012
1 parent d890f51 commit 6f33d58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/linux/compiler-gcc4.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#define __linktime_error(message) __attribute__((__error__(message)))

#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)

#if __GNUC_MINOR__ >= 5
/*
* Mark a position in code as unreachable. This can be used to
Expand Down
9 changes: 9 additions & 0 deletions include/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ extern void __chk_io_ptr(const volatile void __iomem *);
# define __rcu
#endif

/* Indirect macros required for expanded argument pasting, eg. __LINE__. */
#define ___PASTE(a,b) a##b
#define __PASTE(a,b) ___PASTE(a,b)

#ifdef __KERNEL__

#ifdef __GNUC__
Expand Down Expand Up @@ -164,6 +168,11 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
(typeof(ptr)) (__ptr + (off)); })
#endif

/* Not-quite-unique ID. */
#ifndef __UNIQUE_ID
# define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__)
#endif

#endif /* __KERNEL__ */

#endif /* __ASSEMBLY__ */
Expand Down

0 comments on commit 6f33d58

Please sign in to comment.