Skip to content

Development (re usage)

Sebastian Reimers edited this page May 15, 2022 · 12 revisions

Development

Include headers

Preferred order:

  1. System/Third party headers
  2. libre headers
  3. 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.

Conflicting macro definitions

You can #undef conflicting definitions before libre header include:

#include <sys/queue.h>
#undef LIST_INIT
#undef LIST_FOREACH
#include <re.h>

Multithreading

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);
...

See retest remain.c for a complete example.

Clone this wiki locally