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