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

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

View File

@ -214,10 +214,10 @@ asm void qse_spl_unlock (qse_spl_t* spl)
"lwarx %0,0,%1\n" /* load and reserve. rc(%0) = *spl(%1) */ "lwarx %0,0,%1\n" /* load and reserve. rc(%0) = *spl(%1) */
"cmpwi cr0,%0,0\n" /* cr0 = (rc compare-with 0) */ "cmpwi cr0,%0,0\n" /* cr0 = (rc compare-with 0) */
"li %0,0\n" /* rc = 0(failure) */ "li %0,0\n" /* rc = 0(failure) */
"bne- __exit\n" /* if cr0 != 0, goto _exit; */ "bne cr0,__exit\n" /* if cr0 != 0, goto _exit; */
"li %0,1\n" /* rc = 1(success) */ "li %0,1\n" /* rc = 1(success) */
"stwcx. %0,0,%1\n" /* *spl(%1) = 1(value in rc) if reserved */ "stwcx. %0,0,%1\n" /* *spl(%1) = 1(value in rc) if reserved */
"bne- __back\n" /* if reservation is lost, goto __back */ "bne cr0,__back\n" /* if reservation is lost, goto __back */
#if 1 #if 1
"lwsync\n" "lwsync\n"
#else #else
@ -233,20 +233,17 @@ asm void qse_spl_unlock (qse_spl_t* spl)
} }
static QSE_INLINE void qse_spl_lock (qse_spl_t* spl) static QSE_INLINE void qse_spl_lock (qse_spl_t* spl)
{ {
int x; while (!qse_spl_trylock(spl)) /* nothing */;
do
{
x = qse_spl_trylock(spl);
}
while (x);
} }
static QSE_INLINE void qse_spl_unlock (qse_spl_t* spl) static QSE_INLINE void qse_spl_unlock (qse_spl_t* spl)
{ {
__asm__ volatile ( __asm__ volatile (
#if 1 #if 1
"lwsync\n" "lwsync\n"
#else #elif 0
"sync\n" "sync\n"
#else
"eieio\n"
#endif #endif
: :
: :

View File

@ -35,7 +35,7 @@
#include <math.h> #include <math.h>
#if defined(HAVE_QUADMATH_H) #if defined(HAVE_QUADMATH_H)
# include <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 # error QUADMATH.H NOT AVAILABLE or NOT COMPILABLE
#endif #endif

View File

@ -30,6 +30,10 @@
#include <qse/cmn/time.h> #include <qse/cmn/time.h>
#include <stdarg.h> #include <stdarg.h>
#if defined(HAVE_UNISTD_H)
# include <unistd.h>
#endif
#if (!defined(__unix__) && !defined(__unix)) || defined(HAVE_PTHREAD) #if (!defined(__unix__) && !defined(__unix)) || defined(HAVE_PTHREAD)
qse_thr_t* qse_thr_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) qse_thr_t* qse_thr_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
@ -208,7 +212,17 @@ static int __create_thread (qse_thr_t* thr)
if (thr->__stacksize > 0) 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); pthread_attr_destroy (&attr);
return -1; return -1;