-
Notifications
You must be signed in to change notification settings - Fork 84
Development (re usage)
Preferred order:
- System/Third party headers
- libre headers
- Local/Custom headers
Example
#include <string.h>
#include <re.h>
#include "custom.h"
Within libre itself use the specific headers like re_types.h
etc.
You can #undef
conflicting definitions before libre header include:
#include <sys/queue.h>
#undef LIST_INIT
#undef LIST_FOREACH
#include <re.h>
By default re_main()
is single threaded. You can register multiple worker threads with re_thread_init()
like so:
static int thread_handler(void *arg)
{
re_thread_init();
/* register network/tmr callbacks */
err = re_main(NULL); /* Start new worker eventloop */
re_thread_close();
}
...
thr_t tid;
thrd_create(&tid, thread_handler, NULL);
...
Keep in mind the new worker eventloop only handles file descriptors which are registered by the same thread (fd_listen). You can use fd_close and fd_listen to detach/attach file descriptors from another thread (e.g. main thread). For example udp has already some nice helpers for this "udp_thread_attach/udp_thread_detach".
See retest remain.c for a complete example.
If you need to call functions from another thread you can use re_thread_leave
and re_thread_enter
. This works only for the first re main thread and not for other re worker threads.
For details see: https://github.com/baresip/baresip/wiki/Using-baresip-as-a-library#examples-using-re-lock