Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/icmp/icmp.c

    raadf01e rb48ebd19  
    4141#include <fibril_synch.h>
    4242#include <stdint.h>
     43#include <string.h>
    4344
    4445#include <ipc/ipc.h>
     
    175176/** Requests an echo message.
    176177 *  Sends a packet with specified parameters to the target host and waits for the reply upto the given timeout.
    177  *  Blocks the caller until the reply or the timeout occurres.
     178 *  Blocks the caller until the reply or the timeout occurs.
    178179 *  @param[in] id The message identifier.
    179180 *  @param[in] sequence The message sequence parameter.
     
    221222
    222223/** Tries to set the pending reply result as the received message type.
    223  *  If the reply data are still present, the reply timeouted and the parent fibril is awaken.
    224  *  The global lock is not released in this case to be reused by the parent fibril.
     224 *  If the reply data is not present, the reply timed out and the other fibril
     225 *  is already awake.
    225226 *  Releases the packet.
    226227 *  @param[in] packet The received reply message.
     
    334335        }
    335336
    336         // unlock the globals and wait for a reply
     337        // unlock the globals so that we can wait for the reply
    337338        fibril_rwlock_write_unlock(&icmp_globals.lock);
    338339
     
    340341        icmp_send_packet(ICMP_ECHO, 0, packet, header, 0, ttl, tos, dont_fragment);
    341342
    342         // wait for a reply
     343        // wait for the reply
    343344        // timeout in microseconds
    344345        if(ERROR_OCCURRED(fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex, timeout * 1000))){
    345346                result = ERROR_CODE;
    346 
    347                 // lock the globals again and clean up
    348                 fibril_rwlock_write_lock(&icmp_globals.lock);
    349347        }else{
    350348                // read the result
    351349                result = reply->result;
    352 
    353                 // release the reply structure
    354                 fibril_mutex_unlock(&reply->mutex);
    355         }
     350        }
     351
     352        // drop the reply mutex before locking the globals again
     353        fibril_mutex_unlock(&reply->mutex);
     354        fibril_rwlock_write_lock(&icmp_globals.lock);
    356355
    357356        // destroy the reply structure
     
    636635                // set the result
    637636                reply->result = type;
    638                 // notify the main fibril
     637                // notify the waiting fibril
    639638                fibril_condvar_signal(&reply->condvar);
    640         }else{
    641                 // unlock only if no reply
    642                 fibril_rwlock_write_unlock(&icmp_globals.lock);
    643         }
     639        }
     640        fibril_rwlock_write_unlock(&icmp_globals.lock);
    644641        return EOK;
    645642}
Note: See TracChangeset for help on using the changeset viewer.