Skip to content

Commit

Permalink
add the worker directly to the network thread
Browse files Browse the repository at this point in the history
@todo - perhaps assert that we don't mix "same-thread" workers
with "different-thread" workers?
  • Loading branch information
alandekok committed Oct 30, 2024
1 parent 0d0524c commit 9ccf1b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/lib/io/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ int fr_network_directory_add(fr_network_t *nr, fr_listen_t *li)
return fr_control_message_send(nr->control, rb, FR_CONTROL_ID_DIRECTORY, &li, sizeof(li));
}

/** Add a worker to a network
/** Add a worker to a network in a different thread
*
* @param nr the network
* @param worker the worker
Expand All @@ -303,6 +303,19 @@ int fr_network_worker_add(fr_network_t *nr, fr_worker_t *worker)
return fr_control_message_send(nr->control, rb, FR_CONTROL_ID_WORKER, &worker, sizeof(worker));
}

static void fr_network_worker_started_callback(void *ctx, void const *data, size_t data_size, fr_time_t now);

/** Add a worker to a network in the same thread
*
* @param nr the network
* @param worker the worker
*/
void fr_network_worker_add_self(fr_network_t *nr, fr_worker_t *worker)
{
fr_network_worker_started_callback(nr, &worker, sizeof(worker), fr_time_wrap(0));
}


/** Signal the network to read from a listener
*
* @param nr the network
Expand Down
2 changes: 2 additions & 0 deletions src/lib/io/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ int fr_network_directory_add(fr_network_t *nr, fr_listen_t *li) CC_HINT(nonnull

int fr_network_worker_add(fr_network_t *nr, fr_worker_t *worker) CC_HINT(nonnull);

void fr_network_worker_add_self(fr_network_t *nr, fr_worker_t *worker) CC_HINT(nonnull);

void fr_network_listen_read(fr_network_t *nr, fr_listen_t *li) CC_HINT(nonnull);

void fr_network_listen_write(fr_network_t *nr, fr_listen_t *li, uint8_t const *packet, size_t packet_len,
Expand Down
6 changes: 5 additions & 1 deletion src/lib/io/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,11 @@ fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el,
goto st_fail;
}

(void) fr_network_worker_add(sc->single_network, sc->single_worker);
/*
* Register the worker with the network, so
* things like fr_network_send_request() work.
*/
fr_network_worker_add_self(sc->single_network, sc->single_worker);
DEBUG("Scheduler created in single-threaded mode");

if (fr_event_pre_insert(el, fr_worker_pre_event, sc->single_worker) < 0) {
Expand Down

0 comments on commit 9ccf1b7

Please sign in to comment.