Changeset 15d0046 in mainline for uspace/srv/net/ethip/atrans.c


Ignore:
Timestamp:
2014-09-12T13:22:33Z (10 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9b20126
Parents:
8db09e4 (diff), 105d8d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/ethip/atrans.c

    r8db09e4 r15d0046  
    103103}
    104104
    105 int atrans_lookup(addr32_t ip_addr, addr48_t mac_addr)
     105static int atrans_lookup_locked(addr32_t ip_addr, addr48_t mac_addr)
    106106{
    107         fibril_mutex_lock(&atrans_list_lock);
    108107        ethip_atrans_t *atrans = atrans_find(ip_addr);
    109         if (atrans == NULL) {
    110                 fibril_mutex_unlock(&atrans_list_lock);
     108        if (atrans == NULL)
    111109                return ENOENT;
    112         }
    113        
    114         fibril_mutex_unlock(&atrans_list_lock);
     110
    115111        addr48(atrans->mac_addr, mac_addr);
    116112        return EOK;
    117113}
    118114
    119 int atrans_wait_timeout(suseconds_t timeout)
     115int atrans_lookup(addr32_t ip_addr, addr48_t mac_addr)
    120116{
     117        int rc;
     118
    121119        fibril_mutex_lock(&atrans_list_lock);
    122         int rc = fibril_condvar_wait_timeout(&atrans_cv, &atrans_list_lock,
    123             timeout);
     120        rc = atrans_lookup_locked(ip_addr, mac_addr);
    124121        fibril_mutex_unlock(&atrans_list_lock);
    125        
     122
     123        return rc;
     124}
     125
     126static void atrans_lookup_timeout_handler(void *arg)
     127{
     128        bool *timedout = (bool *)arg;
     129
     130        fibril_mutex_lock(&atrans_list_lock);
     131        *timedout = true;
     132        fibril_mutex_unlock(&atrans_list_lock);
     133        fibril_condvar_broadcast(&atrans_cv);
     134}
     135
     136int atrans_lookup_timeout(addr32_t ip_addr, suseconds_t timeout,
     137    addr48_t mac_addr)
     138{
     139        fibril_timer_t *t;
     140        bool timedout;
     141        int rc;
     142
     143        t = fibril_timer_create(NULL);
     144        if (t == NULL)
     145                return ENOMEM;
     146
     147        timedout = false;
     148        fibril_timer_set(t, timeout, atrans_lookup_timeout_handler, &timedout);
     149
     150        fibril_mutex_lock(&atrans_list_lock);
     151
     152        while ((rc = atrans_lookup_locked(ip_addr, mac_addr)) == ENOENT &&
     153            !timedout) {
     154                fibril_condvar_wait(&atrans_cv, &atrans_list_lock);
     155        }
     156
     157        fibril_mutex_unlock(&atrans_list_lock);
     158        (void) fibril_timer_clear(t);
     159        fibril_timer_destroy(t);
     160
    126161        return rc;
    127162}
Note: See TracChangeset for help on using the changeset viewer.