changed qse_thr_setstacksize() to align the given value to the page size
This commit is contained in:
		@ -211,13 +211,13 @@ asm void qse_spl_unlock (qse_spl_t* spl)
 | 
			
		||||
 | 
			
		||||
		__asm__ volatile (
 | 
			
		||||
			"__back:\n"
 | 
			
		||||
			"lwarx           %0,0,%1\n"  /* load and reserve. rc(%0) = *spl(%1) */
 | 
			
		||||
			"cmpwi           cr0,%0,0\n" /* cr0 = (rc compare-with 0) */
 | 
			
		||||
			"li              %0,0\n"     /* rc = 0(failure) */
 | 
			
		||||
			"bne-            __exit\n"   /* if cr0 != 0, goto _exit; */
 | 
			
		||||
			"li              %0,1\n"     /* rc = 1(success) */
 | 
			
		||||
			"stwcx.          %0,0,%1\n"  /* *spl(%1) = 1(value in rc) if reserved */
 | 
			
		||||
			"bne-            __back\n"   /* if reservation is lost, goto __back */
 | 
			
		||||
			"lwarx        %0,0,%1\n"  /* load and reserve. rc(%0) = *spl(%1) */
 | 
			
		||||
			"cmpwi        cr0,%0,0\n" /* cr0 = (rc compare-with 0) */
 | 
			
		||||
			"li           %0,0\n"     /* rc = 0(failure) */
 | 
			
		||||
			"bne          cr0,__exit\n"   /* if cr0 != 0, goto _exit; */
 | 
			
		||||
			"li           %0,1\n"     /* rc = 1(success) */
 | 
			
		||||
			"stwcx.       %0,0,%1\n"  /* *spl(%1) = 1(value in rc) if reserved */
 | 
			
		||||
			"bne          cr0,__back\n"   /* if reservation is lost, goto __back */
 | 
			
		||||
		#if 1
 | 
			
		||||
			"lwsync\n"
 | 
			
		||||
		#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) 
 | 
			
		||||
	{
 | 
			
		||||
		int x;
 | 
			
		||||
		do
 | 
			
		||||
		{
 | 
			
		||||
			x = qse_spl_trylock(spl);
 | 
			
		||||
		}
 | 
			
		||||
		while (x);
 | 
			
		||||
		while (!qse_spl_trylock(spl)) /* nothing */;
 | 
			
		||||
	}
 | 
			
		||||
	static QSE_INLINE void qse_spl_unlock (qse_spl_t* spl) 
 | 
			
		||||
	{
 | 
			
		||||
		__asm__ volatile (
 | 
			
		||||
		#if 1
 | 
			
		||||
			"lwsync\n" 
 | 
			
		||||
		#else
 | 
			
		||||
		#elif 0
 | 
			
		||||
			"sync\n" 
 | 
			
		||||
		#else
 | 
			
		||||
			"eieio\n" 
 | 
			
		||||
		#endif
 | 
			
		||||
			:
 | 
			
		||||
			:
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user