/*
- * DEBUG: section 43 Windows AIOPS
- * AUTHOR: Stewart Forster <slf@connect.com.au>
- * AUTHOR: Robert Collins <robertc@squid-cache.org>
- * AUTHOR: Guido Serassio <serassio@squid-cache.org>
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 43 Windows AIOPS */
+
#include "squid.h"
-#include "squid_windows.h"
#include "DiskIO/DiskThreads/CommIO.h"
#include "DiskThreads.h"
+#include "fd.h"
+#include "mem/Pool.h"
+#include "SquidConfig.h"
#include "SquidTime.h"
#include "Store.h"
-#include <stdio.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <dirent.h>
-#include <signal.h>
+#include <cerrno>
+#include <csignal>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
-#define RIDICULOUS_LENGTH 4096
+#define RIDICULOUS_LENGTH 4096
enum _squidaio_thread_status {
_THREAD_STARTING = 0,
squidaio_request_t *volatile head;
squidaio_request_t *volatile *volatile tailp;
unsigned long requests;
- unsigned long blocked; /* main failed to lock the queue */
+ unsigned long blocked; /* main failed to lock the queue */
} squidaio_request_queue_t;
typedef struct squidaio_thread_t squidaio_thread_t;
static int squidaio_initialised = 0;
#define AIO_LARGE_BUFS 16384
-#define AIO_MEDIUM_BUFS AIO_LARGE_BUFS >> 1
-#define AIO_SMALL_BUFS AIO_LARGE_BUFS >> 2
-#define AIO_TINY_BUFS AIO_LARGE_BUFS >> 3
-#define AIO_MICRO_BUFS 128
+#define AIO_MEDIUM_BUFS AIO_LARGE_BUFS >> 1
+#define AIO_SMALL_BUFS AIO_LARGE_BUFS >> 2
+#define AIO_TINY_BUFS AIO_LARGE_BUFS >> 3
+#define AIO_MICRO_BUFS 128
-static MemAllocator *squidaio_large_bufs = NULL; /* 16K */
-static MemAllocator *squidaio_medium_bufs = NULL; /* 8K */
-static MemAllocator *squidaio_small_bufs = NULL; /* 4K */
-static MemAllocator *squidaio_tiny_bufs = NULL; /* 2K */
-static MemAllocator *squidaio_micro_bufs = NULL; /* 128K */
+static MemAllocator *squidaio_large_bufs = NULL; /* 16K */
+static MemAllocator *squidaio_medium_bufs = NULL; /* 8K */
+static MemAllocator *squidaio_small_bufs = NULL; /* 4K */
+static MemAllocator *squidaio_tiny_bufs = NULL; /* 2K */
+static MemAllocator *squidaio_micro_bufs = NULL; /* 128K */
static int request_queue_len = 0;
static MemAllocator *squidaio_request_pool = NULL;
MemAllocator *pool;
if ((pool = squidaio_get_pool(size)) != NULL) {
- pool->free(p);
+ pool->freeOne(p);
} else
xfree(p);
}
int len = strlen(str) + 1;
if ((pool = squidaio_get_pool(len)) != NULL) {
- pool->free(str);
+ pool->freeOne(str);
} else
xfree(str);
}
done_queue.blocked = 0;
- CommIO::NotifyIOCompleted();
+ // Initialize the thread I/O pipes before creating any threads
+ // see bug 3189 comment 5 about race conditions.
+ CommIO::Initialize();
/* Create threads and get them to sit in their wait loop */
squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t));
- assert(NUMTHREADS);
+ assert(NUMTHREADS > 0);
for (i = 0; i < NUMTHREADS; ++i) {
threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
squidaio_do_unlink(request);
break;
-#if AIO_OPENDIR /* Opendir not implemented yet */
+#if AIO_OPENDIR /* Opendir not implemented yet */
case _AIO_OP_OPENDIR:
squidaio_do_opendir(request);
request->err = EINVAL;
break;
}
- } else { /* cancelled */
+ } else { /* cancelled */
request->ret = -1;
request->err = EINTR;
}
CommIO::NotifyIOCompleted();
Sleep(0);
++ threadp->requests;
- } /* while forever */
+ } /* while forever */
CloseHandle(cond);
return 0;
-} /* squidaio_thread_loop */
+} /* squidaio_thread_loop */
static void
squidaio_queue_request(squidaio_request_t * request)
}
if (request_queue2.head) {
- static int filter = 0;
- static int filter_limit = 8;
+ static uint64_t filter = 0;
+ static uint64_t filter_limit = 8196;
if (++filter >= filter_limit) {
filter_limit += filter;
filter = 0;
- debugs(43, DBG_IMPORTANT, "squidaio_queue_request: WARNING - Queue congestion");
+ debugs(43, DBG_IMPORTANT, "squidaio_queue_request: WARNING - Queue congestion (growing to " << filter_limit << ")");
}
}
squidaio_sync();
debugs(43, DBG_CRITICAL, "squidaio_queue_request: Synced");
}
-} /* squidaio_queue_request */
+} /* squidaio_queue_request */
static void
squidaio_cleanup_request(squidaio_request_t * requestp)
resultp->aio_errno = requestp->err;
}
- squidaio_request_pool->free(requestp);
-} /* squidaio_cleanup_request */
+ squidaio_request_pool->freeOne(requestp);
+} /* squidaio_cleanup_request */
int
squidaio_cancel(squidaio_result_t * resultp)
}
return 1;
-} /* squidaio_cancel */
+} /* squidaio_cancel */
int
squidaio_open(const char *path, int oflag, mode_t mode, squidaio_result_t * resultp)
goto AIO_REPOLL;
return resultp;
-} /* squidaio_poll_done */
+} /* squidaio_poll_done */
int
squidaio_operations_pending(void)
threadp = threadp->next;
}
}
+