Rev 4505 | Rev 4704 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4505 | Rev 4582 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <align.h> |
37 | #include <align.h> |
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <errno.h> |
39 | #include <errno.h> |
40 | #include <futex.h> |
40 | #include <fibril_sync.h> |
41 | //#include <stdio.h> |
41 | //#include <stdio.h> |
42 | #include <unistd.h> |
42 | #include <unistd.h> |
43 | 43 | ||
44 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
45 | #include <sys/mman.h> |
45 | #include <sys/mman.h> |
Line 70... | Line 70... | ||
70 | /** Packet server global data. |
70 | /** Packet server global data. |
71 | */ |
71 | */ |
72 | static struct{ |
72 | static struct{ |
73 | /** Safety lock. |
73 | /** Safety lock. |
74 | */ |
74 | */ |
75 | futex_t lock; |
75 | fibril_mutex_t lock; |
76 | /** Free packet queues. |
76 | /** Free packet queues. |
77 | */ |
77 | */ |
78 | packet_t free[ FREE_QUEUES_COUNT ]; |
78 | packet_t free[ FREE_QUEUES_COUNT ]; |
79 | /** Packet length upper bounds of the free packet queues. |
79 | /** Packet length upper bounds of the free packet queues. |
80 | * The maximal lengths of packets in each queue in the ascending order. |
80 | * The maximal lengths of packets in each queue in the ascending order. |
Line 83... | Line 83... | ||
83 | size_t sizes[ FREE_QUEUES_COUNT ]; |
83 | size_t sizes[ FREE_QUEUES_COUNT ]; |
84 | /** Total packets allocated. |
84 | /** Total packets allocated. |
85 | */ |
85 | */ |
86 | unsigned int count; |
86 | unsigned int count; |
87 | } ps_globals = { |
87 | } ps_globals = { |
88 | { 1 }, |
- | |
- | 88 | { .counter = 1, .waiters = { .prev = & ps_globals.lock.waiters, .next = & ps_globals.lock.waiters, }}, |
|
89 | { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, |
89 | { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, |
90 | { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64 }, |
90 | { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64 }, |
91 | 0 |
91 | 0 |
92 | }; |
92 | }; |
93 | 93 | ||
Line 206... | Line 206... | ||
206 | int packet_release_wrapper( packet_id_t packet_id ){ |
206 | int packet_release_wrapper( packet_id_t packet_id ){ |
207 | packet_t packet; |
207 | packet_t packet; |
208 | 208 | ||
209 | packet = pm_find( packet_id ); |
209 | packet = pm_find( packet_id ); |
210 | if( ! packet_is_valid( packet )) return ENOENT; |
210 | if( ! packet_is_valid( packet )) return ENOENT; |
211 | futex_down( & ps_globals.lock ); |
211 | fibril_mutex_lock( & ps_globals.lock ); |
212 | pq_destroy( packet, packet_release ); |
212 | pq_destroy( packet, packet_release ); |
213 | futex_up( & ps_globals.lock ); |
213 | fibril_mutex_unlock( & ps_globals.lock ); |
214 | return EOK; |
214 | return EOK; |
215 | } |
215 | } |
216 | 216 | ||
217 | void packet_release( packet_t packet ){ |
217 | void packet_release( packet_t packet ){ |
218 | int index; |
218 | int index; |
Line 225... | Line 225... | ||
225 | int index; |
225 | int index; |
226 | packet_t packet; |
226 | packet_t packet; |
227 | size_t length; |
227 | size_t length; |
228 | 228 | ||
229 | length = ALIGN_UP( sizeof( struct packet ) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE ); |
229 | length = ALIGN_UP( sizeof( struct packet ) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE ); |
230 | futex_down( & ps_globals.lock ); |
230 | fibril_mutex_lock( & ps_globals.lock ); |
231 | for( index = 0; index < FREE_QUEUES_COUNT - 1; ++ index ){ |
231 | for( index = 0; index < FREE_QUEUES_COUNT - 1; ++ index ){ |
232 | if( length <= ps_globals.sizes[ index ] ){ |
232 | if( length <= ps_globals.sizes[ index ] ){ |
233 | packet = ps_globals.free[ index ]; |
233 | packet = ps_globals.free[ index ]; |
234 | while( packet_is_valid( packet ) && ( packet->length < length )){ |
234 | while( packet_is_valid( packet ) && ( packet->length < length )){ |
235 | packet = pm_find( packet->next ); |
235 | packet = pm_find( packet->next ); |
Line 239... | Line 239... | ||
239 | ps_globals.free[ index ] = pq_detach( packet ); |
239 | ps_globals.free[ index ] = pq_detach( packet ); |
240 | }else{ |
240 | }else{ |
241 | pq_detach( packet ); |
241 | pq_detach( packet ); |
242 | } |
242 | } |
243 | packet_init( packet, addr_len, max_prefix, max_content, max_suffix ); |
243 | packet_init( packet, addr_len, max_prefix, max_content, max_suffix ); |
244 | futex_up( & ps_globals.lock ); |
244 | fibril_mutex_unlock( & ps_globals.lock ); |
245 | return packet; |
245 | return packet; |
246 | } |
246 | } |
247 | } |
247 | } |
248 | } |
248 | } |
249 | packet = packet_create( length, addr_len, max_prefix, max_content, max_suffix ); |
249 | packet = packet_create( length, addr_len, max_prefix, max_content, max_suffix ); |
250 | futex_up( & ps_globals.lock ); |
250 | fibril_mutex_unlock( & ps_globals.lock ); |
251 | return packet; |
251 | return packet; |
252 | } |
252 | } |
253 | 253 | ||
254 | packet_t packet_create( size_t length, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
254 | packet_t packet_create( size_t length, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
255 | ERROR_DECLARE; |
255 | ERROR_DECLARE; |