Ignore:
File:
1 edited

Legend:

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

    rb48ebd19 raadf01e  
    4141#include <fibril_synch.h>
    4242#include <stdint.h>
    43 #include <string.h>
    4443
    4544#include <ipc/ipc.h>
     
    176175/** Requests an echo message.
    177176 *  Sends a packet with specified parameters to the target host and waits for the reply upto the given timeout.
    178  *  Blocks the caller until the reply or the timeout occurs.
     177 *  Blocks the caller until the reply or the timeout occurres.
    179178 *  @param[in] id The message identifier.
    180179 *  @param[in] sequence The message sequence parameter.
     
    222221
    223222/** Tries to set the pending reply result as the received message type.
    224  *  If the reply data is not present, the reply timed out and the other fibril
    225  *  is already awake.
     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.
    226225 *  Releases the packet.
    227226 *  @param[in] packet The received reply message.
     
    335334        }
    336335
    337         // unlock the globals so that we can wait for the reply
     336        // unlock the globals and wait for a reply
    338337        fibril_rwlock_write_unlock(&icmp_globals.lock);
    339338
     
    341340        icmp_send_packet(ICMP_ECHO, 0, packet, header, 0, ttl, tos, dont_fragment);
    342341
    343         // wait for the reply
     342        // wait for a reply
    344343        // timeout in microseconds
    345344        if(ERROR_OCCURRED(fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex, timeout * 1000))){
    346345                result = ERROR_CODE;
     346
     347                // lock the globals again and clean up
     348                fibril_rwlock_write_lock(&icmp_globals.lock);
    347349        }else{
    348350                // read the result
    349351                result = reply->result;
    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);
     352
     353                // release the reply structure
     354                fibril_mutex_unlock(&reply->mutex);
     355        }
    355356
    356357        // destroy the reply structure
     
    635636                // set the result
    636637                reply->result = type;
    637                 // notify the waiting fibril
     638                // notify the main fibril
    638639                fibril_condvar_signal(&reply->condvar);
    639         }
    640         fibril_rwlock_write_unlock(&icmp_globals.lock);
     640        }else{
     641                // unlock only if no reply
     642                fibril_rwlock_write_unlock(&icmp_globals.lock);
     643        }
    641644        return EOK;
    642645}
Note: See TracChangeset for help on using the changeset viewer.