diff options
author | Rich Felker <dalias@aerifal.cx> | 2020-12-08 18:02:39 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2020-12-08 18:02:39 -0500 |
commit | b67d56c7b3b0f84360db749aa6f431a07761d9c8 (patch) | |
tree | ebb174d2dc4c9a912e9870c8601d32a81ff30718 /src/aio | |
parent | 90ff016996753d83263445940710c87d9afa71f3 (diff) | |
download | musl-b67d56c7b3b0f84360db749aa6f431a07761d9c8.tar.gz |
drop use of pthread_once for aio thread stack size init
pthread_once is not compatible with MT-fork constraints (commit
167390f05564e0a4d3fcb4329377fd7743267560) and is not needed here
anyway; we already have a lock suitable for initialization.
while changing this, fix a corner case where AT_MINSIGSTKSZ gives a
value that's more than MINSIGSTKSZ but by a margin of less than
2048, thereby causing the size to be reduced. it shouldn't matter but
the intent was to be the larger of a 2048-byte margin over the legacy
fixed minimum stack requirement or a 512-byte margin over the minimum
the kernel reports at runtime.
Diffstat (limited to 'src/aio')
-rw-r--r-- | src/aio/aio.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/aio/aio.c b/src/aio/aio.c index e004f98b..a1a3e791 100644 --- a/src/aio/aio.c +++ b/src/aio/aio.c @@ -76,6 +76,10 @@ static struct aio_queue *****map; static volatile int aio_fd_cnt; volatile int __aio_fut; +static size_t io_thread_stack_size; + +#define MAX(a,b) ((a)>(b) ? (a) : (b)) + static struct aio_queue *__aio_get_queue(int fd, int need) { if (fd < 0) { @@ -90,6 +94,10 @@ static struct aio_queue *__aio_get_queue(int fd, int need) pthread_rwlock_unlock(&maplock); if (fcntl(fd, F_GETFD) < 0) return 0; pthread_rwlock_wrlock(&maplock); + if (!io_thread_stack_size) { + unsigned long val = __getauxval(AT_MINSIGSTKSZ); + io_thread_stack_size = MAX(MINSIGSTKSZ+2048, val+512); + } if (!map) map = calloc(sizeof *map, (-1U/2+1)>>24); if (!map) goto out; if (!map[a]) map[a] = calloc(sizeof **map, 256); @@ -265,15 +273,6 @@ static void *io_thread_func(void *ctx) return 0; } -static size_t io_thread_stack_size = MINSIGSTKSZ+2048; -static pthread_once_t init_stack_size_once; - -static void init_stack_size() -{ - unsigned long val = __getauxval(AT_MINSIGSTKSZ); - if (val > MINSIGSTKSZ) io_thread_stack_size = val + 512; -} - static int submit(struct aiocb *cb, int op) { int ret = 0; @@ -299,7 +298,6 @@ static int submit(struct aiocb *cb, int op) else pthread_attr_init(&a); } else { - pthread_once(&init_stack_size_once, init_stack_size); pthread_attr_init(&a); pthread_attr_setstacksize(&a, io_thread_stack_size); pthread_attr_setguardsize(&a, 0); |