Skip to content

Commit

Permalink
Use a separate data structure for the scheduler
Browse files Browse the repository at this point in the history
This makes it easier to test in isolation, and cleans up the pnet_t struct
  • Loading branch information
Jonas Berg committed Jun 8, 2022
1 parent c5c98b5 commit 1db5613
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 221 deletions.
8 changes: 5 additions & 3 deletions src/common/pf_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ static void pf_alarm_apms_timeout (

if (
pf_scheduler_add (
net,
&net->scheduler_data,
p_apmx->timeout_us,
pf_alarm_apms_timeout,
p_apmx,
Expand Down Expand Up @@ -1462,7 +1462,7 @@ static int pf_alarm_apms_apms_a_data_req (
retransmission timer */
if (
pf_scheduler_add (
net,
&net->scheduler_data,
p_apmx->timeout_us,
pf_alarm_apms_timeout,
p_apmx,
Expand Down Expand Up @@ -1552,7 +1552,9 @@ static int pf_alarm_apmx_close (pnet_t * net, pf_ar_t * p_ar, uint8_t err_code)
{
/* Free resources */
/* StopTimer */
pf_scheduler_remove_if_running (net, &p_ar->apmx[ix].resend_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_ar->apmx[ix].resend_timeout);

p_ar->apmx[ix].p_ar = NULL;
p_ar->apmx[ix].apms_state = PF_APMS_STATE_CLOSED;
Expand Down
6 changes: 3 additions & 3 deletions src/common/pf_cpm_driver_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void pf_cpm_control_interval_expired (
/* Timer auto-reload */
if (
pf_scheduler_add (
net,
&net->scheduler_data,
p_iocr->cpm.control_interval,
pf_cpm_control_interval_expired,
arg,
Expand Down Expand Up @@ -155,7 +155,7 @@ static int pf_cpm_driver_sw_close_req (
pf_cpm_t * p_cpm = &p_ar->iocrs[crep].cpm;

p_cpm->ci_running = false; /* StopTimer */
pf_scheduler_remove_if_running (net, &p_cpm->ci_timeout);
pf_scheduler_remove_if_running (&net->scheduler_data, &p_cpm->ci_timeout);

pf_eth_frame_id_map_remove (net, p_cpm->frame_id[0]);
if (p_cpm->nbr_frame_id == 2)
Expand Down Expand Up @@ -425,7 +425,7 @@ static int pf_cpm_driver_sw_activate_req (
}
pf_scheduler_init_handle (&p_cpm->ci_timeout, "cpm");
ret = pf_scheduler_add (
net,
&net->scheduler_data,
p_cpm->control_interval,
pf_cpm_control_interval_expired,
p_iocr,
Expand Down
8 changes: 4 additions & 4 deletions src/common/pf_dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void pf_dcp_restart_sam_timeout (pnet_t * net, const pnet_ethaddr_t * mac

memcpy (&net->dcp_sam, mac, sizeof (net->dcp_sam));
(void)pf_scheduler_restart (
net,
&net->scheduler_data,
PF_DCP_SAM_TIMEOUT,
pf_dcp_clear_sam,
NULL,
Expand Down Expand Up @@ -627,7 +627,7 @@ static void pf_dcp_control_signal_led (

/* Schedule another round */
(void)pf_scheduler_add (
net,
&net->scheduler_data,
PF_DCP_SIGNAL_LED_HALF_INTERVAL,
pf_dcp_control_signal_led,
(void *)(uintptr_t)state,
Expand Down Expand Up @@ -659,7 +659,7 @@ int pf_dcp_trigger_signal_led (pnet_t * net)
"DCP(%d): Received request to flash LED\n",
__LINE__);
(void)pf_scheduler_add (
net,
&net->scheduler_data,
PF_DCP_SIGNAL_LED_HALF_INTERVAL,
pf_dcp_control_signal_led,
(void *)(2 * PF_DCP_SIGNAL_LED_NUMBER_OF_FLASHES - 1),
Expand Down Expand Up @@ -1945,7 +1945,7 @@ static int pf_dcp_identify_req (
#endif

(void)pf_scheduler_add (
net,
&net->scheduler_data,
response_delay,
pf_dcp_responder,
p_rsp,
Expand Down
18 changes: 12 additions & 6 deletions src/common/pf_lldp.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ void pf_lldp_restart_peer_timeout (
{
pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num);

pf_scheduler_remove_if_running (net, &p_port_data->lldp.rx_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_port_data->lldp.rx_timeout);

/*
* Profinet states that the time to live shall be 20 seconds,
Expand All @@ -529,7 +531,7 @@ void pf_lldp_restart_peer_timeout (

if (
pf_scheduler_add (
net,
&net->scheduler_data,
timeout_in_secs * 1000000,
pf_lldp_receive_timeout,
p_port_data,
Expand All @@ -547,7 +549,9 @@ void pf_lldp_stop_peer_timeout (pnet_t * net, int loc_port_num)
{
pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num);

pf_scheduler_remove_if_running (net, &p_port_data->lldp.rx_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_port_data->lldp.rx_timeout);
}

/**
Expand Down Expand Up @@ -1096,7 +1100,7 @@ static void pf_lldp_trigger_sending (

if (
pf_scheduler_add (
net,
&net->scheduler_data,
PF_LLDP_SEND_INTERVAL * 1000,
pf_lldp_trigger_sending,
p_port_data,
Expand Down Expand Up @@ -1125,7 +1129,7 @@ static void pf_lldp_tx_restart (pnet_t * net, int loc_port_num, bool send)

if (
pf_scheduler_restart (
net,
&net->scheduler_data,
PF_LLDP_SEND_INTERVAL * 1000,
pf_lldp_trigger_sending,
p_port_data,
Expand Down Expand Up @@ -1187,7 +1191,9 @@ void pf_lldp_send_disable (pnet_t * net, int loc_port_num)
"LLDP(%d): Disabling LLDP transmission for port %d\n",
__LINE__,
loc_port_num);
pf_scheduler_remove_if_running (net, &p_port_data->lldp.tx_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_port_data->lldp.tx_timeout);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/common/pf_ppm_driver_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void pf_ppm_drv_sw_send (pnet_t * net, void * arg, uint32_t current_time)
delay = p_arg->ppm.next_exec - current_time;
if (
pf_scheduler_add (
net,
&net->scheduler_data,
delay,
pf_ppm_drv_sw_send,
arg,
Expand Down Expand Up @@ -102,7 +102,7 @@ int pf_ppm_drv_sw_activate_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep)

pf_scheduler_init_handle (&p_ppm->ci_timeout, "ppm");
ret = pf_scheduler_add (
net,
&net->scheduler_data,
p_ppm->control_interval,
pf_ppm_drv_sw_send,
p_iocr,
Expand All @@ -124,7 +124,7 @@ int pf_ppm_drv_sw_close_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep)
p_ar->arep,
crep);

pf_scheduler_remove_if_running (net, &p_ppm->ci_timeout);
pf_scheduler_remove_if_running (&net->scheduler_data, &p_ppm->ci_timeout);

return 0;
}
Expand Down
Loading

0 comments on commit 1db5613

Please sign in to comment.