Changeset 78192cc7 in mainline for uspace/srv/net/tcp/conn.c


Ignore:
Timestamp:
2014-07-13T14:06:23Z (10 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.