2 * UCW Library -- Asynchronous I/O
4 * (c) 2006 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #ifndef _UCW_ASYNCIO_H
11 #define _UCW_ASYNCIO_H
13 #include "lib/semaphore.h"
14 #include "lib/clists.h"
16 /* FIXME: Comment, especially on request ordering */
19 uns max_requests; // Maximum number of requests allowed on this queue [user-settable]
20 uns buffer_size; // How large buffers do we use [user-settable]
21 uns allocated_requests;
23 clist idle_list; // Recycled requests waiting for get
24 clist done_list; // Requests returned from the worker threads
25 sem_t *done_sem; // ... and how many of them
26 clist wait_list; // Requests available for wait()
33 ASIO_BACKGROUND_WRITE, // Write with no success notification
38 struct asio_queue *queue;
47 void asio_cleanup(void);
49 void asio_init_queue(struct asio_queue *q); // Initialize a new queue
50 struct asio_request *asio_get(struct asio_queue *q); // Get an empty request
51 void asio_submit(struct asio_request *r); // Submit the request
52 struct asio_request *asio_wait(struct asio_queue *q); // Wait for the first finished request, NULL if no more
53 void asio_put(struct asio_request *r); // Return a finished request for recycling
54 struct asio_request *asio_get_bg(struct asio_queue *q); // Get and if there are no free requests, wait for background writes to finish
55 void asio_sync(struct asio_queue *q); // Wait for all requests to finish
57 #endif /* !_UCW_ASYNCIO_H */