Commit 28dc1296 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Sigh, POSIXed again: The minimum thread stack size is not a

compile time constant on all systems.

Pick it up with sysconf() instead.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4584 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 97c9a342
......@@ -44,7 +44,10 @@
#include "svnid.h"
SVNID("$Id: cache_pool.c 3429 2008-11-24 17:47:21Z phk $")
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include "cli_priv.h"
......@@ -64,6 +67,33 @@ tweak_thread_pool_min(struct cli *cli, const struct parspec *par,
(unsigned)par->min, master.wthread_max);
}
/*--------------------------------------------------------------------
* This is utterly ridiculous: POSIX does not guarantee that the
* minimum thread stack size is a compile time constant.
* XXX: "32" is a magic marker for 32bit systems.
*/
static void
tweak_stack_size(struct cli *cli, const struct parspec *par,
const char *arg)
{
unsigned low, u;
char buf[12];
low = sysconf(_SC_THREAD_STACK_MIN);
if (arg != NULL && !strcmp(arg, "32")) {
u = 65536;
if (u < low)
u = low;
sprintf(buf, "%u", u);
arg = buf;
}
tweak_generic_uint(cli, &master.wthread_stacksize, arg,
low, (uint)par->max);
}
/*--------------------------------------------------------------------*/
static void
......@@ -191,8 +221,7 @@ const struct parspec WRK_parspec[] = {
EXPERIMENTAL,
"3", "requests per request" },
{ "thread_pool_stack",
tweak_uint, &master.wthread_stacksize,
PTHREAD_STACK_MIN, UINT_MAX,
tweak_stack_size, &master.wthread_stacksize, 0, UINT_MAX,
"Worker thread stack size.\n"
"On 32bit systems you may need to tweak this down to fit "
"many threads into the limited address space.\n",
......@@ -200,4 +229,3 @@ const struct parspec WRK_parspec[] = {
"-1", "bytes" },
{ NULL, NULL, NULL }
};
......@@ -588,10 +588,7 @@ main(int argc, char * const *argv)
MCF_ParamSet(cli, "sess_workspace", "16384");
cli_check(cli);
/* Set the stacksize to min(PTHREAD_STACK_MIN, 64k) */
bprintf(dirname, "%d",
PTHREAD_STACK_MIN > 65536 ? PTHREAD_STACK_MIN : 65536);
MCF_ParamSet(cli, "thread_pool_stack", dirname);
MCF_ParamSet(cli, "thread_pool_stack", "32");
cli_check(cli);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment