diff options
| author | David Lamparter <equinox@diac24.net> | 2020-04-28 09:30:50 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2021-02-01 17:20:41 +0100 |
| commit | 60a3efec2458d9a1531f8204d0e4a91729d3fc00 (patch) | |
| tree | ad0208e9394bd9f2c08acb3791a77f97034ed821 /lib/thread.h | |
| parent | b2fa8c0fa30eaa72943c07786312923614ef355a (diff) | |
lib/xref: use to transport thread_* file/line/func
Just a better way of doing what was previously the "debugargdef" macro.
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/thread.h')
| -rw-r--r-- | lib/thread.h | 116 |
1 files changed, 73 insertions, 43 deletions
diff --git a/lib/thread.h b/lib/thread.h index eb1b107e7b..6b510fc4c9 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -27,6 +27,7 @@ #include "monotime.h" #include "frratomic.h" #include "typesafe.h" +#include "xref.h" #ifdef __cplusplus extern "C" { @@ -66,6 +67,14 @@ struct cancel_req { struct thread **threadref; }; +struct xref_threadsched { + struct xref xref; + + const char *funcname; + const char *dest; + uint32_t thread_type; +}; + /* Master of the theads. */ struct thread_master { char *name; @@ -107,9 +116,7 @@ struct thread { struct timeval real; struct cpu_thread_history *hist; /* cache pointer to cpu_history */ unsigned long yield; /* yield time in microseconds */ - const char *funcname; /* name of thread function */ - const char *schedfrom; /* source file thread was scheduled from */ - int schedfrom_line; /* line number of source file */ + const struct xref_threadsched *xref; /* origin location */ pthread_mutex_t mtx; /* mutex for thread.c functions */ }; @@ -156,17 +163,45 @@ struct cpu_thread_history { thread_cancel(&(thread)); \ } while (0) -#define debugargdef const char *funcname, const char *schedfrom, int fromln - -#define thread_add_read(m,f,a,v,t) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,t,#f,__FILE__,__LINE__) -#define thread_add_write(m,f,a,v,t) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,t,#f,__FILE__,__LINE__) -#define thread_add_timer(m,f,a,v,t) funcname_thread_add_timer(m,f,a,v,t,#f,__FILE__,__LINE__) -#define thread_add_timer_msec(m,f,a,v,t) funcname_thread_add_timer_msec(m,f,a,v,t,#f,__FILE__,__LINE__) -#define thread_add_timer_tv(m,f,a,v,t) funcname_thread_add_timer_tv(m,f,a,v,t,#f,__FILE__,__LINE__) -#define thread_add_event(m,f,a,v,t) funcname_thread_add_event(m,f,a,v,t,#f,__FILE__,__LINE__) -#define thread_execute(m,f,a,v) funcname_thread_execute(m,f,a,v,#f,__FILE__,__LINE__) -#define thread_execute_name(m, f, a, v, n) \ - funcname_thread_execute(m, f, a, v, n, __FILE__, __LINE__) +/* + * Macro wrappers to generate xrefs for all thread add calls. Includes + * file/line/function info for debugging/tracing. + */ +#include "lib/xref.h" + +#define _xref_t_a(addfn, type, m, f, a, v, t) \ + ({ \ + static const struct xref_threadsched _xref \ + __attribute__((used)) = { \ + .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \ + .funcname = #f, \ + .dest = #t, \ + .thread_type = THREAD_ ## type, \ + }; \ + XREF_LINK(_xref.xref); \ + _thread_add_ ## addfn(&_xref, m, f, a, v, t); \ + }) \ + /* end */ + +#define thread_add_read(m,f,a,v,t) _xref_t_a(read_write, READ, m,f,a,v,t) +#define thread_add_write(m,f,a,v,t) _xref_t_a(read_write, WRITE, m,f,a,v,t) +#define thread_add_timer(m,f,a,v,t) _xref_t_a(timer, TIMER, m,f,a,v,t) +#define thread_add_timer_msec(m,f,a,v,t) _xref_t_a(timer_msec, TIMER, m,f,a,v,t) +#define thread_add_timer_tv(m,f,a,v,t) _xref_t_a(timer_tv, TIMER, m,f,a,v,t) +#define thread_add_event(m,f,a,v,t) _xref_t_a(event, TIMER, m,f,a,v,t) + +#define thread_execute(m,f,a,v) \ + ({ \ + static const struct xref_threadsched _xref \ + __attribute__((used)) = { \ + .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \ + .funcname = #f, \ + .dest = NULL, \ + .thread_type = THREAD_EXECUTE, \ + }; \ + XREF_LINK(_xref.xref); \ + _thread_execute(&_xref, m, f, a, v); \ + }) /* end */ /* Prototypes. */ extern struct thread_master *thread_master_create(const char *); @@ -174,35 +209,30 @@ void thread_master_set_name(struct thread_master *master, const char *name); extern void thread_master_free(struct thread_master *); extern void thread_master_free_unused(struct thread_master *); -extern struct thread * -funcname_thread_add_read_write(int dir, struct thread_master *, - int (*)(struct thread *), void *, int, - struct thread **, debugargdef); - -extern struct thread *funcname_thread_add_timer(struct thread_master *, - int (*)(struct thread *), - void *, long, struct thread **, - debugargdef); - -extern struct thread * -funcname_thread_add_timer_msec(struct thread_master *, int (*)(struct thread *), - void *, long, struct thread **, debugargdef); - -extern struct thread *funcname_thread_add_timer_tv(struct thread_master *, - int (*)(struct thread *), - void *, struct timeval *, - struct thread **, - debugargdef); - -extern struct thread *funcname_thread_add_event(struct thread_master *, - int (*)(struct thread *), - void *, int, struct thread **, - debugargdef); - -extern void funcname_thread_execute(struct thread_master *, - int (*)(struct thread *), void *, int, - debugargdef); -#undef debugargdef +extern struct thread *_thread_add_read_write( + const struct xref_threadsched *xref, struct thread_master *master, + int (*fn)(struct thread *), void *arg, int fd, struct thread **tref); + +extern struct thread *_thread_add_timer( + const struct xref_threadsched *xref, struct thread_master *master, + int (*fn)(struct thread *), void *arg, long t, struct thread **tref); + +extern struct thread *_thread_add_timer_msec( + const struct xref_threadsched *xref, struct thread_master *master, + int (*fn)(struct thread *), void *arg, long t, struct thread **tref); + +extern struct thread *_thread_add_timer_tv( + const struct xref_threadsched *xref, struct thread_master *master, + int (*fn)(struct thread *), void *arg, struct timeval *tv, + struct thread **tref); + +extern struct thread *_thread_add_event( + const struct xref_threadsched *xref, struct thread_master *master, + int (*fn)(struct thread *), void *arg, int val, struct thread **tref); + +extern void _thread_execute(const struct xref_threadsched *xref, + struct thread_master *master, + int (*fn)(struct thread *), void *arg, int val); extern void thread_cancel(struct thread **event); extern void thread_cancel_async(struct thread_master *, struct thread **, |
