Module: xenomai-3
Branch: next
Commit: bd971c3a9624987d76662b5c67a4ab10bdc51cd8
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=bd971c3a9624987d76662b5c67a4ab10bdc51cd8

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Thu Oct  1 02:10:29 2015 +0200

rtnet: adapt to RTDM task management changes

Replace rtcfg timer tasks with timers, polled in the rtcfg rx task.
Remove useless calls to rtdm_task_join_nrt.

---

 kernel/drivers/net/addons/proxy.c                  |    7 +-
 .../drivers/net/stack/include/rtcfg/rtcfg_event.h  |   12 ++-
 .../drivers/net/stack/include/rtcfg/rtcfg_frame.h  |    6 +-
 .../drivers/net/stack/include/rtcfg/rtcfg_timer.h  |    5 +-
 kernel/drivers/net/stack/include/rtmac/tdma/tdma.h |    1 -
 .../drivers/net/stack/rtcfg/rtcfg_client_event.c   |   70 +++++++-------
 kernel/drivers/net/stack/rtcfg/rtcfg_conn_event.c  |   14 +--
 kernel/drivers/net/stack/rtcfg/rtcfg_event.c       |   48 +++++-----
 kernel/drivers/net/stack/rtcfg/rtcfg_frame.c       |   23 +++--
 kernel/drivers/net/stack/rtcfg/rtcfg_proc.c        |    2 +-
 kernel/drivers/net/stack/rtcfg/rtcfg_timer.c       |   96 ++++++++++++--------
 kernel/drivers/net/stack/rtmac/nomac/nomac_proto.c |    8 +-
 kernel/drivers/net/stack/rtmac/tdma/tdma_module.c  |    4 +-
 kernel/drivers/net/stack/rtmac/tdma/tdma_worker.c  |    2 +-
 kernel/drivers/net/stack/rtnet_rtpc.c              |   13 +--
 kernel/drivers/net/stack/stack_mgr.c               |    6 +-
 16 files changed, 187 insertions(+), 130 deletions(-)

diff --git a/kernel/drivers/net/addons/proxy.c 
b/kernel/drivers/net/addons/proxy.c
index 9b459eb..4887f77 100644
--- a/kernel/drivers/net/addons/proxy.c
+++ b/kernel/drivers/net/addons/proxy.c
@@ -103,7 +103,10 @@ static void rtnetproxy_tx_loop(void *arg)
     struct rtnet_device *rtdev;
     struct rtskb *rtskb;
 
-    while (rtdm_event_wait(&rtnetproxy_tx_event) == 0) {
+    while (!rtdm_task_should_stop()) {
+       if (rtdm_event_wait(&rtnetproxy_tx_event) < 0)
+           break;
+
        while ((rtskb = rtskb_dequeue(&tx_queue)) != NULL) {
            rtdev = rtskb->rtdev;
            rtdev_xmit_proxy(rtskb);
@@ -415,8 +418,8 @@ static void __exit rtnetproxy_cleanup_module(void)
     unregister_netdev(dev_rtnetproxy);
     free_netdev(dev_rtnetproxy);
 
+    rtdm_task_destroy(&rtnetproxy_tx_task);
     rtdm_event_destroy(&rtnetproxy_tx_event);
-    rtdm_task_join_nrt(&rtnetproxy_tx_task, 100);
 
     /* free the non-real-time signal */
     rtdm_nrtsig_destroy(&rtnetproxy_rx_signal);
diff --git a/kernel/drivers/net/stack/include/rtcfg/rtcfg_event.h 
b/kernel/drivers/net/stack/include/rtcfg/rtcfg_event.h
index 44c9bbb..a4b7955 100644
--- a/kernel/drivers/net/stack/include/rtcfg/rtcfg_event.h
+++ b/kernel/drivers/net/stack/include/rtcfg/rtcfg_event.h
@@ -34,9 +34,13 @@
 #include <rtnet_rtpc.h>
 
 
-#define FLAG_TIMER_STARTED          0x00010000
-#define FLAG_TIMER_SHUTDOWN         0x00020000
+#define FLAG_TIMER_STARTED          16
+#define FLAG_TIMER_SHUTDOWN         17
+#define FLAG_TIMER_PENDING          18
 
+#define _FLAG_TIMER_STARTED         (1 << FLAG_TIMER_STARTED)
+#define _FLAG_TIMER_SHUTDOWN        (1 << FLAG_TIMER_SHUTDOWN)
+#define _FLAG_TIMER_PENDING         (1 << FLAG_TIMER_PENDING)
 
 typedef enum {
     RTCFG_MAIN_OFF,
@@ -63,8 +67,8 @@ struct rtcfg_device {
     rtdm_mutex_t                    dev_mutex;
     struct list_head                event_calls;
     rtdm_lock_t                     event_calls_lock;
-    rtdm_task_t                     timer_task;
-    unsigned int                    flags;
+    rtdm_timer_t                    timer;
+    unsigned long                   flags;
     unsigned int                    burstrate;
 #ifdef CONFIG_XENO_OPT_VFILE
     struct xnvfile_directory        proc_entry;
diff --git a/kernel/drivers/net/stack/include/rtcfg/rtcfg_frame.h 
b/kernel/drivers/net/stack/include/rtcfg/rtcfg_frame.h
index ac9f78b..2a6a415 100644
--- a/kernel/drivers/net/stack/include/rtcfg/rtcfg_frame.h
+++ b/kernel/drivers/net/stack/include/rtcfg/rtcfg_frame.h
@@ -51,9 +51,11 @@
 #define RTCFG_ADDRSIZE_IP           4
 #define RTCFG_MAX_ADDRSIZE          RTCFG_ADDRSIZE_IP
 
-#define RTCFG_FLAG_STAGE_2_DATA     1
-#define RTCFG_FLAG_READY            2
+#define RTCFG_FLAG_STAGE_2_DATA 0
+#define RTCFG_FLAG_READY        1
 
+#define _RTCFG_FLAG_STAGE_2_DATA (1 << RTCFG_FLAG_STAGE_2_DATA)
+#define _RTCFG_FLAG_READY        (1 << RTCFG_FLAG_READY)
 
 struct rtcfg_frm_head {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
diff --git a/kernel/drivers/net/stack/include/rtcfg/rtcfg_timer.h 
b/kernel/drivers/net/stack/include/rtcfg/rtcfg_timer.h
index e9f6e27..2da6d50 100644
--- a/kernel/drivers/net/stack/include/rtcfg/rtcfg_timer.h
+++ b/kernel/drivers/net/stack/include/rtcfg/rtcfg_timer.h
@@ -25,7 +25,10 @@
 #ifndef __RTCFG_TIMER_H_
 #define __RTCFG_TIMER_H_
 
+void rtcfg_timer(rtdm_timer_t *t);
 
-void rtcfg_timer(void *arg);
+void rtcfg_timer_run(void);
+
+void rtcfg_thread_signal(void);
 
 #endif /* __RTCFG_TIMER_H_ */
diff --git a/kernel/drivers/net/stack/include/rtmac/tdma/tdma.h 
b/kernel/drivers/net/stack/include/rtmac/tdma/tdma.h
index c9a686e..f933991 100644
--- a/kernel/drivers/net/stack/include/rtmac/tdma/tdma.h
+++ b/kernel/drivers/net/stack/include/rtmac/tdma/tdma.h
@@ -35,7 +35,6 @@
 
 #define TDMA_MAGIC              0x3A0D4D0A
 
-#define TDMA_FLAG_SHUTDOWN      0
 #define TDMA_FLAG_CALIBRATED    1
 #define TDMA_FLAG_RECEIVED_SYNC 2
 #define TDMA_FLAG_MASTER        3   /* also set for backup masters */
diff --git a/kernel/drivers/net/stack/rtcfg/rtcfg_client_event.c 
b/kernel/drivers/net/stack/rtcfg/rtcfg_client_event.c
index 561fef2..b06da37 100644
--- a/kernel/drivers/net/stack/rtcfg/rtcfg_client_event.c
+++ b/kernel/drivers/net/stack/rtcfg/rtcfg_client_event.c
@@ -113,8 +113,10 @@ int rtcfg_main_state_client_1(int ifindex, RTCFG_EVENT 
event_id,
             rtcfg_queue_blocking_call(ifindex,
                 (struct rt_proc_call *)event_data);
 
-            rtcfg_dev->flags = cmd_event->args.announce.flags &
-                (RTCFG_FLAG_STAGE_2_DATA | RTCFG_FLAG_READY);
+           if (cmd_event->args.announce.flags & _RTCFG_FLAG_STAGE_2_DATA)
+               set_bit(RTCFG_FLAG_STAGE_2_DATA, &rtcfg_dev->flags);
+           if (cmd_event->args.announce.flags & _RTCFG_FLAG_READY)
+               set_bit(RTCFG_FLAG_READY, &rtcfg_dev->flags);
             if (cmd_event->args.announce.burstrate < rtcfg_dev->burstrate)
                 rtcfg_dev->burstrate = cmd_event->args.announce.burstrate;
 
@@ -324,8 +326,10 @@ int rtcfg_main_state_client_all_frames(int ifindex, 
RTCFG_EVENT event_id,
                     rtcfg_complete_cmd(ifindex, RTCFG_CMD_ANNOUNCE, 0);
 
                     rtcfg_next_main_state(ifindex,
-                        ((rtcfg_dev->flags & RTCFG_FLAG_READY) != 0) ?
-                        RTCFG_MAIN_CLIENT_READY : RTCFG_MAIN_CLIENT_2);
+                                       test_bit(RTCFG_FLAG_READY,
+                                               &rtcfg_dev->flags) ?
+                                       RTCFG_MAIN_CLIENT_READY
+                                       : RTCFG_MAIN_CLIENT_2);
                 }
 
                 rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
@@ -340,8 +344,10 @@ int rtcfg_main_state_client_all_frames(int ifindex, 
RTCFG_EVENT event_id,
                     rtcfg_complete_cmd(ifindex, RTCFG_CMD_ANNOUNCE, 0);
 
                     rtcfg_next_main_state(ifindex,
-                        ((rtcfg_dev->flags & RTCFG_FLAG_READY) != 0) ?
-                        RTCFG_MAIN_CLIENT_READY : RTCFG_MAIN_CLIENT_2);
+                                       test_bit(RTCFG_FLAG_READY,
+                                               &rtcfg_dev->flags) ?
+                                       RTCFG_MAIN_CLIENT_READY
+                                       : RTCFG_MAIN_CLIENT_2);
                 }
 
                 rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
@@ -393,10 +399,8 @@ int rtcfg_main_state_client_2(int ifindex, RTCFG_EVENT 
event_id,
 
             rtcfg_next_main_state(ifindex, RTCFG_MAIN_CLIENT_READY);
 
-            if ((rtcfg_dev->flags & RTCFG_FLAG_READY) == 0) {
-                rtcfg_dev->flags |= RTCFG_FLAG_READY;
+            if (!test_and_set_bit(RTCFG_FLAG_READY, &rtcfg_dev->flags))
                 rtcfg_send_ready(ifindex);
-            }
 
             rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
 
@@ -498,7 +502,7 @@ static int rtcfg_client_get_frag(int ifindex, struct 
rt_proc_call *call)
 {
     struct rtcfg_device *rtcfg_dev = &device[ifindex];
 
-    if ((rtcfg_dev->flags & RTCFG_FLAG_STAGE_2_DATA) == 0) {
+    if (test_bit(RTCFG_FLAG_STAGE_2_DATA, &rtcfg_dev->flags) == 0) {
         rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
         return -EINVAL;
     }
@@ -510,8 +514,9 @@ static int rtcfg_client_get_frag(int ifindex, struct 
rt_proc_call *call)
             rtpc_complete_call(call, 0);
 
             rtcfg_next_main_state(ifindex,
-                ((rtcfg_dev->flags & RTCFG_FLAG_READY) != 0) ?
-                RTCFG_MAIN_CLIENT_READY : RTCFG_MAIN_CLIENT_2);
+                               test_bit(RTCFG_FLAG_READY,
+                                       &rtcfg_dev->flags) ?
+                               RTCFG_MAIN_CLIENT_READY : RTCFG_MAIN_CLIENT_2);
         } else {
             rtcfg_next_main_state(ifindex, RTCFG_MAIN_CLIENT_ALL_FRAMES);
             rtcfg_queue_blocking_call(ifindex, call);
@@ -547,11 +552,8 @@ static void rtcfg_client_detach(int ifindex, struct 
rt_proc_call *call)
         rtpc_complete_call(call, -ENODEV);
     }
 
-    if (rtcfg_dev->flags & FLAG_TIMER_STARTED) {
-        /* It's safe to kill the task, it either waits for dev_mutex or the
-           next period. */
-        rtdm_task_destroy(&rtcfg_dev->timer_task);
-    }
+    if (test_and_clear_bit(FLAG_TIMER_STARTED, &rtcfg_dev->flags))
+        rtdm_timer_destroy(&rtcfg_dev->timer);
     rtcfg_reset_device(ifindex);
 
     rtcfg_next_main_state(cmd_event->internal.data.ifindex, RTCFG_MAIN_OFF);
@@ -726,7 +728,7 @@ static int rtcfg_add_to_station_list(struct rtcfg_device 
*rtcfg_dev,
         flags;
 
     rtcfg_dev->stations_found++;
-    if ((flags & RTCFG_FLAG_READY) != 0)
+    if ((flags & _RTCFG_FLAG_READY) != 0)
         rtcfg_dev->stations_ready++;
 
     return 0;
@@ -879,15 +881,21 @@ static void rtcfg_client_recv_stage_2_cfg(int ifindex, 
struct rtskb *rtskb)
     __rtskb_pull(rtskb, sizeof(struct rtcfg_frm_stage_2_cfg));
 
     if (stage_2_cfg->heartbeat_period) {
-        ret = rtdm_task_init(&rtcfg_dev->timer_task, "rtcfg-timer",
-                rtcfg_timer, (void *)(long)ifindex,
-                RTDM_TASK_LOWEST_PRIORITY,
-                (nanosecs_rel_t)ntohs(stage_2_cfg->heartbeat_period) *
-                    1000000);
+       ret = rtdm_timer_init(&rtcfg_dev->timer, rtcfg_timer, "rtcfg-timer");
+       if (ret == 0) {
+           ret = rtdm_timer_start(&rtcfg_dev->timer,
+                               XN_INFINITE,
+                               
(nanosecs_rel_t)ntohs(stage_2_cfg->heartbeat_period) *
+                               1000000,
+                               RTDM_TIMERMODE_RELATIVE);
+           if (ret < 0)
+               rtdm_timer_destroy(&rtcfg_dev->timer);
+       }
+
         if (ret < 0)
             /*ERRMSG*/rtdm_printk("RTcfg: unable to create timer task\n");
         else
-            rtcfg_dev->flags |= FLAG_TIMER_STARTED;
+           set_bit(FLAG_TIMER_STARTED, &rtcfg_dev->flags);
     }
 
     /* add server to station list */
@@ -903,7 +911,7 @@ static void rtcfg_client_recv_stage_2_cfg(int ifindex, 
struct rtskb *rtskb)
     rtcfg_dev->spec.clt.cfg_len = ntohl(stage_2_cfg->cfg_len);
     data_len = MIN(rtcfg_dev->spec.clt.cfg_len, rtskb->len);
 
-    if (((rtcfg_dev->flags & RTCFG_FLAG_STAGE_2_DATA) != 0) &&
+    if (test_bit(RTCFG_FLAG_STAGE_2_DATA, &rtcfg_dev->flags) &&
         (data_len > 0)) {
         rtcfg_client_queue_frag(ifindex, rtskb, data_len);
         rtskb = NULL;
@@ -915,8 +923,8 @@ static void rtcfg_client_recv_stage_2_cfg(int ifindex, 
struct rtskb *rtskb)
             rtcfg_complete_cmd(ifindex, RTCFG_CMD_ANNOUNCE, 0);
 
             rtcfg_next_main_state(ifindex,
-                ((rtcfg_dev->flags & RTCFG_FLAG_READY) != 0) ?
-                RTCFG_MAIN_CLIENT_READY : RTCFG_MAIN_CLIENT_2);
+                               test_bit(RTCFG_FLAG_READY, &rtcfg_dev->flags) ?
+                               RTCFG_MAIN_CLIENT_READY : RTCFG_MAIN_CLIENT_2);
         } else
             rtcfg_next_main_state(ifindex, RTCFG_MAIN_CLIENT_ALL_FRAMES);
 
@@ -951,7 +959,7 @@ static void rtcfg_client_recv_stage_2_frag(int ifindex, 
struct rtskb *rtskb)
     data_len = MIN(rtcfg_dev->spec.clt.cfg_len - rtcfg_dev->spec.clt.cfg_offs,
                    rtskb->len);
 
-    if ((rtcfg_dev->flags & RTCFG_FLAG_STAGE_2_DATA) == 0) {
+    if (test_bit(RTCFG_FLAG_STAGE_2_DATA, &rtcfg_dev->flags) == 0) {
         RTCFG_DEBUG(1, "RTcfg: unexpected stage 2 fragment, we did not "
                     "request any data!\n");
 
@@ -998,9 +1006,9 @@ static int rtcfg_client_recv_ready(int ifindex, struct 
rtskb *rtskb)
         if (memcmp(rtcfg_dev->spec.clt.station_addr_list[i].mac_addr,
                    rtskb->mac.ethernet->h_source, ETH_ALEN) == 0) {
             if ((rtcfg_dev->spec.clt.station_addr_list[i].flags &
-                 RTCFG_FLAG_READY) == 0) {
+                 _RTCFG_FLAG_READY) == 0) {
                 rtcfg_dev->spec.clt.station_addr_list[i].flags |=
-                    RTCFG_FLAG_READY;
+                    _RTCFG_FLAG_READY;
                 rtcfg_dev->stations_ready++;
             }
             break;
@@ -1071,7 +1079,7 @@ static void rtcfg_client_recv_dead_station(int ifindex, 
struct rtskb *rtskb)
         if (memcmp(rtcfg_dev->spec.clt.station_addr_list[i].mac_addr,
                    dead_station_frm->physical_addr, ETH_ALEN) == 0) {
             if ((rtcfg_dev->spec.clt.station_addr_list[i].flags &
-                 RTCFG_FLAG_READY) != 0)
+                 _RTCFG_FLAG_READY) != 0)
                 rtcfg_dev->stations_ready--;
 
             rtcfg_dev->stations_found--;
diff --git a/kernel/drivers/net/stack/rtcfg/rtcfg_conn_event.c 
b/kernel/drivers/net/stack/rtcfg/rtcfg_conn_event.c
index ad5181f..1dc5810 100644
--- a/kernel/drivers/net/stack/rtcfg/rtcfg_conn_event.c
+++ b/kernel/drivers/net/stack/rtcfg/rtcfg_conn_event.c
@@ -151,14 +151,14 @@ static int rtcfg_conn_state_stage_1(struct 
rtcfg_connection *conn,
             ack_cfg = (struct rtcfg_frm_ack_cfg *)rtskb->data;
             conn->cfg_offs = ntohl(ack_cfg->ack_len);
 
-            if ((conn->flags & RTCFG_FLAG_STAGE_2_DATA) != 0) {
+            if ((conn->flags & _RTCFG_FLAG_STAGE_2_DATA) != 0) {
                 if (conn->cfg_offs >= conn->stage2_file->size) {
                     rtcfg_dev->spec.srv.clients_configured++;
                     if (rtcfg_dev->spec.srv.clients_configured ==
                         rtcfg_dev->other_stations)
                         rtcfg_complete_cmd(conn->ifindex, RTCFG_CMD_WAIT, 0);
                     rtcfg_next_conn_state(conn,
-                        ((conn->flags & RTCFG_FLAG_READY) != 0) ?
+                        ((conn->flags & _RTCFG_FLAG_READY) != 0) ?
                         RTCFG_CONN_READY : RTCFG_CONN_STAGE_2);
                 } else {
                     packets = conn->burstrate;
@@ -174,7 +174,7 @@ static int rtcfg_conn_state_stage_1(struct rtcfg_connection 
*conn,
                     rtcfg_dev->other_stations)
                     rtcfg_complete_cmd(conn->ifindex, RTCFG_CMD_WAIT, 0);
                 rtcfg_next_conn_state(conn,
-                    ((conn->flags & RTCFG_FLAG_READY) != 0) ?
+                    ((conn->flags & _RTCFG_FLAG_READY) != 0) ?
                     RTCFG_CONN_READY : RTCFG_CONN_STAGE_2);
             }
 
@@ -207,7 +207,7 @@ static int rtcfg_conn_state_stage_2(struct rtcfg_connection 
*conn,
 
             rtcfg_next_conn_state(conn, RTCFG_CONN_READY);
 
-            conn->flags |= RTCFG_FLAG_READY;
+            conn->flags |= _RTCFG_FLAG_READY;
             rtcfg_dev->stations_ready++;
 
             if (rtcfg_dev->stations_ready == rtcfg_dev->other_stations)
@@ -295,10 +295,10 @@ static void rtcfg_conn_recv_announce_new(struct 
rtcfg_connection *conn,
     rtcfg_next_conn_state(conn, RTCFG_CONN_STAGE_1);
 
     rtcfg_dev->stations_found++;
-    if ((conn->flags & RTCFG_FLAG_READY) != 0)
+    if ((conn->flags & _RTCFG_FLAG_READY) != 0)
         rtcfg_dev->stations_ready++;
 
-    if (((conn->flags & RTCFG_FLAG_STAGE_2_DATA) != 0) &&
+    if (((conn->flags & _RTCFG_FLAG_STAGE_2_DATA) != 0) &&
         (conn->stage2_file != NULL)) {
         packets = conn->burstrate - 1;
 
@@ -311,7 +311,7 @@ static void rtcfg_conn_recv_announce_new(struct 
rtcfg_connection *conn,
         }
     } else {
         rtcfg_send_stage_2(conn, 0);
-        conn->flags &= ~RTCFG_FLAG_STAGE_2_DATA;
+        conn->flags &= ~_RTCFG_FLAG_STAGE_2_DATA;
     }
 }
 
diff --git a/kernel/drivers/net/stack/rtcfg/rtcfg_event.c 
b/kernel/drivers/net/stack/rtcfg/rtcfg_event.c
index f60fc52..3569459 100644
--- a/kernel/drivers/net/stack/rtcfg/rtcfg_event.c
+++ b/kernel/drivers/net/stack/rtcfg/rtcfg_event.c
@@ -148,17 +148,26 @@ static int rtcfg_main_state_off(int ifindex, RTCFG_EVENT 
event_id,
        case RTCFG_CMD_SERVER:
            INIT_LIST_HEAD(&rtcfg_dev->spec.srv.conn_list);
 
-           ret = rtdm_task_init(&rtcfg_dev->timer_task, "rtcfg-timer",
-                   rtcfg_timer, (void *)(long)ifindex,
-                    RTDM_TASK_LOWEST_PRIORITY,
-                   ((nanosecs_rel_t)cmd_event->args.server.period)*1000000);
+           ret = rtdm_timer_init(&rtcfg_dev->timer, rtcfg_timer, 
"rtcfg-timer");
+           if (ret == 0) {
+                   ret = rtdm_timer_start(&rtcfg_dev->timer,
+                                           XN_INFINITE,
+                                           (nanosecs_rel_t)
+                                           cmd_event->args.server.period
+                                           * 1000000,
+                                           RTDM_TIMERMODE_RELATIVE);
+                   if (ret < 0)
+                           rtdm_timer_destroy(&rtcfg_dev->timer);
+           }
            if (ret < 0) {
                rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
                return ret;
            }
 
-           rtcfg_dev->flags = FLAG_TIMER_STARTED |
-               (cmd_event->args.server.flags & RTCFG_FLAG_READY);
+           if (cmd_event->args.server.flags & _RTCFG_FLAG_READY)
+                   set_bit(RTCFG_FLAG_READY, &rtcfg_dev->flags);
+           set_bit(FLAG_TIMER_STARTED, &rtcfg_dev->flags);
+
            rtcfg_dev->burstrate = cmd_event->args.server.burstrate;
 
            rtcfg_dev->spec.srv.heartbeat = cmd_event->args.server.heartbeat;
@@ -251,10 +260,8 @@ static int rtcfg_main_state_server_running(int ifindex, 
RTCFG_EVENT event_id,
            else
                rtcfg_queue_blocking_call(ifindex, call);
 
-           if ((rtcfg_dev->flags & RTCFG_FLAG_READY) == 0) {
-               rtcfg_dev->flags |= RTCFG_FLAG_READY;
+           if (!test_and_set_bit(RTCFG_FLAG_READY, &rtcfg_dev->flags))
                rtcfg_send_ready(ifindex);
-           }
 
            rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
 
@@ -427,7 +434,7 @@ static int rtcfg_server_del(struct rtcfg_cmd *cmd_event)
                rtcfg_dev->stations_found--;
                if (conn->state >= RTCFG_CONN_STAGE_2)
                    rtcfg_dev->spec.srv.clients_configured--;
-               if (conn->flags & RTCFG_FLAG_READY)
+               if (conn->flags & _RTCFG_FLAG_READY)
                    rtcfg_dev->stations_ready--;
            }
 
@@ -467,7 +474,7 @@ static int rtcfg_server_detach(int ifindex, struct 
rtcfg_cmd *cmd_event)
            rtcfg_dev->stations_found--;
            if (conn->state >= RTCFG_CONN_STAGE_2)
                rtcfg_dev->spec.srv.clients_configured--;
-           if (conn->flags & RTCFG_FLAG_READY)
+           if (conn->flags & _RTCFG_FLAG_READY)
                rtcfg_dev->stations_ready--;
        }
 
@@ -482,11 +489,8 @@ static int rtcfg_server_detach(int ifindex, struct 
rtcfg_cmd *cmd_event)
        return -EAGAIN;
     }
 
-    if (rtcfg_dev->flags & FLAG_TIMER_STARTED) {
-       /* It's safe to kill the task, it either waits for dev_mutex or the
-          next period. */
-       rtdm_task_destroy(&rtcfg_dev->timer_task);
-    }
+    if (test_and_clear_bit(FLAG_TIMER_STARTED, &rtcfg_dev->flags))
+       rtdm_timer_destroy(&rtcfg_dev->timer);
     rtcfg_reset_device(ifindex);
 
     rtcfg_next_main_state(ifindex, RTCFG_MAIN_OFF);
@@ -737,11 +741,13 @@ void rtcfg_cleanup_state_machines(void)
     for (i = 0; i < MAX_RT_DEVICES; i++) {
        rtcfg_dev = &device[i];
 
-       if (rtcfg_dev->flags & FLAG_TIMER_STARTED) {
-           rtcfg_dev->flags |= FLAG_TIMER_SHUTDOWN;
-           rtdm_task_unblock(&rtcfg_dev->timer_task);
-           rtdm_task_join_nrt(&rtcfg_dev->timer_task, 100);
-       }
+       if (test_and_clear_bit(FLAG_TIMER_STARTED, &rtcfg_dev->flags))
+               rtdm_timer_destroy(&rtcfg_dev->timer);
+
+       /*
+        * No need to synchronize with rtcfg_timer here: the task running
+        * rtcfg_timer is already dead.
+        */
 
        rtdm_mutex_destroy(&rtcfg_dev->dev_mutex);
 
diff --git a/kernel/drivers/net/stack/rtcfg/rtcfg_frame.c 
b/kernel/drivers/net/stack/rtcfg/rtcfg_frame.c
index 4725a01..f80a579 100644
--- a/kernel/drivers/net/stack/rtcfg/rtcfg_frame.c
+++ b/kernel/drivers/net/stack/rtcfg/rtcfg_frame.c
@@ -29,6 +29,7 @@
 #include <rtcfg/rtcfg.h>
 #include <rtcfg/rtcfg_conn_event.h>
 #include <rtcfg/rtcfg_frame.h>
+#include <rtcfg/rtcfg_timer.h>
 
 
 static unsigned int num_rtskbs = 32;
@@ -41,13 +42,17 @@ static rtdm_event_t         rx_event;
 static struct rtskb_queue   rx_queue;
 
 
+void rtcfg_thread_signal(void)
+{
+    rtdm_event_signal(&rx_event);
+}
 
 static int rtcfg_rx_handler(struct rtskb *rtskb, struct rtpacket_type *pt)
 {
     if (rtskb_acquire(rtskb, &rtcfg_pool) == 0) {
        rtskb_queue_tail(&rx_queue, rtskb);
-       rtdm_event_signal(&rx_event);
-    } else
+       rtcfg_thread_signal();
+   } else
        kfree_rtskb(rtskb);
 
     return 0;
@@ -62,7 +67,10 @@ static void rtcfg_rx_task(void *arg)
     struct rtnet_device   *rtdev;
 
 
-    while (rtdm_event_wait(&rx_event) == 0)
+    while (!rtdm_task_should_stop()) {
+       if (rtdm_event_wait(&rx_event) < 0)
+           break;
+
        while ((rtskb = rtskb_dequeue(&rx_queue))) {
            rtdev = rtskb->rtdev;
 
@@ -85,6 +93,9 @@ static void rtcfg_rx_task(void *arg)
                                    rtskb) < 0)
                kfree_rtskb(rtskb);
        }
+
+       rtcfg_timer_run();
+    }
 }
 
 
@@ -390,7 +401,7 @@ int rtcfg_send_announce_reply(int ifindex, u8 
*dest_mac_addr)
     }
 #endif /* CONFIG_XENO_DRIVERS_NET_RTIPV4 */
 
-    announce_rpl->flags     = rtcfg_dev->flags & RTCFG_FLAG_READY;
+    announce_rpl->flags     = rtcfg_dev->flags & _RTCFG_FLAG_READY;
     announce_rpl->burstrate = 0; /* padding field */
 
     return rtcfg_send_frame(rtskb, rtdev, dest_mac_addr);
@@ -556,8 +567,8 @@ int __init rtcfg_init_frames(void)
     return 0;
 
   error2:
+    rtdm_task_destroy(&rx_task);
     rtdm_event_destroy(&rx_event);
-    rtdm_task_join_nrt(&rx_task, 100);
 
   error1:
     rtskb_pool_release(&rtcfg_pool);
@@ -574,8 +585,8 @@ void rtcfg_cleanup_frames(void)
 
     rtdev_remove_pack(&rtcfg_packet_type);
 
+    rtdm_task_destroy(&rx_task);
     rtdm_event_destroy(&rx_event);
-    rtdm_task_join_nrt(&rx_task, 100);
 
     while ((rtskb = rtskb_dequeue(&rx_queue)) != NULL) {
        kfree_rtskb(rtskb);
diff --git a/kernel/drivers/net/stack/rtcfg/rtcfg_proc.c 
b/kernel/drivers/net/stack/rtcfg/rtcfg_proc.c
index a7a6b23..faef27c 100644
--- a/kernel/drivers/net/stack/rtcfg/rtcfg_proc.c
+++ b/kernel/drivers/net/stack/rtcfg/rtcfg_proc.c
@@ -59,7 +59,7 @@ int rtnet_rtcfg_dev_state_show(struct 
xnvfile_regular_iterator *it, void *data)
        };
 
        xnvfile_printf(it, "state:\t\t\t%d (%s)\n"
-                               "flags:\t\t\t%08X\n"
+                               "flags:\t\t\t%08lX\n"
                                "other stations:\t\t%d\n"
                                "stations found:\t\t%d\n"
                                "stations ready:\t\t%d\n",
diff --git a/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c 
b/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c
index 5b9ab5d..0fd17f1 100644
--- a/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c
+++ b/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c
@@ -30,9 +30,18 @@
 #include <rtcfg/rtcfg_conn_event.h>
 #include <rtcfg/rtcfg_event.h>
 #include <rtcfg/rtcfg_frame.h>
+#include <rtcfg/rtcfg_timer.h>
 
+void rtcfg_timer(rtdm_timer_t *t)
+{
+    struct rtcfg_device *rtcfg_dev =
+       container_of(t, struct rtcfg_device, timer);
+
+    set_bit(FLAG_TIMER_PENDING, &rtcfg_dev->flags);
+    rtcfg_thread_signal();
+}
 
-void rtcfg_timer(int ifindex)
+void rtcfg_timer_run_one(int ifindex)
 {
     struct rtcfg_device     *rtcfg_dev = &device[ifindex];
     struct list_head        *entry;
@@ -40,49 +49,56 @@ void rtcfg_timer(int ifindex)
     int                     last_stage_1 = -1;
     int                     burst_credit;
     int                     index;
-    int                     ret;
+    int                     ret, shutdown;
 
+    shutdown = test_and_clear_bit(FLAG_TIMER_SHUTDOWN, &rtcfg_dev->flags);
 
-    while (!(rtcfg_dev->flags & FLAG_TIMER_SHUTDOWN)) {
-        rtdm_mutex_lock(&rtcfg_dev->dev_mutex);
+    if (!test_and_clear_bit(FLAG_TIMER_PENDING, &rtcfg_dev->flags)
+       || shutdown)
+       return;
 
-        if (rtcfg_dev->state == RTCFG_MAIN_SERVER_RUNNING) {
-            index = 0;
-            burst_credit = rtcfg_dev->burstrate;
+    rtdm_mutex_lock(&rtcfg_dev->dev_mutex);
 
-            list_for_each(entry, &rtcfg_dev->spec.srv.conn_list) {
-                conn = list_entry(entry, struct rtcfg_connection, entry);
+    if (rtcfg_dev->state == RTCFG_MAIN_SERVER_RUNNING) {
+       index = 0;
+       burst_credit = rtcfg_dev->burstrate;
 
-                if ((conn->state == RTCFG_CONN_SEARCHING) ||
-                    (conn->state == RTCFG_CONN_DEAD)){
-                    if ((burst_credit > 0) && (index > last_stage_1)) {
-                        if ((ret = rtcfg_send_stage_1(conn)) < 0) {
-                            RTCFG_DEBUG(2, "RTcfg: error %d while sending "
+       list_for_each(entry, &rtcfg_dev->spec.srv.conn_list) {
+           conn = list_entry(entry, struct rtcfg_connection, entry);
+
+           if ((conn->state == RTCFG_CONN_SEARCHING) ||
+               (conn->state == RTCFG_CONN_DEAD)){
+               if ((burst_credit > 0) && (index > last_stage_1)) {
+                   if ((ret = rtcfg_send_stage_1(conn)) < 0) {
+                       RTCFG_DEBUG(2, "RTcfg: error %d while sending "
                                         "stage 1 frame\n", ret);
-                        }
-                        burst_credit--;
-                        last_stage_1 = index;
-                    }
-                } else {
-                    /* skip connection in history */
-                    if (last_stage_1 == (index-1))
-                        last_stage_1 = index;
-
-                    rtcfg_do_conn_event(conn, RTCFG_TIMER, NULL);
-                }
-                index++;
-            }
-
-            /* handle pointer overrun of the last stage 1 transmission */
-            if (last_stage_1 == (index-1))
-                last_stage_1 = -1;
-        } else if (rtcfg_dev->state == RTCFG_MAIN_CLIENT_READY)
-            rtcfg_send_heartbeat(ifindex);
-
-        rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
-
-        rtdm_task_wait_period(NULL);
-    }
-
-    rtcfg_dev->flags &= ~FLAG_TIMER_STARTED;
+                   }
+                   burst_credit--;
+                   last_stage_1 = index;
+               }
+           } else {
+               /* skip connection in history */
+               if (last_stage_1 == (index-1))
+                   last_stage_1 = index;
+
+               rtcfg_do_conn_event(conn, RTCFG_TIMER, NULL);
+           }
+           index++;
+       }
+
+       /* handle pointer overrun of the last stage 1 transmission */
+       if (last_stage_1 == (index-1))
+           last_stage_1 = -1;
+    } else if (rtcfg_dev->state == RTCFG_MAIN_CLIENT_READY)
+       rtcfg_send_heartbeat(ifindex);
+
+    rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
+}
+
+void rtcfg_timer_run(void)
+{
+    int ifindex;
+
+    for (ifindex = 0; ifindex < MAX_RT_DEVICES; ifindex++)
+       rtcfg_timer_run_one(ifindex);
 }
diff --git a/kernel/drivers/net/stack/rtmac/nomac/nomac_proto.c 
b/kernel/drivers/net/stack/rtmac/nomac/nomac_proto.c
index dfb6ef3..df916fa 100644
--- a/kernel/drivers/net/stack/rtmac/nomac/nomac_proto.c
+++ b/kernel/drivers/net/stack/rtmac/nomac/nomac_proto.c
@@ -89,7 +89,10 @@ void nrt_xmit_task(void *arg)
     struct rtnet_device *rtdev;
 
 
-    while (rtdm_event_wait(&wakeup_sem) == 0)
+    while (!rtdm_task_should_stop()) {
+       if (rtdm_event_wait(&wakeup_sem) < 0)
+           break;
+
         while ((rtskb = rtskb_dequeue(&nrt_rtskb_queue))) {
             rtdev = rtskb->rtdev;
 
@@ -98,6 +101,7 @@ void nrt_xmit_task(void *arg)
             rtmac_xmit(rtskb);
             rtdm_mutex_unlock(&rtdev->xmit_mutex);
         }
+    }
 }
 
 
@@ -134,6 +138,6 @@ int __init nomac_proto_init(void)
 
 void nomac_proto_cleanup(void)
 {
+    rtdm_task_destroy(&wrapper_task);
     rtdm_event_destroy(&wakeup_sem);
-    rtdm_task_join_nrt(&wrapper_task, 100);
 }
diff --git a/kernel/drivers/net/stack/rtmac/tdma/tdma_module.c 
b/kernel/drivers/net/stack/rtmac/tdma/tdma_module.c
index ee61500..e367d21 100644
--- a/kernel/drivers/net/stack/rtmac/tdma/tdma_module.c
+++ b/kernel/drivers/net/stack/rtmac/tdma/tdma_module.c
@@ -227,15 +227,13 @@ int tdma_detach(struct rtnet_device *rtdev, void *priv)
     struct tdma_job     *job, *tmp;
 
 
-    set_bit(TDMA_FLAG_SHUTDOWN, &tdma->flags);
-
     rtdm_event_destroy(&tdma->sync_event);
     rtdm_event_destroy(&tdma->xmit_event);
     rtdm_event_destroy(&tdma->worker_wakeup);
 
     tdma_dev_release(tdma);
 
-    rtdm_task_join_nrt(&tdma->worker_task, 100);
+    rtdm_task_destroy(&tdma->worker_task);
 
     list_for_each_entry_safe(job, tmp, &tdma->first_job->entry, entry) {
        if (job->id >= 0)
diff --git a/kernel/drivers/net/stack/rtmac/tdma/tdma_worker.c 
b/kernel/drivers/net/stack/rtmac/tdma/tdma_worker.c
index aa1fcd5..ad29d5d 100644
--- a/kernel/drivers/net/stack/rtmac/tdma/tdma_worker.c
+++ b/kernel/drivers/net/stack/rtmac/tdma/tdma_worker.c
@@ -184,7 +184,7 @@ void tdma_worker(void *arg)
 
     job = tdma->first_job;
 
-    while (!test_bit(TDMA_FLAG_SHUTDOWN, &tdma->flags)) {
+    while (!rtdm_task_should_stop()) {
         job->ref_count++;
         switch (job->id) {
             case WAIT_ON_SYNC:
diff --git a/kernel/drivers/net/stack/rtnet_rtpc.c 
b/kernel/drivers/net/stack/rtnet_rtpc.c
index 1e7e5e1..54a8137 100644
--- a/kernel/drivers/net/stack/rtnet_rtpc.c
+++ b/kernel/drivers/net/stack/rtnet_rtpc.c
@@ -92,11 +92,8 @@ int rtnet_rtpc_dispatch_call(rtpc_proc proc, unsigned int 
timeout,
 
 
     call = kmalloc(sizeof(struct rt_proc_call) + priv_data_size, GFP_KERNEL);
-    if (call == NULL) {
-       if (call->cleanup_handler != NULL)
-           call->cleanup_handler(priv_data);
+    if (call == NULL)
        return -ENOMEM;
-    }
 
     memcpy(call->priv_data, priv_data, priv_data_size);
 
@@ -194,12 +191,16 @@ static void rtpc_dispatch_handler(void *arg)
     int                 ret;
 
 
-    while (rtdm_event_wait(&dispatch_event) == 0)
+    while (!rtdm_task_should_stop()) {
+       if (rtdm_event_wait(&dispatch_event) < 0)
+           break;
+
        while ((call = rtpc_dequeue_pending_call())) {
            ret = call->proc(call);
            if (ret != -CALL_PENDING)
                rtpc_complete_call(call, ret);
        }
+    }
 }
 
 
@@ -271,8 +272,8 @@ int __init rtpc_init(void)
 
 void rtpc_cleanup(void)
 {
+    rtdm_task_destroy(&dispatch_task);
     rtdm_event_destroy(&dispatch_event);
-    rtdm_task_join_nrt(&dispatch_task, 100);
     rtdm_nrtsig_destroy(&rtpc_nrt_signal);
 }
 
diff --git a/kernel/drivers/net/stack/stack_mgr.c 
b/kernel/drivers/net/stack/stack_mgr.c
index 9804ec7..b71e261 100644
--- a/kernel/drivers/net/stack/stack_mgr.c
+++ b/kernel/drivers/net/stack/stack_mgr.c
@@ -200,8 +200,10 @@ static void rt_stack_mgr_task(void *arg)
     rtdm_event_t            *mgr_event = &((struct rtnet_mgr *)arg)->event;
     struct rtskb            *rtskb;
 
+    while (!rtdm_task_should_stop()) {
+       if (rtdm_event_wait(mgr_event) < 0)
+           break;
 
-    while (rtdm_event_wait(mgr_event) == 0) {
        /* we are the only reader => no locking required */
        while ((rtskb = __rtskb_fifo_remove(&rx.fifo)))
            rt_stack_deliver(rtskb);
@@ -259,6 +261,6 @@ int rt_stack_mgr_init (struct rtnet_mgr *mgr)
  */
 void rt_stack_mgr_delete (struct rtnet_mgr *mgr)
 {
+    rtdm_task_destroy(&mgr->task);
     rtdm_event_destroy(&mgr->event);
-    rtdm_task_join_nrt(&mgr->task, 100);
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to