X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fovs-thread.h;h=9527843f0268869be0e8fc44d08204dfbcf41d9d;hb=8ba0a5227f6e6b50838c157bd303c2d5bf6f4e59;hp=2e9a937f585b9ca44182abd1c9e2ca64266441a6;hpb=6b59b543c840ac82acc4d57f865c0b5e331ac590;p=sliver-openvswitch.git diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h index 2e9a937f5..9527843f0 100644 --- a/lib/ovs-thread.h +++ b/lib/ovs-thread.h @@ -146,11 +146,17 @@ void xpthread_cond_destroy(pthread_cond_t *); void xpthread_cond_signal(pthread_cond_t *); void xpthread_cond_broadcast(pthread_cond_t *); +/* Wrappers for pthread_barrier_*() that abort the process on any error. */ +void xpthread_barrier_init(pthread_barrier_t *, pthread_barrierattr_t *, + unsigned int count); +int xpthread_barrier_wait(pthread_barrier_t *); +void xpthread_barrier_destroy(pthread_barrier_t *); + void xpthread_key_create(pthread_key_t *, void (*destructor)(void *)); void xpthread_key_delete(pthread_key_t); void xpthread_setspecific(pthread_key_t, const void *); -void xpthread_create(pthread_t *, pthread_attr_t *, void *(*)(void *), void *); +pthread_t ovs_thread_create(const char *name, void *(*)(void *), void *); void xpthread_join(pthread_t, void **); /* Per-thread data. @@ -586,17 +592,34 @@ ovsthread_id_self(void) * * Fully thread-safe. */ -struct ovsthread_counter *ovsthread_counter_create(void); -void ovsthread_counter_destroy(struct ovsthread_counter *); -void ovsthread_counter_inc(struct ovsthread_counter *, unsigned long long int); -unsigned long long int ovsthread_counter_read( - const struct ovsthread_counter *); +struct ovsthread_stats { + struct ovs_mutex mutex; + void *volatile buckets[16]; +}; + +void ovsthread_stats_init(struct ovsthread_stats *); +void ovsthread_stats_destroy(struct ovsthread_stats *); + +void *ovsthread_stats_bucket_get(struct ovsthread_stats *, + void *(*new_bucket)(void)); + +#define OVSTHREAD_STATS_FOR_EACH_BUCKET(BUCKET, IDX, STATS) \ + for ((IDX) = ovs_thread_stats_next_bucket(STATS, 0); \ + ((IDX) < ARRAY_SIZE((STATS)->buckets) \ + ? ((BUCKET) = (STATS)->buckets[IDX], true) \ + : false); \ + (IDX) = ovs_thread_stats_next_bucket(STATS, (IDX) + 1)) +size_t ovs_thread_stats_next_bucket(const struct ovsthread_stats *, size_t); +bool single_threaded(void); + void assert_single_threaded_at(const char *where); #define assert_single_threaded() assert_single_threaded_at(SOURCE_LOCATOR) +#ifndef _WIN32 pid_t xfork_at(const char *where); #define xfork() xfork_at(SOURCE_LOCATOR) +#endif void forbid_forking(const char *reason); bool may_fork(void);