Changeset 78192cc7 in mainline for uspace/srv/net/tcp


Ignore:
Timestamp:
2014-07-13T14:06:23Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
af2a76c, f303f2cf
Parents:
c1b979a
Message:

Fibril timer locking improvements.

Location:
uspace/srv/net/tcp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/conn.c

    rc1b979a r78192cc7  
    7878                goto error;
    7979
    80         conn->tw_timer = fibril_timer_create();
     80        fibril_mutex_initialize(&conn->lock);
     81
     82        conn->tw_timer = fibril_timer_create(&conn->lock);
    8183        if (conn->tw_timer == NULL)
    8284                goto error;
    83 
    84         fibril_mutex_initialize(&conn->lock);
    8585
    8686        /* One for the user, one for not being in closed state */
     
    200200        if (atomic_predec(&conn->refcnt) == 0)
    201201                tcp_conn_free(conn);
     202}
     203
     204/** Lock connection.
     205 *
     206 * Must be called before any other connection-manipulating function,
     207 * except tcp_conn_{add|del}ref(). Locks the connection including
     208 * its timers. Must not be called inside any of the connection
     209 * timer handlers.
     210 *
     211 * @param conn          Connection
     212 */
     213void tcp_conn_lock(tcp_conn_t *conn)
     214{
     215        fibril_mutex_lock(&conn->lock);
     216}
     217
     218/** Unlock connection.
     219 *
     220 * @param conn          Connection
     221 */
     222void tcp_conn_unlock(tcp_conn_t *conn)
     223{
     224        fibril_mutex_unlock(&conn->lock);
    202225}
    203226
     
    11831206        log_msg(LOG_DEFAULT, LVL_DEBUG, "tw_timeout_func(%p)", conn);
    11841207
    1185         fibril_mutex_lock(&conn->lock);
     1208        tcp_conn_lock(conn);
    11861209
    11871210        if (conn->cstate == st_closed) {
    11881211                log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection already closed.");
    1189                 fibril_mutex_unlock(&conn->lock);
     1212                tcp_conn_unlock(conn);
    11901213                tcp_conn_delref(conn);
    11911214                return;
     
    11961219        tcp_conn_state_set(conn, st_closed);
    11971220
    1198         fibril_mutex_unlock(&conn->lock);
     1221        tcp_conn_unlock(conn);
    11991222        tcp_conn_delref(conn);
     1223
     1224        log_msg(LOG_DEFAULT, LVL_DEBUG, "tw_timeout_func(%p) end", conn);
    12001225}
    12011226
     
    12061231void tcp_conn_tw_timer_set(tcp_conn_t *conn)
    12071232{
     1233        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_set() begin");
    12081234        tcp_conn_addref(conn);
    1209         fibril_timer_set(conn->tw_timer, TIME_WAIT_TIMEOUT, tw_timeout_func,
    1210             (void *)conn);
     1235        fibril_timer_set_locked(conn->tw_timer, TIME_WAIT_TIMEOUT,
     1236            tw_timeout_func, (void *)conn);
     1237        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_set() end");
    12111238}
    12121239
     
    12171244void tcp_conn_tw_timer_clear(tcp_conn_t *conn)
    12181245{
    1219         if (fibril_timer_clear(conn->tw_timer) == fts_active)
     1246        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_clear() begin");
     1247        if (fibril_timer_clear_locked(conn->tw_timer) == fts_active)
    12201248                tcp_conn_delref(conn);
     1249        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_clear() end");
    12211250}
    12221251
  • uspace/srv/net/tcp/conn.h

    rc1b979a r78192cc7  
    5050extern void tcp_conn_addref(tcp_conn_t *);
    5151extern void tcp_conn_delref(tcp_conn_t *);
     52extern void tcp_conn_lock(tcp_conn_t *);
     53extern void tcp_conn_unlock(tcp_conn_t *);
    5254extern bool tcp_conn_got_syn(tcp_conn_t *);
    5355extern void tcp_conn_segment_arrived(tcp_conn_t *, tcp_segment_t *);
  • uspace/srv/net/tcp/tqueue.c

    rc1b979a r78192cc7  
    5959static void tcp_tqueue_timer_clear(tcp_conn_t *conn);
    6060
     61#include <stdio.h>
    6162int tcp_tqueue_init(tcp_tqueue_t *tqueue, tcp_conn_t *conn)
    6263{
     64        printf("tcp_tqueue_init\n");
    6365        tqueue->conn = conn;
    64         tqueue->timer = fibril_timer_create();
     66        tqueue->timer = fibril_timer_create(&conn->lock);
    6567        if (tqueue->timer == NULL)
    6668                return ENOMEM;
     
    7880void tcp_tqueue_fini(tcp_tqueue_t *tqueue)
    7981{
     82        printf("tcp_tqueue_fini\n");
    8083        if (tqueue->timer != NULL) {
    8184                fibril_timer_destroy(tqueue->timer);
     
    319322        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: retransmit_timeout_func(%p)", conn->name, conn);
    320323
    321         fibril_mutex_lock(&conn->lock);
     324        tcp_conn_lock(conn);
    322325
    323326        if (conn->cstate == st_closed) {
    324327                log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection already closed.");
    325                 fibril_mutex_unlock(&conn->lock);
     328                tcp_conn_unlock(conn);
    326329                tcp_conn_delref(conn);
    327330                return;
     
    331334        if (link == NULL) {
    332335                log_msg(LOG_DEFAULT, LVL_DEBUG, "Nothing to retransmit");
    333                 fibril_mutex_unlock(&conn->lock);
     336                tcp_conn_unlock(conn);
    334337                tcp_conn_delref(conn);
    335338                return;
     
    341344        if (rt_seg == NULL) {
    342345                log_msg(LOG_DEFAULT, LVL_ERROR, "Memory allocation failed.");
    343                 fibril_mutex_unlock(&conn->lock);
     346                tcp_conn_unlock(conn);
    344347                tcp_conn_delref(conn);
    345348                /* XXX Handle properly */
     
    353356        tcp_tqueue_timer_set(tqe->conn);
    354357
    355         fibril_mutex_unlock(&conn->lock);
     358        tcp_conn_unlock(conn);
    356359        tcp_conn_delref(conn);
     360
     361        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: retransmit_timeout_func(%p) end", conn->name, conn);
    357362}
    358363
     
    360365static void tcp_tqueue_timer_set(tcp_conn_t *conn)
    361366{
    362         log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set()", conn->name);
     367        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() begin", conn->name);
    363368
    364369        /* Clear first to make sure we update refcnt correctly */
     
    366371
    367372        tcp_conn_addref(conn);
    368         fibril_timer_set(conn->retransmit.timer, RETRANSMIT_TIMEOUT,
     373        fibril_timer_set_locked(conn->retransmit.timer, RETRANSMIT_TIMEOUT,
    369374            retransmit_timeout_func, (void *) conn);
     375
     376        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() end", conn->name);
    370377}
    371378
     
    373380static void tcp_tqueue_timer_clear(tcp_conn_t *conn)
    374381{
    375         log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear()", conn->name);
    376 
    377         if (fibril_timer_clear(conn->retransmit.timer) == fts_active)
     382        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() begin", conn->name);
     383
     384        if (fibril_timer_clear_locked(conn->retransmit.timer) == fts_active)
    378385                tcp_conn_delref(conn);
     386
     387        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() end", conn->name);
    379388}
    380389
  • uspace/srv/net/tcp/ucall.c

    rc1b979a r78192cc7  
    9090        /* Wait for connection to be established or reset */
    9191        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Wait for connection.");
    92         fibril_mutex_lock(&nconn->lock);
     92        tcp_conn_lock(nconn);
    9393        while (nconn->cstate == st_listen ||
    9494            nconn->cstate == st_syn_sent ||
     
    100100                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was reset.");
    101101                assert(nconn->cstate == st_closed);
    102                 fibril_mutex_unlock(&nconn->lock);
     102                tcp_conn_unlock(nconn);
    103103                return TCP_ERESET;
    104104        }
    105105
    106         fibril_mutex_unlock(&nconn->lock);
     106        tcp_conn_unlock(nconn);
    107107        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was established.");
    108108
     
    121121        log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_send()", conn->name);
    122122
    123         fibril_mutex_lock(&conn->lock);
     123        tcp_conn_lock(conn);
    124124
    125125        if (conn->cstate == st_closed) {
    126                 fibril_mutex_unlock(&conn->lock);
     126                tcp_conn_unlock(conn);
    127127                return TCP_ENOTEXIST;
    128128        }
     
    135135
    136136        if (conn->snd_buf_fin) {
    137                 fibril_mutex_unlock(&conn->lock);
     137                tcp_conn_unlock(conn);
    138138                return TCP_ECLOSING;
    139139        }
     
    149149
    150150                if (conn->reset) {
    151                         fibril_mutex_unlock(&conn->lock);
     151                        tcp_conn_unlock(conn);
    152152                        return TCP_ERESET;
    153153                }
     
    165165
    166166        tcp_tqueue_new_data(conn);
    167         fibril_mutex_unlock(&conn->lock);
     167        tcp_conn_unlock(conn);
    168168
    169169        return TCP_EOK;
     
    178178        log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_receive()", conn->name);
    179179
    180         fibril_mutex_lock(&conn->lock);
     180        tcp_conn_lock(conn);
    181181
    182182        if (conn->cstate == st_closed) {
    183                 fibril_mutex_unlock(&conn->lock);
     183                tcp_conn_unlock(conn);
    184184                return TCP_ENOTEXIST;
    185185        }
     
    197197                if (conn->rcv_buf_fin) {
    198198                        /* End of data, peer closed connection */
    199                         fibril_mutex_unlock(&conn->lock);
     199                        tcp_conn_unlock(conn);
    200200                        return TCP_ECLOSING;
    201201                } else {
    202202                        /* Connection was reset */
    203203                        assert(conn->reset);
    204                         fibril_mutex_unlock(&conn->lock);
     204                        tcp_conn_unlock(conn);
    205205                        return TCP_ERESET;
    206206                }
     
    227227            conn->name, xfer_size);
    228228
    229         fibril_mutex_unlock(&conn->lock);
     229        tcp_conn_unlock(conn);
    230230
    231231        return TCP_EOK;
     
    238238            conn);
    239239
    240         fibril_mutex_lock(&conn->lock);
     240        tcp_conn_lock(conn);
    241241
    242242        if (conn->cstate == st_closed) {
    243243                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ENOTEXIST");
    244                 fibril_mutex_unlock(&conn->lock);
     244                tcp_conn_unlock(conn);
    245245                return TCP_ENOTEXIST;
    246246        }
     
    250250                tcp_conn_reset(conn);
    251251                tcp_conn_remove(conn);
     252                tcp_conn_unlock(conn);
    252253                return TCP_EOK;
    253254        }
     
    255256        if (conn->snd_buf_fin) {
    256257                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ECLOSING");
    257                 fibril_mutex_unlock(&conn->lock);
     258                tcp_conn_unlock(conn);
    258259                return TCP_ECLOSING;
    259260        }
     
    263264        tcp_tqueue_new_data(conn);
    264265
    265         fibril_mutex_unlock(&conn->lock);
     266        tcp_conn_unlock(conn);
    266267        return TCP_EOK;
    267268}
     
    321322        }
    322323
    323         fibril_mutex_lock(&conn->lock);
     324        tcp_conn_lock(conn);
    324325
    325326        if (conn->cstate == st_closed) {
    326327                log_msg(LOG_DEFAULT, LVL_WARN, "Connection is closed.");
    327328                tcp_unexpected_segment(sp, seg);
    328                 fibril_mutex_unlock(&conn->lock);
     329                tcp_conn_unlock(conn);
    329330                tcp_conn_delref(conn);
    330331                return;
     
    342343        tcp_conn_segment_arrived(conn, seg);
    343344
    344         fibril_mutex_unlock(&conn->lock);
     345        tcp_conn_unlock(conn);
    345346        tcp_conn_delref(conn);
    346347}
Note: See TracChangeset for help on using the changeset viewer.