changed qse_thr_setstacksize() to align the given value to the page size

This commit is contained in:
2018-10-29 08:45:31 +00:00
parent 38ffad3544
commit 2c02013ec1
3 changed files with 28 additions and 17 deletions

View File

@ -35,7 +35,7 @@
#include <math.h>
#if defined(HAVE_QUADMATH_H)
# include <quadmath.h>
#elif defined(QSE_USE_AWK_FLTMAX) && (QSE_AWK_SIZEOF_FLT_T == 16)
#elif defined(QSE_USE_AWK_FLTMAX) && (QSE_AWK_SIZEOF_FLT_T == 16) && defined(QSE_FLTMAX_REQUIRE_QUADMATH)
# error QUADMATH.H NOT AVAILABLE or NOT COMPILABLE
#endif

View File

@ -30,6 +30,10 @@
#include <qse/cmn/time.h>
#include <stdarg.h>
#if defined(HAVE_UNISTD_H)
# include <unistd.h>
#endif
#if (!defined(__unix__) && !defined(__unix)) || defined(HAVE_PTHREAD)
qse_thr_t* qse_thr_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
@ -208,14 +212,24 @@ static int __create_thread (qse_thr_t* thr)
if (thr->__stacksize > 0)
{
if (pthread_attr_setstacksize (&attr, thr->__stacksize) != 0)
int x;
qse_size_t ss = thr->__stacksize;
#if defined(PTHREAD_STACK_MIN)
if (ss < PTHREAD_STACK_MIN) ss = PTHREAD_STACK_MIN;
#endif
#if defined(_SC_PAGESIZE)
/* some systems(e.g. darwin 8.11.0/macosx) require the size
* to be page size aligned. */
ss = QSE_ALIGNTO(ss, sysconf(_SC_PAGESIZE));
#endif
if ((x = pthread_attr_setstacksize(&attr, ss)) != 0)
{
pthread_attr_destroy (&attr);
return -1;
}
}
if (pthread_create (&thr->__handle, &attr, __thread_main, thr) != 0)
if (pthread_create(&thr->__handle, &attr, __thread_main, thr) != 0)
{
pthread_attr_destroy (&attr);
return -1;