Ignore:
Timestamp:
2010-04-23T21:42:26Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6c39a907
Parents:
38aaacc2 (diff), 80badbe (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/lib/socket/packet/packet_server.c

    r38aaacc2 rf4f866c  
    9797};
    9898
    99 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){
    100         if(! packet){
     99int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id)
     100{
     101        if (!packet)
    101102                return EINVAL;
    102         }
     103       
    103104        *packet = pm_find(packet_id);
    104105        return (*packet) ? EOK : ENOENT;
     
    161162}
    162163
    163 /** Returns the packet of dimensions at least as given.
    164  *  Tries to reuse free packets first.
    165  *  Creates a&nbsp;new packet aligned to the memory page size if none available.
    166  *  Locks the global data during its processing.
    167  *  @param[in] addr_len The source and destination addresses maximal length in bytes.
    168  *  @param[in] max_prefix The maximal prefix length in bytes.
    169  *  @param[in] max_content The maximal content length in bytes.
    170  *  @param[in] max_suffix The maximal suffix length in bytes.
    171  *  @returns The packet of dimensions at least as given.
    172  *  @returns NULL if there is not enough memory left.
    173  */
    174 static packet_t packet_get(size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
    175         int index;
     164/** Return the packet of dimensions at least as given.
     165 *
     166 * Try to reuse free packets first.
     167 * Create a new packet aligned to the memory page size if none available.
     168 * Lock the global data during its processing.
     169 *
     170 * @param[in] addr_len    The source and destination addresses
     171 *                        maximal length in bytes.
     172 * @param[in] max_prefix  The maximal prefix length in bytes.
     173 * @param[in] max_content The maximal content length in bytes.
     174 * @param[in] max_suffix  The maximal suffix length in bytes.
     175 *
     176 * @return The packet of dimensions at least as given.
     177 * @return NULL if there is not enough memory left.
     178 *
     179 */
     180static packet_t packet_get_local(size_t addr_len, size_t max_prefix,
     181    size_t max_content, size_t max_suffix)
     182{
     183        size_t length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix
     184            + max_content + max_suffix, PAGE_SIZE);
     185       
     186        fibril_mutex_lock(&ps_globals.lock);
     187       
    176188        packet_t packet;
    177         size_t length;
    178 
    179         length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE);
    180         fibril_mutex_lock(&ps_globals.lock);
    181         for(index = 0; index < FREE_QUEUES_COUNT - 1; ++ index){
    182                 if(length <= ps_globals.sizes[index]){
     189        unsigned int index;
     190       
     191        for (index = 0; index < FREE_QUEUES_COUNT - 1; index++) {
     192                if (length <= ps_globals.sizes[index]) {
    183193                        packet = ps_globals.free[index];
    184                         while(packet_is_valid(packet) && (packet->length < length)){
     194                       
     195                        while (packet_is_valid(packet) && (packet->length < length))
    185196                                packet = pm_find(packet->next);
    186                         }
    187                         if(packet_is_valid(packet)){
    188                                 if(packet == ps_globals.free[index]){
     197                       
     198                        if (packet_is_valid(packet)) {
     199                                if (packet == ps_globals.free[index])
    189200                                        ps_globals.free[index] = pq_detach(packet);
    190                                 }else{
     201                                else
    191202                                        pq_detach(packet);
    192                                 }
    193                                 packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
     203                               
     204                                packet_init(packet, addr_len, max_prefix, max_content,
     205                                    max_suffix);
    194206                                fibril_mutex_unlock(&ps_globals.lock);
    195                                 // remove debug dump
    196 //                              printf("packet %d got\n", packet->packet_id);
     207                               
    197208                                return packet;
    198209                        }
    199210                }
    200211        }
    201         packet = packet_create(length, addr_len, max_prefix, max_content, max_suffix);
     212       
     213        packet = packet_create(length, addr_len, max_prefix, max_content,
     214            max_suffix);
     215       
    202216        fibril_mutex_unlock(&ps_globals.lock);
    203         // remove debug dump
    204 //      printf("packet %d created\n", packet->packet_id);
     217       
    205218        return packet;
    206219}
    207220
    208 packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){
    209         return packet_get(addr_len, max_prefix, max_content, max_suffix);
    210 }
    211 
    212 packet_t packet_get_1(int phone, size_t content){
    213         return packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, DEFAULT_SUFFIX);
    214 }
    215 
    216 /** Releases the packet and returns it to the appropriate free packet queue.
     221packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len,
     222    size_t max_prefix, size_t max_suffix)
     223{
     224        return packet_get_local(addr_len, max_prefix, max_content, max_suffix);
     225}
     226
     227packet_t packet_get_1_local(int phone, size_t content)
     228{
     229        return packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content,
     230            DEFAULT_SUFFIX);
     231}
     232
     233/** Release the packet and returns it to the appropriate free packet queue.
     234 *
    217235 *  Should be used only when the global data are locked.
     236 *
    218237 *  @param[in] packet The packet to be released.
     238 *
    219239 */
    220240static void packet_release(packet_t packet){
     
    247267}
    248268
    249 void pq_release(int phone, packet_id_t packet_id){
     269void pq_release_local(int phone, packet_id_t packet_id)
     270{
    250271        (void) packet_release_wrapper(packet_id);
    251272}
     
    281302                        return EOK;
    282303                case NET_PACKET_CREATE_1:
    283                         packet = packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
     304                        packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
    284305                        if(! packet){
    285306                                return ENOMEM;
     
    290311                        return EOK;
    291312                case NET_PACKET_CREATE_4:
    292                         packet = packet_get(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
     313                        packet = packet_get_local(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
    293314                        if(! packet){
    294315                                return ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.