Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/net/packet.c

    rc69d327 r46d4d9f  
    4141#include <unistd.h>
    4242#include <errno.h>
    43 #include <err.h>
    4443
    4544#include <sys/mman.h>
     
    6362
    6463/** Type definition of the packet map page. */
    65 typedef packet_t packet_map_t[PACKET_MAP_SIZE];
    66 
    67 /** Type definition of the packet map page pointer. */
    68 typedef packet_map_t * packet_map_ref;
     64typedef packet_t *packet_map_t[PACKET_MAP_SIZE];
    6965
    7066/** Packet map.
     
    8682/** Initializes the packet map.
    8783 *
    88  * @returns             EOK on success.
    89  * @returns             ENOMEM if there is not enough memory left.
     84 * @return              EOK on success.
     85 * @return              ENOMEM if there is not enough memory left.
    9086 */
    9187int pm_init(void)
    9288{
    93         ERROR_DECLARE;
     89        int rc;
    9490
    9591        fibril_rwlock_initialize(&pm_globals.lock);
     92       
    9693        fibril_rwlock_write_lock(&pm_globals.lock);
    97         ERROR_PROPAGATE(gpm_initialize(&pm_globals.packet_map));
     94        rc = gpm_initialize(&pm_globals.packet_map);
    9895        fibril_rwlock_write_unlock(&pm_globals.lock);
    99         return EOK;
     96       
     97        return rc;
    10098}
    10199
     
    103101 *
    104102 * @param[in] packet_id The packet identifier to be found.
    105  * @returns             The found packet reference.
    106  * @returns             NULL if the mapping does not exist.
    107  */
    108 packet_t pm_find(packet_id_t packet_id)
    109 {
    110         packet_map_ref map;
    111         packet_t packet;
     103 * @return              The found packet reference.
     104 * @return              NULL if the mapping does not exist.
     105 */
     106packet_t *pm_find(packet_id_t packet_id)
     107{
     108        packet_map_t *map;
     109        packet_t *packet;
    112110
    113111        if (!packet_id)
     
    132130 *
    133131 * @param[in] packet    The packet to be remembered.
    134  * @returns             EOK on success.
    135  * @returns             EINVAL if the packet is not valid.
    136  * @returns             EINVAL if the packet map is not initialized.
    137  * @returns             ENOMEM if there is not enough memory left.
    138  */
    139 int pm_add(packet_t packet)
    140 {
    141         ERROR_DECLARE;
    142 
    143         packet_map_ref map;
     132 * @return              EOK on success.
     133 * @return              EINVAL if the packet is not valid.
     134 * @return              EINVAL if the packet map is not initialized.
     135 * @return              ENOMEM if there is not enough memory left.
     136 */
     137int pm_add(packet_t *packet)
     138{
     139        packet_map_t *map;
     140        int rc;
    144141
    145142        if (!packet_is_valid(packet))
     
    154151        } else {
    155152                do {
    156                         map = (packet_map_ref) malloc(sizeof(packet_map_t));
     153                        map = (packet_map_t *) malloc(sizeof(packet_map_t));
    157154                        if (!map) {
    158155                                fibril_rwlock_write_unlock(&pm_globals.lock);
     
    160157                        }
    161158                        bzero(map, sizeof(packet_map_t));
    162                         if ((ERROR_CODE =
    163                             gpm_add(&pm_globals.packet_map, map)) < 0) {
     159                        rc = gpm_add(&pm_globals.packet_map, map);
     160                        if (rc < 0) {
    164161                                fibril_rwlock_write_unlock(&pm_globals.lock);
    165162                                free(map);
    166                                 return ERROR_CODE;
     163                                return rc;
    167164                        }
    168165                } while (PACKET_MAP_PAGE(packet->packet_id) >=
     
    180177        int count;
    181178        int index;
    182         packet_map_ref map;
    183         packet_t packet;
     179        packet_map_t *map;
     180        packet_t *packet;
    184181
    185182        fibril_rwlock_write_lock(&pm_globals.lock);
     
    208205 * @param[in] order     The packet order value.
    209206 * @param[in] metric    The metric value of the packet.
    210  * @returns             EOK on success.
    211  * @returns             EINVAL if the first parameter is NULL.
    212  * @returns             EINVAL if the packet is not valid.
    213  */
    214 int pq_add(packet_t * first, packet_t packet, size_t order, size_t metric)
    215 {
    216         packet_t item;
     207 * @return              EOK on success.
     208 * @return              EINVAL if the first parameter is NULL.
     209 * @return              EINVAL if the packet is not valid.
     210 */
     211int pq_add(packet_t **first, packet_t *packet, size_t order, size_t metric)
     212{
     213        packet_t *item;
    217214
    218215        if (!first || !packet_is_valid(packet))
     
    252249 * @param[in] first     The first packet of the queue.
    253250 * @param[in] order     The packet order value.
    254  * @returns             The packet with the given order.
    255  * @returns             NULL if the first packet is not valid.
    256  * @returns             NULL if the packet is not found.
    257  */
    258 packet_t pq_find(packet_t packet, size_t order)
    259 {
    260         packet_t item;
     251 * @return              The packet with the given order.
     252 * @return              NULL if the first packet is not valid.
     253 * @return              NULL if the packet is not found.
     254 */
     255packet_t *pq_find(packet_t *packet, size_t order)
     256{
     257        packet_t *item;
    261258
    262259        if (!packet_is_valid(packet))
     
    278275 * @param[in] packet    The packet in the queue.
    279276 * @param[in] new_packet The new packet to be inserted.
    280  * @returns             EOK on success.
    281  * @returns             EINVAL if etiher of the packets is invalid.
    282  */
    283 int pq_insert_after(packet_t packet, packet_t new_packet)
    284 {
    285         packet_t item;
     277 * @return              EOK on success.
     278 * @return              EINVAL if etiher of the packets is invalid.
     279 */
     280int pq_insert_after(packet_t *packet, packet_t *new_packet)
     281{
     282        packet_t *item;
    286283
    287284        if (!packet_is_valid(packet) || !packet_is_valid(new_packet))
     
    301298 *
    302299 * @param[in] packet    The packet to be detached.
    303  * @returns             The next packet in the queue. If the packet is the first
     300 * @return              The next packet in the queue. If the packet is the first
    304301 *                      one of the queue, this becomes the new first one.
    305  * @returns             NULL if there is no packet left.
    306  * @returns             NULL if the packet is not valid.
    307  */
    308 packet_t pq_detach(packet_t packet)
    309 {
    310         packet_t next;
    311         packet_t previous;
     302 * @return              NULL if there is no packet left.
     303 * @return              NULL if the packet is not valid.
     304 */
     305packet_t *pq_detach(packet_t *packet)
     306{
     307        packet_t *next;
     308        packet_t *previous;
    312309
    313310        if (!packet_is_valid(packet))
     
    331328 * @param[in] order     The packet order value.
    332329 * @param[in] metric    The metric value of the packet.
    333  * @returns             EOK on success.
    334  * @returns             EINVAL if the packet is invalid.
    335  */
    336 int pq_set_order(packet_t packet, size_t order, size_t metric)
     330 * @return              EOK on success.
     331 * @return              EINVAL if the packet is invalid.
     332 */
     333int pq_set_order(packet_t *packet, size_t order, size_t metric)
    337334{
    338335        if (!packet_is_valid(packet))
     
    349346 * @param[out] order    The packet order value.
    350347 * @param[out] metric   The metric value of the packet.
    351  * @returns             EOK on success.
    352  * @returns             EINVAL if the packet is invalid.
    353  */
    354 int pq_get_order(packet_t packet, size_t *order, size_t *metric)
     348 * @return              EOK on success.
     349 * @return              EINVAL if the packet is invalid.
     350 */
     351int pq_get_order(packet_t *packet, size_t *order, size_t *metric)
    355352{
    356353        if (!packet_is_valid(packet))
     
    375372 *                      packets after its detachment.
    376373 */
    377 void pq_destroy(packet_t first, void (*packet_release)(packet_t packet))
    378 {
    379         packet_t actual;
    380         packet_t next;
     374void pq_destroy(packet_t *first, void (*packet_release)(packet_t *packet))
     375{
     376        packet_t *actual;
     377        packet_t *next;
    381378
    382379        actual = first;
     
    394391 *
    395392 * @param[in] packet    The packet queue member.
    396  * @returns             The next packet in the queue.
    397  * @returns             NULL if there is no next packet.
    398  * @returns             NULL if the packet is not valid.
    399  */
    400 packet_t pq_next(packet_t packet)
     393 * @return              The next packet in the queue.
     394 * @return              NULL if there is no next packet.
     395 * @return              NULL if the packet is not valid.
     396 */
     397packet_t *pq_next(packet_t *packet)
    401398{
    402399        if (!packet_is_valid(packet))
     
    409406 *
    410407 * @param[in] packet    The packet queue member.
    411  * @returns             The previous packet in the queue.
    412  * @returns             NULL if there is no previous packet.
    413  * @returns             NULL if the packet is not valid.
    414  */
    415 packet_t pq_previous(packet_t packet)
     408 * @return              The previous packet in the queue.
     409 * @return              NULL if there is no previous packet.
     410 * @return              NULL if the packet is not valid.
     411 */
     412packet_t *pq_previous(packet_t *packet)
    416413{
    417414        if (!packet_is_valid(packet))
Note: See TracChangeset for help on using the changeset viewer.