Skip to content

Commit 091bddd

Browse files
pabigotjukkar
authored andcommitted
net: Conversion of k_work API
Replace all existing deprecated API with the recommended alternative. Signed-off-by: Peter Bigot <[email protected]> Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 8e50e6b commit 091bddd

File tree

40 files changed

+338
-341
lines changed

40 files changed

+338
-341
lines changed

drivers/net/ppp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,9 @@ static int ppp_driver_init(const struct device *dev)
716716
ring_buf_init(&ppp->rx_ringbuf, sizeof(ppp->rx_buf), ppp->rx_buf);
717717
k_work_init(&ppp->cb_work, ppp_isr_cb_work);
718718

719-
k_work_q_start(&ppp->cb_workq, ppp_workq,
720-
K_KERNEL_STACK_SIZEOF(ppp_workq),
721-
K_PRIO_COOP(PPP_WORKQ_PRIORITY));
719+
k_work_queue_start(&ppp->cb_workq, ppp_workq,
720+
K_KERNEL_STACK_SIZEOF(ppp_workq),
721+
K_PRIO_COOP(PPP_WORKQ_PRIORITY), NULL);
722722
k_thread_name_set(&ppp->cb_workq.thread, "ppp_workq");
723723
#endif
724724

include/net/dsa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct dsa_context {
140140
struct dsa_api *dapi;
141141

142142
/** DSA related work (e.g. monitor if network interface is up) */
143-
struct k_delayed_work dsa_work;
143+
struct k_work_delayable dsa_work;
144144

145145
/** The switch_id, which equals to the reg property number from
146146
* DTS is used to distinct between many connected switches.

include/net/http_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ struct http_response {
155155
*/
156156
struct http_client_internal_data {
157157
/** Work for handling timeout */
158-
struct k_delayed_work work;
158+
struct k_work_delayable work;
159159

160160
/** HTTP parser context */
161161
struct http_parser parser;

include/net/lwm2m.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct lwm2m_ctx {
7777
/** Private CoAP and networking structures */
7878
struct coap_pending pendings[CONFIG_LWM2M_ENGINE_MAX_PENDING];
7979
struct coap_reply replies[CONFIG_LWM2M_ENGINE_MAX_REPLIES];
80-
struct k_delayed_work retransmit_work;
80+
struct k_work_delayable retransmit_work;
8181
struct sys_mutex send_lock;
8282

8383
/** A pointer to currently processed request, for internal LwM2M engine

include/net/ppp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ struct ppp_my_option_info;
223223
*/
224224
struct ppp_fsm {
225225
/** Timeout timer */
226-
struct k_delayed_work timer;
226+
struct k_work_delayable timer;
227227

228228
struct {
229229
/** Acknowledge Configuration Information */
@@ -382,7 +382,7 @@ struct ppp_context {
382382
atomic_t flags;
383383

384384
/** PPP startup worker. */
385-
struct k_delayed_work startup;
385+
struct k_work_delayable startup;
386386

387387
/** Carrier ON/OFF handler worker. This is used to create
388388
* network interface UP/DOWN event when PPP L2 driver

include/net/trickle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct net_trickle {
6161

6262
uint32_t Imax_abs; /**< Max interval size in ms (not doublings) */
6363

64-
struct k_delayed_work timer;
64+
struct k_work_delayable timer;
6565
net_trickle_cb_t cb; /**< Callback to be called when timer expires */
6666
void *user_data;
6767
};

samples/net/cloud/mqtt_azure/src/main.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ static int nfds;
3939

4040
static bool mqtt_connected;
4141

42-
static struct k_delayed_work pub_message;
42+
static struct k_work_delayable pub_message;
4343
#if defined(CONFIG_NET_DHCPV4)
44-
static struct k_delayed_work check_network_conn;
44+
static struct k_work_delayable check_network_conn;
4545

4646
/* Network Management events */
4747
#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
@@ -343,7 +343,7 @@ static void publish_timeout(struct k_work *work)
343343

344344
LOG_DBG("mqtt_publish OK");
345345
end:
346-
k_delayed_work_submit(&pub_message, K_SECONDS(timeout_for_publish()));
346+
k_work_reschedule(&pub_message, K_SECONDS(timeout_for_publish()));
347347
}
348348

349349
static int try_to_connect(struct mqtt_client *client)
@@ -374,8 +374,8 @@ static int try_to_connect(struct mqtt_client *client)
374374

375375
if (mqtt_connected) {
376376
subscribe(client);
377-
k_delayed_work_submit(&pub_message,
378-
K_SECONDS(timeout_for_publish()));
377+
k_work_reschedule(&pub_message,
378+
K_SECONDS(timeout_for_publish()));
379379
return 0;
380380
}
381381

@@ -471,7 +471,7 @@ static void check_network_connection(struct k_work *work)
471471
LOG_INF("waiting for DHCP to acquire addr");
472472

473473
end:
474-
k_delayed_work_submit(&check_network_conn, K_SECONDS(3));
474+
k_work_reschedule(&check_network_conn, K_SECONDS(3));
475475
}
476476
#endif
477477

@@ -481,7 +481,7 @@ static void abort_mqtt_connection(void)
481481
if (mqtt_connected) {
482482
mqtt_connected = false;
483483
mqtt_abort(&client_ctx);
484-
k_delayed_work_cancel(&pub_message);
484+
k_work_cancel_delayable(&pub_message);
485485
}
486486
}
487487

@@ -494,14 +494,14 @@ static void l4_event_handler(struct net_mgmt_event_callback *cb,
494494

495495
if (mgmt_event == NET_EVENT_L4_CONNECTED) {
496496
/* Wait for DHCP to be back in BOUND state */
497-
k_delayed_work_submit(&check_network_conn, K_SECONDS(3));
497+
k_work_reschedule(&check_network_conn, K_SECONDS(3));
498498

499499
return;
500500
}
501501

502502
if (mgmt_event == NET_EVENT_L4_DISCONNECTED) {
503503
abort_mqtt_connection();
504-
k_delayed_work_cancel(&check_network_conn);
504+
k_work_cancel_delayable(&check_network_conn);
505505

506506
return;
507507
}
@@ -519,10 +519,10 @@ void main(void)
519519
return;
520520
}
521521

522-
k_delayed_work_init(&pub_message, publish_timeout);
522+
k_work_init_delayable(&pub_message, publish_timeout);
523523

524524
#if defined(CONFIG_NET_DHCPV4)
525-
k_delayed_work_init(&check_network_conn, check_network_connection);
525+
k_work_init_delayable(&check_network_conn, check_network_connection);
526526

527527
net_mgmt_init_event_callback(&l4_mgmt_cb, l4_event_handler,
528528
L4_EVENT_MASK);

samples/net/dns_resolve/src/main.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ LOG_MODULE_REGISTER(net_dns_resolve_client_sample, LOG_LEVEL_DBG);
1919

2020
#if defined(CONFIG_MDNS_RESOLVER)
2121
#if defined(CONFIG_NET_IPV4)
22-
static struct k_delayed_work mdns_ipv4_timer;
22+
static struct k_work_delayable mdns_ipv4_timer;
2323
static void do_mdns_ipv4_lookup(struct k_work *work);
2424
#endif
2525
#if defined(CONFIG_NET_IPV6)
26-
static struct k_delayed_work mdns_ipv6_timer;
26+
static struct k_work_delayable mdns_ipv6_timer;
2727
static void do_mdns_ipv6_lookup(struct k_work *work);
2828
#endif
2929
#endif
@@ -130,7 +130,7 @@ void mdns_result_cb(enum dns_resolve_status status,
130130

131131
#if defined(CONFIG_NET_DHCPV4)
132132
static struct net_mgmt_event_callback mgmt4_cb;
133-
static struct k_delayed_work ipv4_timer;
133+
static struct k_work_delayable ipv4_timer;
134134

135135
static void do_ipv4_lookup(struct k_work *work)
136136
{
@@ -192,12 +192,12 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
192192
* management event thread stack is very small by default.
193193
* So run it from work queue instead.
194194
*/
195-
k_delayed_work_init(&ipv4_timer, do_ipv4_lookup);
196-
k_delayed_work_submit(&ipv4_timer, K_NO_WAIT);
195+
k_work_init_delayable(&ipv4_timer, do_ipv4_lookup);
196+
k_work_reschedule(&ipv4_timer, K_NO_WAIT);
197197

198198
#if defined(CONFIG_MDNS_RESOLVER)
199-
k_delayed_work_init(&mdns_ipv4_timer, do_mdns_ipv4_lookup);
200-
k_delayed_work_submit(&mdns_ipv4_timer, K_NO_WAIT);
199+
k_work_init_delayable(&mdns_ipv4_timer, do_mdns_ipv4_lookup);
200+
k_work_reschedule(&mdns_ipv4_timer, K_NO_WAIT);
201201
#endif
202202
}
203203

@@ -274,8 +274,8 @@ static void setup_ipv4(struct net_if *iface)
274274
do_ipv4_lookup();
275275

276276
#if defined(CONFIG_MDNS_RESOLVER) && defined(CONFIG_NET_IPV4)
277-
k_delayed_work_init(&mdns_ipv4_timer, do_mdns_ipv4_lookup);
278-
k_delayed_work_submit(&mdns_ipv4_timer, K_NO_WAIT);
277+
k_work_init_delayable(&mdns_ipv4_timer, do_mdns_ipv4_lookup);
278+
k_work_reschedule(&mdns_ipv4_timer, K_NO_WAIT);
279279
#endif
280280
}
281281

@@ -316,8 +316,8 @@ static void setup_ipv6(struct net_if *iface)
316316
do_ipv6_lookup();
317317

318318
#if defined(CONFIG_MDNS_RESOLVER) && defined(CONFIG_NET_IPV6)
319-
k_delayed_work_init(&mdns_ipv6_timer, do_mdns_ipv6_lookup);
320-
k_delayed_work_submit(&mdns_ipv6_timer, K_NO_WAIT);
319+
k_work_init_delayable(&mdns_ipv6_timer, do_mdns_ipv6_lookup);
320+
k_work_reschedule(&mdns_ipv6_timer, K_NO_WAIT);
321321
#endif
322322
}
323323

samples/net/gptp/src/gptp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(net_gptp_sample);
1818
#include "ethernet/gptp/gptp_data_set.h"
1919

2020
static int run_duration = CONFIG_NET_SAMPLE_RUN_DURATION;
21-
static struct k_delayed_work stop_sample;
21+
static struct k_work_delayable stop_sample;
2222
static struct k_sem quit_lock;
2323

2424
static void stop_handler(struct k_work *work)
@@ -82,8 +82,8 @@ void init_testing(void)
8282

8383
k_sem_init(&quit_lock, 0, K_SEM_MAX_LIMIT);
8484

85-
k_delayed_work_init(&stop_sample, stop_handler);
86-
k_delayed_work_submit(&stop_sample, K_SECONDS(run_duration));
85+
k_work_init_delayable(&stop_sample, stop_handler);
86+
k_work_reschedule(&stop_sample, K_SECONDS(run_duration));
8787

8888
k_sem_take(&quit_lock, K_FOREVER);
8989

samples/net/sockets/coap_server/src/coap-server.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ static struct coap_observer observers[NUM_OBSERVERS];
4949

5050
static struct coap_pending pendings[NUM_PENDINGS];
5151

52-
static struct k_delayed_work observer_work;
52+
static struct k_work_delayable observer_work;
5353

5454
static int obs_counter;
5555

5656
static struct coap_resource *resource_to_notify;
5757

58-
static struct k_delayed_work retransmit_work;
58+
static struct k_work_delayable retransmit_work;
5959

6060
#if defined(CONFIG_NET_IPV6)
6161
static bool join_coap_multicast_group(void)
@@ -966,7 +966,7 @@ static void retransmit_request(struct k_work *work)
966966
return;
967967
}
968968

969-
k_delayed_work_submit(&retransmit_work, K_MSEC(pending->timeout));
969+
k_work_reschedule(&retransmit_work, K_MSEC(pending->timeout));
970970
}
971971

972972
static void update_counter(struct k_work *work)
@@ -977,7 +977,7 @@ static void update_counter(struct k_work *work)
977977
coap_resource_notify(resource_to_notify);
978978
}
979979

980-
k_delayed_work_submit(&observer_work, K_SECONDS(5));
980+
k_work_reschedule(&observer_work, K_SECONDS(5));
981981
}
982982

983983
static int create_pending_request(struct coap_packet *response,
@@ -1004,7 +1004,7 @@ static int create_pending_request(struct coap_packet *response,
10041004
return 0;
10051005
}
10061006

1007-
k_delayed_work_submit(&retransmit_work, K_MSEC(pending->timeout));
1007+
k_work_reschedule(&retransmit_work, K_MSEC(pending->timeout));
10081008

10091009
return 0;
10101010
}
@@ -1081,7 +1081,7 @@ static int send_notification_packet(const struct sockaddr *addr,
10811081
}
10821082
}
10831083

1084-
k_delayed_work_submit(&observer_work, K_SECONDS(5));
1084+
k_work_reschedule(&observer_work, K_SECONDS(5));
10851085

10861086
r = send_coap_reply(&response, addr, addr_len);
10871087

@@ -1416,8 +1416,8 @@ void main(void)
14161416
goto quit;
14171417
}
14181418

1419-
k_delayed_work_init(&retransmit_work, retransmit_request);
1420-
k_delayed_work_init(&observer_work, update_counter);
1419+
k_work_init_delayable(&retransmit_work, retransmit_request);
1420+
k_work_init_delayable(&observer_work, update_counter);
14211421

14221422
while (1) {
14231423
r = process_client_request();

samples/net/sockets/echo_client/src/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ struct data {
3333
struct {
3434
int sock;
3535
/* Work controlling udp data sending */
36-
struct k_delayed_work recv;
37-
struct k_delayed_work transmit;
36+
struct k_work_delayable recv;
37+
struct k_work_delayable transmit;
3838
uint32_t expecting;
3939
uint32_t counter;
4040
uint32_t mtu;

samples/net/sockets/echo_client/src/udp.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int send_udp_data(struct data *data)
4040

4141
LOG_DBG("%s UDP: Sent %d bytes", data->proto, data->udp.expecting);
4242

43-
k_delayed_work_submit(&data->udp.recv, UDP_WAIT);
43+
k_work_reschedule(&data->udp.recv, UDP_WAIT);
4444

4545
return ret < 0 ? -EIO : 0;
4646
}
@@ -83,8 +83,8 @@ static int start_udp_proto(struct data *data, struct sockaddr *addr,
8383
{
8484
int ret;
8585

86-
k_delayed_work_init(&data->udp.recv, wait_reply);
87-
k_delayed_work_init(&data->udp.transmit, wait_transmit);
86+
k_work_init_delayable(&data->udp.recv, wait_reply);
87+
k_work_init_delayable(&data->udp.transmit, wait_transmit);
8888

8989
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
9090
data->udp.sock = socket(addr->sa_family, SOCK_DGRAM, IPPROTO_DTLS_1_2);
@@ -168,11 +168,11 @@ static int process_udp_proto(struct data *data)
168168
data->udp.counter);
169169
}
170170

171-
k_delayed_work_cancel(&data->udp.recv);
171+
k_work_cancel_delayable(&data->udp.recv);
172172

173173
/* Do not flood the link if we have also TCP configured */
174174
if (IS_ENABLED(CONFIG_NET_TCP)) {
175-
k_delayed_work_submit(&data->udp.transmit, UDP_SLEEP);
175+
k_work_reschedule(&data->udp.transmit, UDP_SLEEP);
176176
ret = 0;
177177
} else {
178178
ret = send_udp_data(data);
@@ -251,17 +251,17 @@ int process_udp(void)
251251
void stop_udp(void)
252252
{
253253
if (IS_ENABLED(CONFIG_NET_IPV6)) {
254-
k_delayed_work_cancel(&conf.ipv6.udp.recv);
255-
k_delayed_work_cancel(&conf.ipv6.udp.transmit);
254+
k_work_cancel_delayable(&conf.ipv6.udp.recv);
255+
k_work_cancel_delayable(&conf.ipv6.udp.transmit);
256256

257257
if (conf.ipv6.udp.sock >= 0) {
258258
(void)close(conf.ipv6.udp.sock);
259259
}
260260
}
261261

262262
if (IS_ENABLED(CONFIG_NET_IPV4)) {
263-
k_delayed_work_cancel(&conf.ipv4.udp.recv);
264-
k_delayed_work_cancel(&conf.ipv4.udp.transmit);
263+
k_work_cancel_delayable(&conf.ipv4.udp.recv);
264+
k_work_cancel_delayable(&conf.ipv4.udp.transmit);
265265

266266
if (conf.ipv4.udp.sock >= 0) {
267267
(void)close(conf.ipv4.udp.sock);

samples/net/sockets/echo_server/src/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ struct data {
4242
char recv_buffer[RECV_BUFFER_SIZE];
4343
uint32_t counter;
4444
atomic_t bytes_received;
45-
struct k_delayed_work stats_print;
45+
struct k_work_delayable stats_print;
4646
} udp;
4747

4848
struct {
4949
int sock;
5050
atomic_t bytes_received;
51-
struct k_delayed_work stats_print;
51+
struct k_work_delayable stats_print;
5252

5353
struct {
5454
int sock;

0 commit comments

Comments
 (0)