2 * DEBUG: section 43 Windows AIOPS
3 * AUTHOR: Stewart Forster <slf@connect.com.au>
4 * AUTHOR: Robert Collins <robertc@squid-cache.org>
5 * AUTHOR: Guido Serassio <serassio@squid-cache.org>
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36 #include "squid_windows.h"
37 #include "DiskIO/DiskThreads/CommIO.h"
38 #include "DiskThreads.h"
39 #include "SquidTime.h"
49 #define RIDICULOUS_LENGTH 4096
51 enum _squidaio_thread_status
{
58 typedef enum _squidaio_thread_status squidaio_thread_status
;
60 typedef struct squidaio_request_t
{
62 struct squidaio_request_t
*next
;
63 squidaio_request_type request_type
;
77 struct stat
*tmpstatp
;
80 squidaio_result_t
*resultp
;
83 typedef struct squidaio_request_queue_t
{
85 HANDLE cond
; /* See Event objects */
86 squidaio_request_t
*volatile head
;
87 squidaio_request_t
*volatile *volatile tailp
;
88 unsigned long requests
;
89 unsigned long blocked
; /* main failed to lock the queue */
90 } squidaio_request_queue_t
;
92 typedef struct squidaio_thread_t squidaio_thread_t
;
94 struct squidaio_thread_t
{
95 squidaio_thread_t
*next
;
97 DWORD dwThreadId
; /* thread ID */
98 squidaio_thread_status status
;
100 struct squidaio_request_t
*current_req
;
101 unsigned long requests
;
105 static void squidaio_queue_request(squidaio_request_t
*);
106 static void squidaio_cleanup_request(squidaio_request_t
*);
107 static DWORD WINAPI
squidaio_thread_loop( LPVOID lpParam
);
108 static void squidaio_do_open(squidaio_request_t
*);
109 static void squidaio_do_read(squidaio_request_t
*);
110 static void squidaio_do_write(squidaio_request_t
*);
111 static void squidaio_do_close(squidaio_request_t
*);
112 static void squidaio_do_stat(squidaio_request_t
*);
113 static void squidaio_do_unlink(squidaio_request_t
*);
115 static void *squidaio_do_opendir(squidaio_request_t
*);
117 static void squidaio_debug(squidaio_request_t
*);
118 static void squidaio_poll_queues(void);
120 static squidaio_thread_t
*threads
= NULL
;
121 static int squidaio_initialised
= 0;
123 #define AIO_LARGE_BUFS 16384
124 #define AIO_MEDIUM_BUFS AIO_LARGE_BUFS >> 1
125 #define AIO_SMALL_BUFS AIO_LARGE_BUFS >> 2
126 #define AIO_TINY_BUFS AIO_LARGE_BUFS >> 3
127 #define AIO_MICRO_BUFS 128
129 static MemAllocator
*squidaio_large_bufs
= NULL
; /* 16K */
130 static MemAllocator
*squidaio_medium_bufs
= NULL
; /* 8K */
131 static MemAllocator
*squidaio_small_bufs
= NULL
; /* 4K */
132 static MemAllocator
*squidaio_tiny_bufs
= NULL
; /* 2K */
133 static MemAllocator
*squidaio_micro_bufs
= NULL
; /* 128K */
135 static int request_queue_len
= 0;
136 static MemAllocator
*squidaio_request_pool
= NULL
;
137 static MemAllocator
*squidaio_thread_pool
= NULL
;
138 static squidaio_request_queue_t request_queue
;
141 squidaio_request_t
*head
, **tailp
;
146 NULL
, &request_queue2
.head
148 static squidaio_request_queue_t done_queue
;
151 squidaio_request_t
*head
, **tailp
;
156 NULL
, &done_requests
.head
159 static HANDLE main_thread
;
161 static MemAllocator
*
162 squidaio_get_pool(int size
)
164 if (size
<= AIO_LARGE_BUFS
) {
165 if (size
<= AIO_MICRO_BUFS
)
166 return squidaio_micro_bufs
;
167 else if (size
<= AIO_TINY_BUFS
)
168 return squidaio_tiny_bufs
;
169 else if (size
<= AIO_SMALL_BUFS
)
170 return squidaio_small_bufs
;
171 else if (size
<= AIO_MEDIUM_BUFS
)
172 return squidaio_medium_bufs
;
174 return squidaio_large_bufs
;
181 squidaio_xmalloc(int size
)
186 if ((pool
= squidaio_get_pool(size
)) != NULL
) {
195 squidaio_xstrdup(const char *str
)
198 int len
= strlen(str
) + 1;
200 p
= (char *)squidaio_xmalloc(len
);
201 strncpy(p
, str
, len
);
207 squidaio_xfree(void *p
, int size
)
211 if ((pool
= squidaio_get_pool(size
)) != NULL
) {
218 squidaio_xstrfree(char *str
)
221 int len
= strlen(str
) + 1;
223 if ((pool
= squidaio_get_pool(len
)) != NULL
) {
233 squidaio_thread_t
*threadp
;
235 if (squidaio_initialised
)
238 if (!DuplicateHandle(GetCurrentProcess(), /* pseudo handle, don't close */
239 GetCurrentThread(), /* pseudo handle to copy */
240 GetCurrentProcess(), /* pseudo handle, don't close */
242 0, /* required access */
243 FALSE
, /* child process's don't inherit the handle */
244 DUPLICATE_SAME_ACCESS
)) {
246 fatal("Couldn't get current thread handle");
249 /* Initialize request queue */
250 if ((request_queue
.mutex
= CreateMutex(NULL
, /* no inheritance */
251 FALSE
, /* start unowned (as per mutex_init) */
254 fatal("Failed to create mutex");
257 if ((request_queue
.cond
= CreateEvent(NULL
, /* no inheritance */
258 FALSE
, /* auto signal reset - which I think is pthreads like ? */
259 FALSE
, /* start non signaled */
262 fatal("Failed to create condition variable");
265 request_queue
.head
= NULL
;
267 request_queue
.tailp
= &request_queue
.head
;
269 request_queue
.requests
= 0;
271 request_queue
.blocked
= 0;
273 /* Initialize done queue */
275 if ((done_queue
.mutex
= CreateMutex(NULL
, /* no inheritance */
276 FALSE
, /* start unowned (as per mutex_init) */
279 fatal("Failed to create mutex");
282 if ((done_queue
.cond
= CreateEvent(NULL
, /* no inheritance */
283 TRUE
, /* manually signaled - which I think is pthreads like ? */
284 FALSE
, /* start non signaled */
287 fatal("Failed to create condition variable");
290 done_queue
.head
= NULL
;
292 done_queue
.tailp
= &done_queue
.head
;
294 done_queue
.requests
= 0;
296 done_queue
.blocked
= 0;
298 CommIO::NotifyIOCompleted();
300 /* Create threads and get them to sit in their wait loop */
301 squidaio_thread_pool
= memPoolCreate("aio_thread", sizeof(squidaio_thread_t
));
305 for (i
= 0; i
< NUMTHREADS
; ++i
) {
306 threadp
= (squidaio_thread_t
*)squidaio_thread_pool
->alloc();
307 threadp
->status
= _THREAD_STARTING
;
308 threadp
->current_req
= NULL
;
309 threadp
->requests
= 0;
310 threadp
->next
= threads
;
313 if ((threadp
->thread
= CreateThread(NULL
, /* no security attributes */
314 0, /* use default stack size */
315 squidaio_thread_loop
, /* thread function */
316 threadp
, /* argument to thread function */
317 0, /* use default creation flags */
318 &(threadp
->dwThreadId
)) /* returns the thread identifier */
320 fprintf(stderr
, "Thread creation failed\n");
321 threadp
->status
= _THREAD_FAILED
;
325 /* Set the new thread priority above parent process */
326 SetThreadPriority(threadp
->thread
,THREAD_PRIORITY_ABOVE_NORMAL
);
329 /* Create request pool */
330 squidaio_request_pool
= memPoolCreate("aio_request", sizeof(squidaio_request_t
));
332 squidaio_large_bufs
= memPoolCreate("squidaio_large_bufs", AIO_LARGE_BUFS
);
334 squidaio_medium_bufs
= memPoolCreate("squidaio_medium_bufs", AIO_MEDIUM_BUFS
);
336 squidaio_small_bufs
= memPoolCreate("squidaio_small_bufs", AIO_SMALL_BUFS
);
338 squidaio_tiny_bufs
= memPoolCreate("squidaio_tiny_bufs", AIO_TINY_BUFS
);
340 squidaio_micro_bufs
= memPoolCreate("squidaio_micro_bufs", AIO_MICRO_BUFS
);
342 squidaio_initialised
= 1;
346 squidaio_shutdown(void)
348 squidaio_thread_t
*threadp
;
352 if (!squidaio_initialised
)
355 /* This is the same as in squidaio_sync */
357 squidaio_poll_queues();
358 } while (request_queue_len
> 0);
360 hthreads
= (HANDLE
*) xcalloc (NUMTHREADS
, sizeof (HANDLE
));
364 for (i
= 0; i
< NUMTHREADS
; ++i
) {
366 hthreads
[i
] = threadp
->thread
;
367 threadp
= threadp
->next
;
370 ReleaseMutex(request_queue
.mutex
);
371 ResetEvent(request_queue
.cond
);
372 ReleaseMutex(done_queue
.mutex
);
373 ResetEvent(done_queue
.cond
);
376 WaitForMultipleObjects(NUMTHREADS
, hthreads
, TRUE
, 2000);
378 for (i
= 0; i
< NUMTHREADS
; ++i
) {
379 CloseHandle(hthreads
[i
]);
382 CloseHandle(main_thread
);
383 CommIO::NotifyIOClose();
385 squidaio_initialised
= 0;
390 squidaio_thread_loop(LPVOID lpParam
)
392 squidaio_thread_t
*threadp
= (squidaio_thread_t
*)lpParam
;
393 squidaio_request_t
*request
;
394 HANDLE cond
; /* local copy of the event queue because win32 event handles
395 * don't atomically release the mutex as cond variables do. */
397 /* lock the thread info */
399 if (WAIT_FAILED
== WaitForSingleObject(request_queue
.mutex
, INFINITE
)) {
400 fatal("Can't get ownership of mutex\n");
403 /* duplicate the handle */
404 if (!DuplicateHandle(GetCurrentProcess(), /* pseudo handle, don't close */
405 request_queue
.cond
, /* handle to copy */
406 GetCurrentProcess(), /* pseudo handle, don't close */
408 0, /* required access */
409 FALSE
, /* child process's don't inherit the handle */
410 DUPLICATE_SAME_ACCESS
))
411 fatal("Can't duplicate mutex handle\n");
413 if (!ReleaseMutex(request_queue
.mutex
)) {
415 fatal("Can't release mutex\n");
422 threadp
->current_req
= request
= NULL
;
424 /* Get a request to process */
425 threadp
->status
= _THREAD_WAITING
;
428 CloseHandle(request_queue
.mutex
);
433 rv
= WaitForSingleObject(request_queue
.mutex
, INFINITE
);
435 if (rv
== WAIT_FAILED
) {
440 while (!request_queue
.head
) {
441 if (!ReleaseMutex(request_queue
.mutex
)) {
443 threadp
->status
= _THREAD_FAILED
;
448 rv
= WaitForSingleObject(cond
, INFINITE
);
450 if (rv
== WAIT_FAILED
) {
455 rv
= WaitForSingleObject(request_queue
.mutex
, INFINITE
);
457 if (rv
== WAIT_FAILED
) {
463 request
= request_queue
.head
;
466 request_queue
.head
= request
->next
;
468 if (!request_queue
.head
)
469 request_queue
.tailp
= &request_queue
.head
;
471 if (!ReleaseMutex(request_queue
.mutex
)) {
478 /* process the request */
479 threadp
->status
= _THREAD_BUSY
;
481 request
->next
= NULL
;
483 threadp
->current_req
= request
;
487 if (!request
->cancelled
) {
488 switch (request
->request_type
) {
491 squidaio_do_open(request
);
495 squidaio_do_read(request
);
499 squidaio_do_write(request
);
503 squidaio_do_close(request
);
507 squidaio_do_unlink(request
);
510 #if AIO_OPENDIR /* Opendir not implemented yet */
512 case _AIO_OP_OPENDIR
:
513 squidaio_do_opendir(request
);
518 squidaio_do_stat(request
);
523 request
->err
= EINVAL
;
526 } else { /* cancelled */
528 request
->err
= EINTR
;
531 threadp
->status
= _THREAD_DONE
;
532 /* put the request in the done queue */
533 rv
= WaitForSingleObject(done_queue
.mutex
, INFINITE
);
535 if (rv
== WAIT_FAILED
) {
540 *done_queue
.tailp
= request
;
541 done_queue
.tailp
= &request
->next
;
543 if (!ReleaseMutex(done_queue
.mutex
)) {
548 CommIO::NotifyIOCompleted();
550 ++ threadp
->requests
;
551 } /* while forever */
556 } /* squidaio_thread_loop */
559 squidaio_queue_request(squidaio_request_t
* request
)
561 static int high_start
= 0;
562 debugs(43, 9, "squidaio_queue_request: " << request
<< " type=" << request
->request_type
<< " result=" << request
->resultp
);
563 /* Mark it as not executed (failing result, no error) */
566 /* Internal housekeeping */
567 request_queue_len
+= 1;
568 request
->resultp
->_data
= request
;
569 /* Play some tricks with the request_queue2 queue */
570 request
->next
= NULL
;
572 if (WaitForSingleObject(request_queue
.mutex
, 0) == WAIT_OBJECT_0
) {
573 if (request_queue2
.head
) {
574 /* Grab blocked requests */
575 *request_queue
.tailp
= request_queue2
.head
;
576 request_queue
.tailp
= request_queue2
.tailp
;
579 /* Enqueue request */
580 *request_queue
.tailp
= request
;
582 request_queue
.tailp
= &request
->next
;
584 if (!SetEvent(request_queue
.cond
))
585 fatal("Couldn't push queue");
587 if (!ReleaseMutex(request_queue
.mutex
)) {
588 /* unexpected error */
589 fatal("Couldn't push queue");
594 if (request_queue2
.head
) {
595 /* Clear queue of blocked requests */
596 request_queue2
.head
= NULL
;
597 request_queue2
.tailp
= &request_queue2
.head
;
600 /* Oops, the request queue is blocked, use request_queue2 */
601 *request_queue2
.tailp
= request
;
602 request_queue2
.tailp
= &request
->next
;
605 if (request_queue2
.head
) {
606 static int filter
= 0;
607 static int filter_limit
= 8;
609 if (++filter
>= filter_limit
) {
610 filter_limit
+= filter
;
612 debugs(43, DBG_IMPORTANT
, "squidaio_queue_request: WARNING - Queue congestion");
616 /* Warn if out of threads */
617 if (request_queue_len
> MAGIC1
) {
618 static int last_warn
= 0;
619 static int queue_high
, queue_low
;
621 if (high_start
== 0) {
622 high_start
= (int)squid_curtime
;
623 queue_high
= request_queue_len
;
624 queue_low
= request_queue_len
;
627 if (request_queue_len
> queue_high
)
628 queue_high
= request_queue_len
;
630 if (request_queue_len
< queue_low
)
631 queue_low
= request_queue_len
;
633 if (squid_curtime
>= (last_warn
+ 15) &&
634 squid_curtime
>= (high_start
+ 5)) {
635 debugs(43, DBG_IMPORTANT
, "squidaio_queue_request: WARNING - Disk I/O overloading");
637 if (squid_curtime
>= (high_start
+ 15))
638 debugs(43, DBG_IMPORTANT
, "squidaio_queue_request: Queue Length: current=" <<
639 request_queue_len
<< ", high=" << queue_high
<<
640 ", low=" << queue_low
<< ", duration=" <<
641 (long int) (squid_curtime
- high_start
));
643 last_warn
= (int)squid_curtime
;
649 /* Warn if seriously overloaded */
650 if (request_queue_len
> RIDICULOUS_LENGTH
) {
651 debugs(43, DBG_CRITICAL
, "squidaio_queue_request: Async request queue growing uncontrollably!");
652 debugs(43, DBG_CRITICAL
, "squidaio_queue_request: Syncing pending I/O operations.. (blocking)");
654 debugs(43, DBG_CRITICAL
, "squidaio_queue_request: Synced");
656 } /* squidaio_queue_request */
659 squidaio_cleanup_request(squidaio_request_t
* requestp
)
661 squidaio_result_t
*resultp
= requestp
->resultp
;
662 int cancelled
= requestp
->cancelled
;
664 /* Free allocated structures and copy data back to user space if the */
665 /* request hasn't been cancelled */
667 switch (requestp
->request_type
) {
671 if (!cancelled
&& requestp
->ret
== 0)
672 memcpy(requestp
->statp
, requestp
->tmpstatp
, sizeof(struct stat
));
674 squidaio_xfree(requestp
->tmpstatp
, sizeof(struct stat
));
676 squidaio_xstrfree(requestp
->path
);
681 if (cancelled
&& requestp
->ret
>= 0)
682 /* The open() was cancelled but completed */
683 close(requestp
->ret
);
685 squidaio_xstrfree(requestp
->path
);
690 if (cancelled
&& requestp
->ret
< 0)
691 /* The close() was cancelled and never got executed */
698 case _AIO_OP_OPENDIR
:
699 squidaio_xstrfree(requestp
->path
);
713 if (resultp
!= NULL
&& !cancelled
) {
714 resultp
->aio_return
= requestp
->ret
;
715 resultp
->aio_errno
= requestp
->err
;
718 squidaio_request_pool
->free(requestp
);
719 } /* squidaio_cleanup_request */
722 squidaio_cancel(squidaio_result_t
* resultp
)
724 squidaio_request_t
*request
= (squidaio_request_t
*)resultp
->_data
;
726 if (request
&& request
->resultp
== resultp
) {
727 debugs(43, 9, "squidaio_cancel: " << request
<< " type=" << request
->request_type
<< " result=" << request
->resultp
);
728 request
->cancelled
= 1;
729 request
->resultp
= NULL
;
730 resultp
->_data
= NULL
;
731 resultp
->result_type
= _AIO_OP_NONE
;
736 } /* squidaio_cancel */
739 squidaio_open(const char *path
, int oflag
, mode_t mode
, squidaio_result_t
* resultp
)
742 squidaio_request_t
*requestp
;
744 requestp
= (squidaio_request_t
*)squidaio_request_pool
->alloc();
746 requestp
->path
= (char *) squidaio_xstrdup(path
);
748 requestp
->oflag
= oflag
;
750 requestp
->mode
= mode
;
752 requestp
->resultp
= resultp
;
754 requestp
->request_type
= _AIO_OP_OPEN
;
756 requestp
->cancelled
= 0;
758 resultp
->result_type
= _AIO_OP_OPEN
;
760 squidaio_queue_request(requestp
);
766 squidaio_do_open(squidaio_request_t
* requestp
)
768 requestp
->ret
= open(requestp
->path
, requestp
->oflag
, requestp
->mode
);
769 requestp
->err
= errno
;
773 squidaio_read(int fd
, char *bufp
, size_t bufs
, off_t offset
, int whence
, squidaio_result_t
* resultp
)
775 squidaio_request_t
*requestp
;
777 requestp
= (squidaio_request_t
*)squidaio_request_pool
->alloc();
781 requestp
->bufferp
= bufp
;
783 requestp
->buflen
= bufs
;
785 requestp
->offset
= offset
;
787 requestp
->whence
= whence
;
789 requestp
->resultp
= resultp
;
791 requestp
->request_type
= _AIO_OP_READ
;
793 requestp
->cancelled
= 0;
795 resultp
->result_type
= _AIO_OP_READ
;
797 squidaio_queue_request(requestp
);
803 squidaio_do_read(squidaio_request_t
* requestp
)
805 lseek(requestp
->fd
, requestp
->offset
, requestp
->whence
);
807 if (!ReadFile((HANDLE
)_get_osfhandle(requestp
->fd
), requestp
->bufferp
,
808 requestp
->buflen
, (LPDWORD
)&requestp
->ret
, NULL
)) {
809 WIN32_maperror(GetLastError());
813 requestp
->err
= errno
;
817 squidaio_write(int fd
, char *bufp
, size_t bufs
, off_t offset
, int whence
, squidaio_result_t
* resultp
)
819 squidaio_request_t
*requestp
;
821 requestp
= (squidaio_request_t
*)squidaio_request_pool
->alloc();
825 requestp
->bufferp
= bufp
;
827 requestp
->buflen
= bufs
;
829 requestp
->offset
= offset
;
831 requestp
->whence
= whence
;
833 requestp
->resultp
= resultp
;
835 requestp
->request_type
= _AIO_OP_WRITE
;
837 requestp
->cancelled
= 0;
839 resultp
->result_type
= _AIO_OP_WRITE
;
841 squidaio_queue_request(requestp
);
847 squidaio_do_write(squidaio_request_t
* requestp
)
849 if (!WriteFile((HANDLE
)_get_osfhandle(requestp
->fd
), requestp
->bufferp
,
850 requestp
->buflen
, (LPDWORD
)&requestp
->ret
, NULL
)) {
851 WIN32_maperror(GetLastError());
855 requestp
->err
= errno
;
859 squidaio_close(int fd
, squidaio_result_t
* resultp
)
861 squidaio_request_t
*requestp
;
863 requestp
= (squidaio_request_t
*)squidaio_request_pool
->alloc();
867 requestp
->resultp
= resultp
;
869 requestp
->request_type
= _AIO_OP_CLOSE
;
871 requestp
->cancelled
= 0;
873 resultp
->result_type
= _AIO_OP_CLOSE
;
875 squidaio_queue_request(requestp
);
881 squidaio_do_close(squidaio_request_t
* requestp
)
883 if ((requestp
->ret
= close(requestp
->fd
)) < 0) {
884 debugs(43, DBG_CRITICAL
, "squidaio_do_close: FD " << requestp
->fd
<< ", errno " << errno
);
888 requestp
->err
= errno
;
893 squidaio_stat(const char *path
, struct stat
*sb
, squidaio_result_t
* resultp
)
896 squidaio_request_t
*requestp
;
898 requestp
= (squidaio_request_t
*)squidaio_request_pool
->alloc();
900 requestp
->path
= (char *) squidaio_xstrdup(path
);
902 requestp
->statp
= sb
;
904 requestp
->tmpstatp
= (struct stat
*) squidaio_xmalloc(sizeof(struct stat
));
906 requestp
->resultp
= resultp
;
908 requestp
->request_type
= _AIO_OP_STAT
;
910 requestp
->cancelled
= 0;
912 resultp
->result_type
= _AIO_OP_STAT
;
914 squidaio_queue_request(requestp
);
920 squidaio_do_stat(squidaio_request_t
* requestp
)
922 requestp
->ret
= stat(requestp
->path
, requestp
->tmpstatp
);
923 requestp
->err
= errno
;
927 squidaio_unlink(const char *path
, squidaio_result_t
* resultp
)
930 squidaio_request_t
*requestp
;
932 requestp
= (squidaio_request_t
*)squidaio_request_pool
->alloc();
934 requestp
->path
= squidaio_xstrdup(path
);
936 requestp
->resultp
= resultp
;
938 requestp
->request_type
= _AIO_OP_UNLINK
;
940 requestp
->cancelled
= 0;
942 resultp
->result_type
= _AIO_OP_UNLINK
;
944 squidaio_queue_request(requestp
);
950 squidaio_do_unlink(squidaio_request_t
* requestp
)
952 requestp
->ret
= unlink(requestp
->path
);
953 requestp
->err
= errno
;
957 /* XXX squidaio_opendir NOT implemented yet.. */
960 squidaio_opendir(const char *path
, squidaio_result_t
* resultp
)
962 squidaio_request_t
*requestp
;
965 requestp
= squidaio_request_pool
->alloc();
967 resultp
->result_type
= _AIO_OP_OPENDIR
;
973 squidaio_do_opendir(squidaio_request_t
* requestp
)
975 /* NOT IMPLEMENTED */
981 squidaio_poll_queues(void)
983 /* kick "overflow" request queue */
985 if (request_queue2
.head
&&
986 (WaitForSingleObject(request_queue
.mutex
, 0 )== WAIT_OBJECT_0
)) {
987 *request_queue
.tailp
= request_queue2
.head
;
988 request_queue
.tailp
= request_queue2
.tailp
;
990 if (!SetEvent(request_queue
.cond
))
991 fatal("couldn't push queue\n");
993 if (!ReleaseMutex(request_queue
.mutex
)) {
994 /* unexpected error */
998 request_queue2
.head
= NULL
;
999 request_queue2
.tailp
= &request_queue2
.head
;
1002 /* poll done queue */
1003 if (done_queue
.head
&&
1004 (WaitForSingleObject(done_queue
.mutex
, 0)==WAIT_OBJECT_0
)) {
1006 struct squidaio_request_t
*requests
= done_queue
.head
;
1007 done_queue
.head
= NULL
;
1008 done_queue
.tailp
= &done_queue
.head
;
1010 if (!ReleaseMutex(done_queue
.mutex
)) {
1011 /* unexpected error */
1015 *done_requests
.tailp
= requests
;
1016 request_queue_len
-= 1;
1018 while (requests
->next
) {
1019 requests
= requests
->next
;
1020 request_queue_len
-= 1;
1023 done_requests
.tailp
= &requests
->next
;
1028 squidaio_poll_done(void)
1030 squidaio_request_t
*request
;
1031 squidaio_result_t
*resultp
;
1036 request
= done_requests
.head
;
1038 if (request
== NULL
&& !polled
) {
1039 CommIO::ResetNotifications();
1040 squidaio_poll_queues();
1042 request
= done_requests
.head
;
1049 debugs(43, 9, "squidaio_poll_done: " << request
<< " type=" << request
->request_type
<< " result=" << request
->resultp
);
1050 done_requests
.head
= request
->next
;
1052 if (!done_requests
.head
)
1053 done_requests
.tailp
= &done_requests
.head
;
1055 resultp
= request
->resultp
;
1057 cancelled
= request
->cancelled
;
1059 squidaio_debug(request
);
1061 debugs(43, 5, "DONE: " << request
->ret
<< " -> " << request
->err
);
1063 squidaio_cleanup_request(request
);
1069 } /* squidaio_poll_done */
1072 squidaio_operations_pending(void)
1074 return request_queue_len
+ (done_requests
.head
? 1 : 0);
1080 /* XXX This might take a while if the queue is large.. */
1083 squidaio_poll_queues();
1084 } while (request_queue_len
> 0);
1086 return squidaio_operations_pending();
1090 squidaio_get_queue_len(void)
1092 return request_queue_len
;
1096 squidaio_debug(squidaio_request_t
* request
)
1098 switch (request
->request_type
) {
1101 debugs(43, 5, "OPEN of " << request
->path
<< " to FD " << request
->ret
);
1105 debugs(43, 5, "READ on fd: " << request
->fd
);
1109 debugs(43, 5, "WRITE on fd: " << request
->fd
);
1113 debugs(43, 5, "CLOSE of fd: " << request
->fd
);
1116 case _AIO_OP_UNLINK
:
1117 debugs(43, 5, "UNLINK of " << request
->path
);
1126 squidaio_stats(StoreEntry
* sentry
)
1128 squidaio_thread_t
*threadp
;
1131 if (!squidaio_initialised
)
1134 storeAppendPrintf(sentry
, "\n\nThreads Status:\n");
1136 storeAppendPrintf(sentry
, "#\tID\t# Requests\n");
1140 for (i
= 0; i
< NUMTHREADS
; ++i
) {
1141 storeAppendPrintf(sentry
, "%i\t0x%lx\t%ld\n", i
+ 1, threadp
->dwThreadId
, threadp
->requests
);
1142 threadp
= threadp
->next
;