… | |
… | |
43 | #ifdef __cplusplus |
43 | #ifdef __cplusplus |
44 | extern "C" { |
44 | extern "C" { |
45 | #endif |
45 | #endif |
46 | |
46 | |
47 | #include <stddef.h> |
47 | #include <stddef.h> |
|
|
48 | #include <signal.h> |
48 | #include <sys/types.h> |
49 | #include <sys/types.h> |
49 | |
50 | |
50 | typedef struct eio_req eio_req; |
51 | typedef struct eio_req eio_req; |
51 | typedef struct eio_dirent eio_dirent; |
52 | typedef struct eio_dirent eio_dirent; |
52 | |
53 | |
… | |
… | |
152 | EIO_SYNC, EIO_FSYNC, EIO_FDATASYNC, |
153 | EIO_SYNC, EIO_FSYNC, EIO_FDATASYNC, |
153 | EIO_MSYNC, EIO_MTOUCH, EIO_SYNC_FILE_RANGE, |
154 | EIO_MSYNC, EIO_MTOUCH, EIO_SYNC_FILE_RANGE, |
154 | EIO_MLOCK, EIO_MLOCKALL, |
155 | EIO_MLOCK, EIO_MLOCKALL, |
155 | EIO_UNLINK, EIO_RMDIR, EIO_MKDIR, EIO_RENAME, |
156 | EIO_UNLINK, EIO_RMDIR, EIO_MKDIR, EIO_RENAME, |
156 | EIO_MKNOD, EIO_READDIR, |
157 | EIO_MKNOD, EIO_READDIR, |
157 | EIO_LINK, EIO_SYMLINK, EIO_READLINK, |
158 | EIO_LINK, EIO_SYMLINK, EIO_READLINK, EIO_REALPATH, |
158 | EIO_GROUP, EIO_NOP, |
159 | EIO_GROUP, EIO_NOP, |
159 | EIO_BUSY |
160 | EIO_BUSY |
160 | }; |
161 | }; |
161 | |
162 | |
162 | /* mlockall constants */ |
163 | /* mlockall constants */ |
… | |
… | |
193 | int int1; /* all applicable requests: file descriptor; sendfile: output fd; open, msync, mlockall, readdir: flags */ |
194 | int int1; /* all applicable requests: file descriptor; sendfile: output fd; open, msync, mlockall, readdir: flags */ |
194 | long int2; /* chown, fchown: uid; sendfile: input fd; open, chmod, mkdir, mknod: file mode, sync_file_range: flags */ |
195 | long int2; /* chown, fchown: uid; sendfile: input fd; open, chmod, mkdir, mknod: file mode, sync_file_range: flags */ |
195 | long int3; /* chown, fchown: gid */ |
196 | long int3; /* chown, fchown: gid */ |
196 | int errorno; /* errno value on syscall return */ |
197 | int errorno; /* errno value on syscall return */ |
197 | |
198 | |
|
|
199 | #if __i386 || __amd64 |
|
|
200 | unsigned char cancelled; |
|
|
201 | #else |
|
|
202 | sig_atomic_t cancelled; |
|
|
203 | #endif |
|
|
204 | |
198 | unsigned char flags; /* private */ |
205 | unsigned char flags; /* private */ |
199 | signed char pri; /* the priority */ |
206 | signed char pri; /* the priority */ |
200 | |
207 | |
201 | void *data; |
208 | void *data; |
202 | eio_cb finish; |
209 | eio_cb finish; |
203 | void (*destroy)(eio_req *req); /* called when requets no longer needed */ |
210 | void (*destroy)(eio_req *req); /* called when request no longer needed */ |
204 | void (*feed)(eio_req *req); /* only used for group requests */ |
211 | void (*feed)(eio_req *req); /* only used for group requests */ |
205 | |
212 | |
206 | EIO_REQ_MEMBERS |
213 | EIO_REQ_MEMBERS |
207 | |
214 | |
208 | eio_req *grp, *grp_prev, *grp_next, *grp_first; /* private */ |
215 | eio_req *grp, *grp_prev, *grp_next, *grp_first; /* private */ |
209 | }; |
216 | }; |
210 | |
217 | |
211 | /* _private_ request flags */ |
218 | /* _private_ request flags */ |
212 | enum { |
219 | enum { |
213 | EIO_FLAG_CANCELLED = 0x01, /* request was cancelled */ |
|
|
214 | EIO_FLAG_PTR1_FREE = 0x02, /* need to free(ptr1) */ |
220 | EIO_FLAG_PTR1_FREE = 0x01, /* need to free(ptr1) */ |
215 | EIO_FLAG_PTR2_FREE = 0x04, /* need to free(ptr2) */ |
221 | EIO_FLAG_PTR2_FREE = 0x02, /* need to free(ptr2) */ |
216 | EIO_FLAG_GROUPADD = 0x08 /* some request was added to the group */ |
222 | EIO_FLAG_GROUPADD = 0x04 /* some request was added to the group */ |
217 | }; |
223 | }; |
218 | |
224 | |
219 | /* undocumented/unsupported/private helper */ |
225 | /* undocumented/unsupported/private helper */ |
220 | /*void eio_page_align (void **addr, size_t *length);*/ |
226 | /*void eio_page_align (void **addr, size_t *length);*/ |
221 | |
227 | |
… | |
… | |
239 | * maximum wanted number |
245 | * maximum wanted number |
240 | * or maximum idle number of threads */ |
246 | * or maximum idle number of threads */ |
241 | void eio_set_min_parallel (unsigned int nthreads); |
247 | void eio_set_min_parallel (unsigned int nthreads); |
242 | void eio_set_max_parallel (unsigned int nthreads); |
248 | void eio_set_max_parallel (unsigned int nthreads); |
243 | void eio_set_max_idle (unsigned int nthreads); |
249 | void eio_set_max_idle (unsigned int nthreads); |
|
|
250 | void eio_set_idle_timeout (unsigned int seconds); |
244 | |
251 | |
245 | unsigned int eio_nreqs (void); /* number of requests in-flight */ |
252 | unsigned int eio_nreqs (void); /* number of requests in-flight */ |
246 | unsigned int eio_nready (void); /* number of not-yet handled requests */ |
253 | unsigned int eio_nready (void); /* number of not-yet handled requests */ |
247 | unsigned int eio_npending (void); /* numbe rof finished but unhandled requests */ |
254 | unsigned int eio_npending (void); /* numbe rof finished but unhandled requests */ |
248 | unsigned int eio_nthreads (void); /* number of worker threads in use currently */ |
255 | unsigned int eio_nthreads (void); /* number of worker threads in use currently */ |
249 | |
256 | |
250 | /*****************************************************************************/ |
257 | /*****************************************************************************/ |
251 | /* convinience wrappers */ |
258 | /* convenience wrappers */ |
252 | |
259 | |
253 | #ifndef EIO_NO_WRAPPERS |
260 | #ifndef EIO_NO_WRAPPERS |
254 | eio_req *eio_nop (int pri, eio_cb cb, void *data); /* does nothing except go through the whole process */ |
261 | eio_req *eio_nop (int pri, eio_cb cb, void *data); /* does nothing except go through the whole process */ |
255 | eio_req *eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data); /* ties a thread for this long, simulating busyness */ |
262 | eio_req *eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data); /* ties a thread for this long, simulating busyness */ |
256 | eio_req *eio_sync (int pri, eio_cb cb, void *data); |
263 | eio_req *eio_sync (int pri, eio_cb cb, void *data); |
… | |
… | |
281 | eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data); |
288 | eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data); |
282 | eio_req *eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ |
289 | eio_req *eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ |
283 | eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data); |
290 | eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data); |
284 | eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data); |
291 | eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data); |
285 | eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ |
292 | eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ |
|
|
293 | eio_req *eio_realpath (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ |
286 | eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ |
294 | eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ |
287 | eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ |
295 | eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ |
288 | eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ |
296 | eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ |
289 | eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data); |
297 | eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data); |
290 | eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data); |
298 | eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data); |
291 | eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data); |
299 | eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data); |
292 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data); |
300 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data); |
293 | eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data); |
301 | eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data); |
294 | #endif |
302 | #endif |
295 | |
303 | |
296 | /*****************************************************************************/ |
304 | /*****************************************************************************/ |
297 | /* groups */ |
305 | /* groups */ |
298 | |
306 | |
… | |
… | |
304 | |
312 | |
305 | /*****************************************************************************/ |
313 | /*****************************************************************************/ |
306 | /* request api */ |
314 | /* request api */ |
307 | |
315 | |
308 | /* true if the request was cancelled, useful in the invoke callback */ |
316 | /* true if the request was cancelled, useful in the invoke callback */ |
309 | #define EIO_CANCELLED(req) ((req)->flags & EIO_FLAG_CANCELLED) |
317 | #define EIO_CANCELLED(req) ((req)->cancelled) |
310 | |
318 | |
311 | #define EIO_RESULT(req) ((req)->result) |
319 | #define EIO_RESULT(req) ((req)->result) |
312 | /* returns a pointer to the result buffer allocated by eio */ |
320 | /* returns a pointer to the result buffer allocated by eio */ |
313 | #define EIO_BUF(req) ((req)->ptr2) |
321 | #define EIO_BUF(req) ((req)->ptr2) |
314 | #define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) |
322 | #define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) |
… | |
… | |
317 | |
325 | |
318 | /* submit a request for execution */ |
326 | /* submit a request for execution */ |
319 | void eio_submit (eio_req *req); |
327 | void eio_submit (eio_req *req); |
320 | /* cancel a request as soon fast as possible, if possible */ |
328 | /* cancel a request as soon fast as possible, if possible */ |
321 | void eio_cancel (eio_req *req); |
329 | void eio_cancel (eio_req *req); |
322 | /* destroy a request that has never been submitted */ |
|
|
323 | void eio_destroy (eio_req *req); |
|
|
324 | |
330 | |
325 | /*****************************************************************************/ |
331 | /*****************************************************************************/ |
326 | /* convinience functions */ |
332 | /* convenience functions */ |
327 | |
333 | |
328 | ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count); |
334 | ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count); |
329 | |
335 | |
330 | #ifdef __cplusplus |
336 | #ifdef __cplusplus |
331 | } |
337 | } |