summaryrefslogtreecommitdiff
path: root/lib/frr_pthread.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/frr_pthread.h')
-rw-r--r--lib/frr_pthread.h34
1 files changed, 29 insertions, 5 deletions
diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h
index 2cc50196a8..3990e2a4ce 100644
--- a/lib/frr_pthread.h
+++ b/lib/frr_pthread.h
@@ -1,6 +1,6 @@
/*
* Utilities and interfaces for managing POSIX threads within FRR.
- * Copyright (C) 2017 Cumulus Networks
+ * Copyright (C) 2017 Cumulus Networks, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,14 +32,19 @@ struct frr_pthread;
struct frr_pthread_attr;
struct frr_pthread_attr {
- int id;
+ _Atomic uint32_t id;
void *(*start)(void *);
int (*stop)(struct frr_pthread *, void **);
- const char *name;
};
struct frr_pthread {
+ /*
+ * Mutex protecting this structure. Must be taken for reading some
+ * fields, denoted by a 'Requires: mtx'.
+ */
+ pthread_mutex_t mtx;
+
/* pthread id */
pthread_t thread;
@@ -73,8 +78,17 @@ struct frr_pthread {
* Fake thread-specific storage. No constraints on usage. Helpful when
* creating reentrant pthread implementations. Can be used to pass
* argument to pthread entry function.
+ *
+ * Requires: mtx
*/
void *data;
+
+ /*
+ * Human-readable thread name.
+ *
+ * Requires: mtx
+ */
+ char *name;
};
extern struct frr_pthread_attr frr_pthread_attr_default;
@@ -107,9 +121,19 @@ void frr_pthread_finish(void);
* frr_pthread will cause them to run on that pthread.
*
* @param attr - the thread attributes
+ * @param name - Human-readable name
* @return the created frr_pthread upon success, or NULL upon failure
*/
-struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr);
+struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
+ const char *name);
+
+/*
+ * Changes the name of the frr_pthread.
+ *
+ * @param fpt - the frr_pthread to operate on
+ * @param name - Human-readable name
+ */
+void frr_pthread_set_name(struct frr_pthread *fpt, const char *name);
/*
* Destroys an frr_pthread.
@@ -198,6 +222,6 @@ void frr_pthread_yield(void);
*
* @return unique identifier
*/
-unsigned int frr_pthread_get_id(void);
+uint32_t frr_pthread_get_id(void);
#endif /* _FRR_PTHREAD_H */