aio_misc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /* Handle general operations.
  2. Copyright (C) 1997-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <aio.h>
  17. #include <assert.h>
  18. #include <errno.h>
  19. #include <limits.h>
  20. #include <pthread.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <sys/param.h>
  24. #include <sys/stat.h>
  25. #include <sys/time.h>
  26. #include <aio_misc.h>
  27. #ifndef aio_create_helper_thread
  28. # define aio_create_helper_thread __aio_create_helper_thread
  29. extern inline int
  30. __aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *), void *arg)
  31. {
  32. pthread_attr_t attr;
  33. /* Make sure the thread is created detached. */
  34. pthread_attr_init (&attr);
  35. pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
  36. int ret = pthread_create (threadp, &attr, tf, arg);
  37. (void) pthread_attr_destroy (&attr);
  38. return ret;
  39. }
  40. #endif
  41. static void add_request_to_runlist (struct requestlist *newrequest);
  42. /* Pool of request list entries. */
  43. static struct requestlist **pool;
  44. /* Number of total and allocated pool entries. */
  45. static size_t pool_max_size;
  46. static size_t pool_size;
  47. /* We implement a two dimensional array but allocate each row separately.
  48. The macro below determines how many entries should be used per row.
  49. It should better be a power of two. */
  50. #define ENTRIES_PER_ROW 32
  51. /* How many rows we allocate at once. */
  52. #define ROWS_STEP 8
  53. /* List of available entries. */
  54. static struct requestlist *freelist;
  55. /* List of request waiting to be processed. */
  56. static struct requestlist *runlist;
  57. /* Structure list of all currently processed requests. */
  58. static struct requestlist *requests;
  59. /* Number of threads currently running. */
  60. static int nthreads;
  61. /* Number of threads waiting for work to arrive. */
  62. static int idle_thread_count;
  63. /* These are the values used to optimize the use of AIO. The user can
  64. overwrite them by using the `aio_init' function. */
  65. static struct aioinit optim =
  66. {
  67. 20, /* int aio_threads; Maximal number of threads. */
  68. 64, /* int aio_num; Number of expected simultaneous requests. */
  69. 0,
  70. 0,
  71. 0,
  72. 0,
  73. 1,
  74. 0
  75. };
  76. /* Since the list is global we need a mutex protecting it. */
  77. pthread_mutex_t __aio_requests_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
  78. /* When you add a request to the list and there are idle threads present,
  79. you signal this condition variable. When a thread finishes work, it waits
  80. on this condition variable for a time before it actually exits. */
  81. pthread_cond_t __aio_new_request_notification = PTHREAD_COND_INITIALIZER;
  82. /* Functions to handle request list pool. */
  83. static struct requestlist *
  84. get_elem (void)
  85. {
  86. struct requestlist *result;
  87. if (freelist == NULL)
  88. {
  89. struct requestlist *new_row;
  90. int cnt;
  91. assert (sizeof (struct aiocb) == sizeof (struct aiocb64));
  92. if (pool_size + 1 >= pool_max_size)
  93. {
  94. size_t new_max_size = pool_max_size + ROWS_STEP;
  95. struct requestlist **new_tab;
  96. new_tab = (struct requestlist **)
  97. realloc (pool, new_max_size * sizeof (struct requestlist *));
  98. if (new_tab == NULL)
  99. return NULL;
  100. pool_max_size = new_max_size;
  101. pool = new_tab;
  102. }
  103. /* Allocate the new row. */
  104. cnt = pool_size == 0 ? optim.aio_num : ENTRIES_PER_ROW;
  105. new_row = (struct requestlist *) calloc (cnt,
  106. sizeof (struct requestlist));
  107. if (new_row == NULL)
  108. return NULL;
  109. pool[pool_size++] = new_row;
  110. /* Put all the new entries in the freelist. */
  111. do
  112. {
  113. new_row->next_prio = freelist;
  114. freelist = new_row++;
  115. }
  116. while (--cnt > 0);
  117. }
  118. result = freelist;
  119. freelist = freelist->next_prio;
  120. return result;
  121. }
  122. void
  123. __aio_free_request (struct requestlist *elem)
  124. {
  125. elem->running = no;
  126. elem->next_prio = freelist;
  127. freelist = elem;
  128. }
  129. struct requestlist *
  130. __aio_find_req (aiocb_union *elem)
  131. {
  132. struct requestlist *runp = requests;
  133. int fildes = elem->aiocb.aio_fildes;
  134. while (runp != NULL && runp->aiocbp->aiocb.aio_fildes < fildes)
  135. runp = runp->next_fd;
  136. if (runp != NULL)
  137. {
  138. if (runp->aiocbp->aiocb.aio_fildes != fildes)
  139. runp = NULL;
  140. else
  141. while (runp != NULL && runp->aiocbp != elem)
  142. runp = runp->next_prio;
  143. }
  144. return runp;
  145. }
  146. struct requestlist *
  147. __aio_find_req_fd (int fildes)
  148. {
  149. struct requestlist *runp = requests;
  150. while (runp != NULL && runp->aiocbp->aiocb.aio_fildes < fildes)
  151. runp = runp->next_fd;
  152. return (runp != NULL && runp->aiocbp->aiocb.aio_fildes == fildes
  153. ? runp : NULL);
  154. }
  155. void
  156. __aio_remove_request (struct requestlist *last, struct requestlist *req,
  157. int all)
  158. {
  159. assert (req->running == yes || req->running == queued
  160. || req->running == done);
  161. if (last != NULL)
  162. last->next_prio = all ? NULL : req->next_prio;
  163. else
  164. {
  165. if (all || req->next_prio == NULL)
  166. {
  167. if (req->last_fd != NULL)
  168. req->last_fd->next_fd = req->next_fd;
  169. else
  170. requests = req->next_fd;
  171. if (req->next_fd != NULL)
  172. req->next_fd->last_fd = req->last_fd;
  173. }
  174. else
  175. {
  176. if (req->last_fd != NULL)
  177. req->last_fd->next_fd = req->next_prio;
  178. else
  179. requests = req->next_prio;
  180. if (req->next_fd != NULL)
  181. req->next_fd->last_fd = req->next_prio;
  182. req->next_prio->last_fd = req->last_fd;
  183. req->next_prio->next_fd = req->next_fd;
  184. /* Mark this entry as runnable. */
  185. req->next_prio->running = yes;
  186. }
  187. if (req->running == yes)
  188. {
  189. struct requestlist *runp = runlist;
  190. last = NULL;
  191. while (runp != NULL)
  192. {
  193. if (runp == req)
  194. {
  195. if (last == NULL)
  196. runlist = runp->next_run;
  197. else
  198. last->next_run = runp->next_run;
  199. break;
  200. }
  201. last = runp;
  202. runp = runp->next_run;
  203. }
  204. }
  205. }
  206. }
  207. /* The thread handler. */
  208. static void *handle_fildes_io (void *arg);
  209. /* User optimization. */
  210. void
  211. __aio_init (const struct aioinit *init)
  212. {
  213. /* Get the mutex. */
  214. pthread_mutex_lock (&__aio_requests_mutex);
  215. /* Only allow writing new values if the table is not yet allocated. */
  216. if (pool == NULL)
  217. {
  218. optim.aio_threads = init->aio_threads < 1 ? 1 : init->aio_threads;
  219. assert (powerof2 (ENTRIES_PER_ROW));
  220. optim.aio_num = (init->aio_num < ENTRIES_PER_ROW
  221. ? ENTRIES_PER_ROW
  222. : init->aio_num & ~(ENTRIES_PER_ROW - 1));
  223. }
  224. if (init->aio_idle_time != 0)
  225. optim.aio_idle_time = init->aio_idle_time;
  226. /* Release the mutex. */
  227. pthread_mutex_unlock (&__aio_requests_mutex);
  228. }
  229. weak_alias (__aio_init, aio_init)
  230. /* The main function of the async I/O handling. It enqueues requests
  231. and if necessary starts and handles threads. */
  232. struct requestlist *
  233. __aio_enqueue_request (aiocb_union *aiocbp, int operation)
  234. {
  235. int result = 0;
  236. int policy, prio;
  237. struct sched_param param;
  238. struct requestlist *last, *runp, *newp;
  239. int running = no;
  240. if (operation == LIO_SYNC || operation == LIO_DSYNC)
  241. aiocbp->aiocb.aio_reqprio = 0;
  242. else if (aiocbp->aiocb.aio_reqprio < 0
  243. #ifdef AIO_PRIO_DELTA_MAX
  244. || aiocbp->aiocb.aio_reqprio > AIO_PRIO_DELTA_MAX
  245. #endif
  246. )
  247. {
  248. /* Invalid priority value. */
  249. __set_errno (EINVAL);
  250. aiocbp->aiocb.__error_code = EINVAL;
  251. aiocbp->aiocb.__return_value = -1;
  252. return NULL;
  253. }
  254. /* Compute priority for this request. */
  255. pthread_getschedparam (pthread_self (), &policy, &param);
  256. prio = param.sched_priority - aiocbp->aiocb.aio_reqprio;
  257. /* Get the mutex. */
  258. pthread_mutex_lock (&__aio_requests_mutex);
  259. last = NULL;
  260. runp = requests;
  261. /* First look whether the current file descriptor is currently
  262. worked with. */
  263. while (runp != NULL
  264. && runp->aiocbp->aiocb.aio_fildes < aiocbp->aiocb.aio_fildes)
  265. {
  266. last = runp;
  267. runp = runp->next_fd;
  268. }
  269. /* Get a new element for the waiting list. */
  270. newp = get_elem ();
  271. if (newp == NULL)
  272. {
  273. pthread_mutex_unlock (&__aio_requests_mutex);
  274. __set_errno (EAGAIN);
  275. return NULL;
  276. }
  277. newp->aiocbp = aiocbp;
  278. newp->waiting = NULL;
  279. aiocbp->aiocb.__abs_prio = prio;
  280. aiocbp->aiocb.__policy = policy;
  281. aiocbp->aiocb.aio_lio_opcode = operation;
  282. aiocbp->aiocb.__error_code = EINPROGRESS;
  283. aiocbp->aiocb.__return_value = 0;
  284. if (runp != NULL
  285. && runp->aiocbp->aiocb.aio_fildes == aiocbp->aiocb.aio_fildes)
  286. {
  287. /* The current file descriptor is worked on. It makes no sense
  288. to start another thread since this new thread would fight
  289. with the running thread for the resources. But we also cannot
  290. say that the thread processing this desriptor shall immediately
  291. after finishing the current job process this request if there
  292. are other threads in the running queue which have a higher
  293. priority. */
  294. /* Simply enqueue it after the running one according to the
  295. priority. */
  296. last = NULL;
  297. while (runp->next_prio != NULL
  298. && runp->next_prio->aiocbp->aiocb.__abs_prio >= prio)
  299. {
  300. last = runp;
  301. runp = runp->next_prio;
  302. }
  303. newp->next_prio = runp->next_prio;
  304. runp->next_prio = newp;
  305. running = queued;
  306. }
  307. else
  308. {
  309. running = yes;
  310. /* Enqueue this request for a new descriptor. */
  311. if (last == NULL)
  312. {
  313. newp->last_fd = NULL;
  314. newp->next_fd = requests;
  315. if (requests != NULL)
  316. requests->last_fd = newp;
  317. requests = newp;
  318. }
  319. else
  320. {
  321. newp->next_fd = last->next_fd;
  322. newp->last_fd = last;
  323. last->next_fd = newp;
  324. if (newp->next_fd != NULL)
  325. newp->next_fd->last_fd = newp;
  326. }
  327. newp->next_prio = NULL;
  328. last = NULL;
  329. }
  330. if (running == yes)
  331. {
  332. /* We try to create a new thread for this file descriptor. The
  333. function which gets called will handle all available requests
  334. for this descriptor and when all are processed it will
  335. terminate.
  336. If no new thread can be created or if the specified limit of
  337. threads for AIO is reached we queue the request. */
  338. /* See if we need to and are able to create a thread. */
  339. if (nthreads < optim.aio_threads && idle_thread_count == 0)
  340. {
  341. pthread_t thid;
  342. running = newp->running = allocated;
  343. /* Now try to start a thread. */
  344. result = aio_create_helper_thread (&thid, handle_fildes_io, newp);
  345. if (result == 0)
  346. /* We managed to enqueue the request. All errors which can
  347. happen now can be recognized by calls to `aio_return' and
  348. `aio_error'. */
  349. ++nthreads;
  350. else
  351. {
  352. /* Reset the running flag. The new request is not running. */
  353. running = newp->running = yes;
  354. if (nthreads == 0)
  355. {
  356. /* We cannot create a thread in the moment and there is
  357. also no thread running. This is a problem. `errno' is
  358. set to EAGAIN if this is only a temporary problem. */
  359. __aio_remove_request (last, newp, 0);
  360. }
  361. else
  362. result = 0;
  363. }
  364. }
  365. }
  366. /* Enqueue the request in the run queue if it is not yet running. */
  367. if (running == yes && result == 0)
  368. {
  369. add_request_to_runlist (newp);
  370. /* If there is a thread waiting for work, then let it know that we
  371. have just given it something to do. */
  372. if (idle_thread_count > 0)
  373. pthread_cond_signal (&__aio_new_request_notification);
  374. }
  375. if (result == 0)
  376. newp->running = running;
  377. else
  378. {
  379. /* Something went wrong. */
  380. __aio_free_request (newp);
  381. aiocbp->aiocb.__error_code = result;
  382. __set_errno (result);
  383. newp = NULL;
  384. }
  385. /* Release the mutex. */
  386. pthread_mutex_unlock (&__aio_requests_mutex);
  387. return newp;
  388. }
  389. static void *
  390. handle_fildes_io (void *arg)
  391. {
  392. pthread_t self = pthread_self ();
  393. struct sched_param param;
  394. struct requestlist *runp = (struct requestlist *) arg;
  395. aiocb_union *aiocbp;
  396. int policy;
  397. int fildes;
  398. pthread_getschedparam (self, &policy, &param);
  399. do
  400. {
  401. /* If runp is NULL, then we were created to service the work queue
  402. in general, not to handle any particular request. In that case we
  403. skip the "do work" stuff on the first pass, and go directly to the
  404. "get work off the work queue" part of this loop, which is near the
  405. end. */
  406. if (runp == NULL)
  407. pthread_mutex_lock (&__aio_requests_mutex);
  408. else
  409. {
  410. /* Hopefully this request is marked as running. */
  411. assert (runp->running == allocated);
  412. /* Update our variables. */
  413. aiocbp = runp->aiocbp;
  414. fildes = aiocbp->aiocb.aio_fildes;
  415. /* Change the priority to the requested value (if necessary). */
  416. if (aiocbp->aiocb.__abs_prio != param.sched_priority
  417. || aiocbp->aiocb.__policy != policy)
  418. {
  419. param.sched_priority = aiocbp->aiocb.__abs_prio;
  420. policy = aiocbp->aiocb.__policy;
  421. pthread_setschedparam (self, policy, &param);
  422. }
  423. /* Process request pointed to by RUNP. We must not be disturbed
  424. by signals. */
  425. if ((aiocbp->aiocb.aio_lio_opcode & 127) == LIO_READ)
  426. {
  427. if (sizeof (off_t) != sizeof (off64_t)
  428. && aiocbp->aiocb.aio_lio_opcode & 128)
  429. aiocbp->aiocb.__return_value =
  430. TEMP_FAILURE_RETRY (__pread64 (fildes, (void *)
  431. aiocbp->aiocb64.aio_buf,
  432. aiocbp->aiocb64.aio_nbytes,
  433. aiocbp->aiocb64.aio_offset));
  434. else
  435. aiocbp->aiocb.__return_value =
  436. TEMP_FAILURE_RETRY (__libc_pread (fildes,
  437. (void *)
  438. aiocbp->aiocb.aio_buf,
  439. aiocbp->aiocb.aio_nbytes,
  440. aiocbp->aiocb.aio_offset));
  441. if (aiocbp->aiocb.__return_value == -1 && errno == ESPIPE)
  442. /* The Linux kernel is different from others. It returns
  443. ESPIPE if using pread on a socket. Other platforms
  444. simply ignore the offset parameter and behave like
  445. read. */
  446. aiocbp->aiocb.__return_value =
  447. TEMP_FAILURE_RETRY (read (fildes,
  448. (void *) aiocbp->aiocb64.aio_buf,
  449. aiocbp->aiocb64.aio_nbytes));
  450. }
  451. else if ((aiocbp->aiocb.aio_lio_opcode & 127) == LIO_WRITE)
  452. {
  453. if (sizeof (off_t) != sizeof (off64_t)
  454. && aiocbp->aiocb.aio_lio_opcode & 128)
  455. aiocbp->aiocb.__return_value =
  456. TEMP_FAILURE_RETRY (__pwrite64 (fildes, (const void *)
  457. aiocbp->aiocb64.aio_buf,
  458. aiocbp->aiocb64.aio_nbytes,
  459. aiocbp->aiocb64.aio_offset));
  460. else
  461. aiocbp->aiocb.__return_value =
  462. TEMP_FAILURE_RETRY (__libc_pwrite (fildes, (const void *)
  463. aiocbp->aiocb.aio_buf,
  464. aiocbp->aiocb.aio_nbytes,
  465. aiocbp->aiocb.aio_offset));
  466. if (aiocbp->aiocb.__return_value == -1 && errno == ESPIPE)
  467. /* The Linux kernel is different from others. It returns
  468. ESPIPE if using pwrite on a socket. Other platforms
  469. simply ignore the offset parameter and behave like
  470. write. */
  471. aiocbp->aiocb.__return_value =
  472. TEMP_FAILURE_RETRY (write (fildes,
  473. (void *) aiocbp->aiocb64.aio_buf,
  474. aiocbp->aiocb64.aio_nbytes));
  475. }
  476. else if (aiocbp->aiocb.aio_lio_opcode == LIO_DSYNC)
  477. aiocbp->aiocb.__return_value =
  478. TEMP_FAILURE_RETRY (fdatasync (fildes));
  479. else if (aiocbp->aiocb.aio_lio_opcode == LIO_SYNC)
  480. aiocbp->aiocb.__return_value =
  481. TEMP_FAILURE_RETRY (fsync (fildes));
  482. else
  483. {
  484. /* This is an invalid opcode. */
  485. aiocbp->aiocb.__return_value = -1;
  486. __set_errno (EINVAL);
  487. }
  488. /* Get the mutex. */
  489. pthread_mutex_lock (&__aio_requests_mutex);
  490. if (aiocbp->aiocb.__return_value == -1)
  491. aiocbp->aiocb.__error_code = errno;
  492. else
  493. aiocbp->aiocb.__error_code = 0;
  494. /* Send the signal to notify about finished processing of the
  495. request. */
  496. __aio_notify (runp);
  497. /* For debugging purposes we reset the running flag of the
  498. finished request. */
  499. assert (runp->running == allocated);
  500. runp->running = done;
  501. /* Now dequeue the current request. */
  502. __aio_remove_request (NULL, runp, 0);
  503. if (runp->next_prio != NULL)
  504. add_request_to_runlist (runp->next_prio);
  505. /* Free the old element. */
  506. __aio_free_request (runp);
  507. }
  508. runp = runlist;
  509. /* If the runlist is empty, then we sleep for a while, waiting for
  510. something to arrive in it. */
  511. if (runp == NULL && optim.aio_idle_time >= 0)
  512. {
  513. struct timeval now;
  514. struct timespec wakeup_time;
  515. ++idle_thread_count;
  516. __gettimeofday (&now, NULL);
  517. wakeup_time.tv_sec = now.tv_sec + optim.aio_idle_time;
  518. wakeup_time.tv_nsec = now.tv_usec * 1000;
  519. if (wakeup_time.tv_nsec >= 1000000000)
  520. {
  521. wakeup_time.tv_nsec -= 1000000000;
  522. ++wakeup_time.tv_sec;
  523. }
  524. pthread_cond_timedwait (&__aio_new_request_notification,
  525. &__aio_requests_mutex,
  526. &wakeup_time);
  527. --idle_thread_count;
  528. runp = runlist;
  529. }
  530. if (runp == NULL)
  531. --nthreads;
  532. else
  533. {
  534. assert (runp->running == yes);
  535. runp->running = allocated;
  536. runlist = runp->next_run;
  537. /* If we have a request to process, and there's still another in
  538. the run list, then we need to either wake up or create a new
  539. thread to service the request that is still in the run list. */
  540. if (runlist != NULL)
  541. {
  542. /* There are at least two items in the work queue to work on.
  543. If there are other idle threads, then we should wake them
  544. up for these other work elements; otherwise, we should try
  545. to create a new thread. */
  546. if (idle_thread_count > 0)
  547. pthread_cond_signal (&__aio_new_request_notification);
  548. else if (nthreads < optim.aio_threads)
  549. {
  550. pthread_t thid;
  551. pthread_attr_t attr;
  552. /* Make sure the thread is created detached. */
  553. pthread_attr_init (&attr);
  554. pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
  555. /* Now try to start a thread. If we fail, no big deal,
  556. because we know that there is at least one thread (us)
  557. that is working on AIO operations. */
  558. if (pthread_create (&thid, &attr, handle_fildes_io, NULL)
  559. == 0)
  560. ++nthreads;
  561. }
  562. }
  563. }
  564. /* Release the mutex. */
  565. pthread_mutex_unlock (&__aio_requests_mutex);
  566. }
  567. while (runp != NULL);
  568. return NULL;
  569. }
  570. /* Free allocated resources. */
  571. libc_freeres_fn (free_res)
  572. {
  573. size_t row;
  574. for (row = 0; row < pool_max_size; ++row)
  575. free (pool[row]);
  576. free (pool);
  577. }
  578. /* Add newrequest to the runlist. The __abs_prio flag of newrequest must
  579. be correctly set to do this. Also, you had better set newrequest's
  580. "running" flag to "yes" before you release your lock or you'll throw an
  581. assertion. */
  582. static void
  583. add_request_to_runlist (struct requestlist *newrequest)
  584. {
  585. int prio = newrequest->aiocbp->aiocb.__abs_prio;
  586. struct requestlist *runp;
  587. if (runlist == NULL || runlist->aiocbp->aiocb.__abs_prio < prio)
  588. {
  589. newrequest->next_run = runlist;
  590. runlist = newrequest;
  591. }
  592. else
  593. {
  594. runp = runlist;
  595. while (runp->next_run != NULL
  596. && runp->next_run->aiocbp->aiocb.__abs_prio >= prio)
  597. runp = runp->next_run;
  598. newrequest->next_run = runp->next_run;
  599. runp->next_run = newrequest;
  600. }
  601. }