Changes in uspace/lib/c/generic/net/packet.c [5fe7692:c69d327] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/net/packet.c
r5fe7692 rc69d327 41 41 #include <unistd.h> 42 42 #include <errno.h> 43 #include <err.h> 43 44 44 45 #include <sys/mman.h> … … 62 63 63 64 /** Type definition of the packet map page. */ 64 typedef packet_t *packet_map_t[PACKET_MAP_SIZE]; 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; 65 69 66 70 /** Packet map. … … 82 86 /** Initializes the packet map. 83 87 * 84 * @return EOK on success.85 * @return ENOMEM if there is not enough memory left.88 * @returns EOK on success. 89 * @returns ENOMEM if there is not enough memory left. 86 90 */ 87 91 int pm_init(void) 88 92 { 89 int rc;93 ERROR_DECLARE; 90 94 91 95 fibril_rwlock_initialize(&pm_globals.lock); 92 93 96 fibril_rwlock_write_lock(&pm_globals.lock); 94 rc = gpm_initialize(&pm_globals.packet_map);97 ERROR_PROPAGATE(gpm_initialize(&pm_globals.packet_map)); 95 98 fibril_rwlock_write_unlock(&pm_globals.lock); 96 97 return rc; 99 return EOK; 98 100 } 99 101 … … 101 103 * 102 104 * @param[in] packet_id The packet identifier to be found. 103 * @return The found packet reference.104 * @return NULL if the mapping does not exist.105 */ 106 packet_t *pm_find(packet_id_t packet_id)107 { 108 packet_map_ t *map;109 packet_t *packet;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; 110 112 111 113 if (!packet_id) … … 130 132 * 131 133 * @param[in] packet The packet to be remembered. 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 */ 137 int pm_add(packet_t *packet) 138 { 139 packet_map_t *map; 140 int rc; 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; 141 144 142 145 if (!packet_is_valid(packet)) … … 151 154 } else { 152 155 do { 153 map = (packet_map_ t *) malloc(sizeof(packet_map_t));156 map = (packet_map_ref) malloc(sizeof(packet_map_t)); 154 157 if (!map) { 155 158 fibril_rwlock_write_unlock(&pm_globals.lock); … … 157 160 } 158 161 bzero(map, sizeof(packet_map_t)); 159 rc = gpm_add(&pm_globals.packet_map, map);160 if (rc< 0) {162 if ((ERROR_CODE = 163 gpm_add(&pm_globals.packet_map, map)) < 0) { 161 164 fibril_rwlock_write_unlock(&pm_globals.lock); 162 165 free(map); 163 return rc;166 return ERROR_CODE; 164 167 } 165 168 } while (PACKET_MAP_PAGE(packet->packet_id) >= … … 177 180 int count; 178 181 int index; 179 packet_map_ t *map;180 packet_t *packet;182 packet_map_ref map; 183 packet_t packet; 181 184 182 185 fibril_rwlock_write_lock(&pm_globals.lock); … … 190 193 } 191 194 } 192 gpm_destroy(&pm_globals.packet_map , free);193 / * leave locked */195 gpm_destroy(&pm_globals.packet_map); 196 // leave locked 194 197 } 195 198 … … 205 208 * @param[in] order The packet order value. 206 209 * @param[in] metric The metric value of the packet. 207 * @return EOK on success.208 * @return EINVAL if the first parameter is NULL.209 * @return EINVAL if the packet is not valid.210 */ 211 int pq_add(packet_t * *first, packet_t *packet, size_t order, size_t metric)212 { 213 packet_t *item;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; 214 217 215 218 if (!first || !packet_is_valid(packet)) … … 249 252 * @param[in] first The first packet of the queue. 250 253 * @param[in] order The packet order value. 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 */ 255 packet_t *pq_find(packet_t *packet, size_t order)256 { 257 packet_t *item;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; 258 261 259 262 if (!packet_is_valid(packet)) … … 275 278 * @param[in] packet The packet in the queue. 276 279 * @param[in] new_packet The new packet to be inserted. 277 * @return EOK on success.278 * @return EINVAL if etiher of the packets is invalid.279 */ 280 int pq_insert_after(packet_t *packet, packet_t *new_packet)281 { 282 packet_t *item;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; 283 286 284 287 if (!packet_is_valid(packet) || !packet_is_valid(new_packet)) … … 298 301 * 299 302 * @param[in] packet The packet to be detached. 300 * @return The next packet in the queue. If the packet is the first303 * @returns The next packet in the queue. If the packet is the first 301 304 * one of the queue, this becomes the new first one. 302 * @return NULL if there is no packet left.303 * @return NULL if the packet is not valid.304 */ 305 packet_t *pq_detach(packet_t *packet)306 { 307 packet_t *next;308 packet_t *previous;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; 309 312 310 313 if (!packet_is_valid(packet)) … … 328 331 * @param[in] order The packet order value. 329 332 * @param[in] metric The metric value of the packet. 330 * @return EOK on success.331 * @return EINVAL if the packet is invalid.332 */ 333 int pq_set_order(packet_t *packet, size_t order, size_t metric)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) 334 337 { 335 338 if (!packet_is_valid(packet)) … … 346 349 * @param[out] order The packet order value. 347 350 * @param[out] metric The metric value of the packet. 348 * @return EOK on success.349 * @return EINVAL if the packet is invalid.350 */ 351 int pq_get_order(packet_t *packet, size_t *order, size_t *metric)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) 352 355 { 353 356 if (!packet_is_valid(packet)) … … 372 375 * packets after its detachment. 373 376 */ 374 void pq_destroy(packet_t *first, void (*packet_release)(packet_t *packet))375 { 376 packet_t *actual;377 packet_t *next;377 void pq_destroy(packet_t first, void (*packet_release)(packet_t packet)) 378 { 379 packet_t actual; 380 packet_t next; 378 381 379 382 actual = first; … … 391 394 * 392 395 * @param[in] packet The packet queue member. 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 */ 397 packet_t *pq_next(packet_t *packet)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) 398 401 { 399 402 if (!packet_is_valid(packet)) … … 406 409 * 407 410 * @param[in] packet The packet queue member. 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 */ 412 packet_t *pq_previous(packet_t *packet)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) 413 416 { 414 417 if (!packet_is_valid(packet))
Note:
See TracChangeset
for help on using the changeset viewer.