diff options
author | Ben Pfaff <blp@nicira.com> | 2013-08-06 14:57:19 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2013-08-08 13:18:10 -0700 |
commit | 6878fada586a8ed5f45a50f9c8834dcf06bdc1f5 (patch) | |
tree | a716be3e6527287cf0e80b615104cbc9be95deb1 /lib/ovs-thread.h | |
parent | 2ba4f163d9ea84aa8b8e9d8678371a70af766b5e (diff) | |
download | openvswitch-6878fada586a8ed5f45a50f9c8834dcf06bdc1f5.tar.gz |
ovs-thread: New function ovsthread_id_self().
I foresee a need for possibly large numbers of instances of "struct
seq" (which is introduced in an upcoming patch). Each struct seq
needs some per-thread data. POSIX has pthread_key_t for this, but
the number of keys can be fairly limited, to as few as 128. It is
reasonable to work around this by using a hash table indexed on the
current thread. That only works if one can get a thread identifier
that is hashable (pthread_t is not). This patch introduces a
hashable thread identifier.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/ovs-thread.h')
-rw-r--r-- | lib/ovs-thread.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h index abe479ae6..e644832b2 100644 --- a/lib/ovs-thread.h +++ b/lib/ovs-thread.h @@ -501,6 +501,23 @@ ovsthread_once_start(struct ovsthread_once *once) ((ONCE)->done ? false : ({ OVS_MACRO_LOCK((&ONCE->mutex)); true; })) #endif +/* Thread ID. + * + * pthread_t isn't so nice for some purposes. Its size and representation are + * implementation dependent, which means that there is no way to hash it. + * This thread ID avoids the problem. + */ + +DECLARE_EXTERN_PER_THREAD_DATA(unsigned int, ovsthread_id); + +/* Returns a per-thread identifier unique within the lifetime of the + * process. */ +static inline unsigned int +ovsthread_id_self(void) +{ + return *ovsthread_id_get(); +} + void assert_single_threaded_at(const char *where); #define assert_single_threaded() assert_single_threaded_at(SOURCE_LOCATOR) |