Changes in uspace/lib/socket/packet/packet_server.c [849ed54:14f1db0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/socket/packet/packet_server.c
r849ed54 r14f1db0 97 97 }; 98 98 99 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){ 100 if(! packet){ 99 int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id) 100 { 101 if (!packet) 101 102 return EINVAL; 102 }103 103 104 *packet = pm_find(packet_id); 104 105 return (*packet) ? EOK : ENOENT; … … 161 162 } 162 163 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; 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 186 fibril_mutex_lock(&ps_globals.lock); 187 176 188 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]) { 183 193 packet = ps_globals.free[index]; 184 while(packet_is_valid(packet) && (packet->length < length)){ 194 195 while (packet_is_valid(packet) && (packet->length < length)) 185 196 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]) 189 200 ps_globals.free[index] = pq_detach(packet); 190 }else{201 else 191 202 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); 194 206 fibril_mutex_unlock(&ps_globals.lock); 195 // remove debug dump 196 // printf("packet %d got\n", packet->packet_id); 207 197 208 return packet; 198 209 } 199 210 } 200 211 } 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 202 216 fibril_mutex_unlock(&ps_globals.lock); 203 // remove debug dump 204 // printf("packet %d created\n", packet->packet_id); 217 205 218 return packet; 206 219 } 207 220 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. 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 * 217 235 * Should be used only when the global data are locked. 236 * 218 237 * @param[in] packet The packet to be released. 238 * 219 239 */ 220 240 static void packet_release(packet_t packet){ … … 247 267 } 248 268 249 void pq_release(int phone, packet_id_t packet_id){ 269 void pq_release_local(int phone, packet_id_t packet_id) 270 { 250 271 (void) packet_release_wrapper(packet_id); 251 272 } … … 281 302 return EOK; 282 303 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); 284 305 if(! packet){ 285 306 return ENOMEM; … … 290 311 return EOK; 291 312 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)); 293 314 if(! packet){ 294 315 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.