Changes in uspace/lib/socket/packet/packet_server.c [14f1db0:849ed54] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/socket/packet/packet_server.c
r14f1db0 r849ed54 97 97 }; 98 98 99 int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id) 100 { 101 if (!packet) 99 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){ 100 if(! packet){ 102 101 return EINVAL; 103 102 } 104 103 *packet = pm_find(packet_id); 105 104 return (*packet) ? EOK : ENOENT; … … 162 161 } 163 162 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 */ 180 static 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 163 /** Returns the packet of dimensions at least as given. 164 * Tries to reuse free packets first. 165 * Creates a 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; 176 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); 186 180 fibril_mutex_lock(&ps_globals.lock); 187 188 packet_t packet; 189 unsigned int index; 190 191 for (index = 0; index < FREE_QUEUES_COUNT - 1; index++) { 192 if (length <= ps_globals.sizes[index]) { 181 for(index = 0; index < FREE_QUEUES_COUNT - 1; ++ index){ 182 if(length <= ps_globals.sizes[index]){ 193 183 packet = ps_globals.free[index]; 194 195 while (packet_is_valid(packet) && (packet->length < length)) 184 while(packet_is_valid(packet) && (packet->length < length)){ 196 185 packet = pm_find(packet->next); 197 198 if (packet_is_valid(packet)){199 if (packet == ps_globals.free[index])186 } 187 if(packet_is_valid(packet)){ 188 if(packet == ps_globals.free[index]){ 200 189 ps_globals.free[index] = pq_detach(packet); 201 else190 }else{ 202 191 pq_detach(packet); 203 204 packet_init(packet, addr_len, max_prefix, max_content, 205 max_suffix); 192 } 193 packet_init(packet, addr_len, max_prefix, max_content, max_suffix); 206 194 fibril_mutex_unlock(&ps_globals.lock); 207 195 // remove debug dump 196 // printf("packet %d got\n", packet->packet_id); 208 197 return packet; 209 198 } 210 199 } 211 200 } 212 213 packet = packet_create(length, addr_len, max_prefix, max_content, 214 max_suffix); 215 201 packet = packet_create(length, addr_len, max_prefix, max_content, max_suffix); 216 202 fibril_mutex_unlock(&ps_globals.lock); 217 203 // remove debug dump 204 // printf("packet %d created\n", packet->packet_id); 218 205 return packet; 219 206 } 220 207 221 packet_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 227 packet_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 * 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. 235 217 * Should be used only when the global data are locked. 236 *237 218 * @param[in] packet The packet to be released. 238 *239 219 */ 240 220 static void packet_release(packet_t packet){ … … 267 247 } 268 248 269 void pq_release_local(int phone, packet_id_t packet_id) 270 { 249 void pq_release(int phone, packet_id_t packet_id){ 271 250 (void) packet_release_wrapper(packet_id); 272 251 } … … 302 281 return EOK; 303 282 case NET_PACKET_CREATE_1: 304 packet = packet_get _local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);283 packet = packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX); 305 284 if(! packet){ 306 285 return ENOMEM; … … 311 290 return EOK; 312 291 case NET_PACKET_CREATE_4: 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));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)); 314 293 if(! packet){ 315 294 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.