Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Wrapper or callback on thread creation #310

@eqvinox

Description

@eqvinox

Description of current state

rtr_start creates a thread in

int rtval = pthread_create(&(rtr_socket->thread_id), NULL, (void *(*)(void *)) & rtr_fsm_start, rtr_socket);

which runs, as the thread main function, rtr_fsm_start(), which more or less directly proceeds into a loop:

rtrlib/rtrlib/rtr/rtr.c

Lines 114 to 126 in c17fafc

/* WARNING: This Function has cancelable sections*/
void *rtr_fsm_start(struct rtr_socket *rtr_socket)
{
if (rtr_socket->state == RTR_SHUTDOWN)
return NULL;
// We don't care about the old state, but POSIX demands a non null value for setcancelstate
int oldcancelstate;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
rtr_socket->state = RTR_CONNECTING;
while (1) {

Improvement

We (FRR) would really like some way to run some code in the freshly created thread before anything else. This could be done either with exposing rtr_fsm_start, or having some way to pass in a function pointer that will be called at the top of the new thread.

Useful links

The reason we need this is to initialize the per-thread RCU data, otherwise it's not possible to call FRR logging functions from other rtrlib callbacks.

https://github.com/FRRouting/frr/blob/e2bf684f9a137837b9bbf21ccf6fcce55f1ff961/lib/frrcu.c#L173-L194

(rcu_thread_prepare is called before creating the thread, rcu_thread_start after/inside.)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions