fixed starvation in samples/si/spl01.c

This commit is contained in:
hyung-hwan 2018-10-29 09:18:30 +00:00
parent 2c02013ec1
commit 388753fcba
2 changed files with 6 additions and 4 deletions

View File

@ -210,20 +210,20 @@ asm void qse_spl_unlock (qse_spl_t* spl)
unsigned int rc; unsigned int rc;
__asm__ volatile ( __asm__ volatile (
"__back:\n" "1:\n"
"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 cr0,__exit\n" /* if cr0 != 0, goto _exit; */ "bne cr0,2f\n" /* if cr0 != 0, goto 2; */
"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 cr0,__back\n" /* if reservation is lost, goto __back */ "bne cr0,1b\n" /* if reservation is lost, goto 1 */
#if 1 #if 1
"lwsync\n" "lwsync\n"
#else #else
"isync\n" "isync\n"
#endif #endif
"__exit:\n" "2:\n"
: "=&r"(rc) : "=&r"(rc)
: "r"(spl) : "r"(spl)
: "cr0", "memory" : "cr0", "memory"

View File

@ -10,6 +10,7 @@
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <sched.h>
static int g_stopreq = 0; static int g_stopreq = 0;
static qse_ntime_t sleep_interval = { 1, 0 }; static qse_ntime_t sleep_interval = { 1, 0 };
@ -33,6 +34,7 @@ static int thr_func (qse_thr_t* thr, void* ctx)
qse_printf (QSE_T("%s: [% 16d] [% 16d] [% 16d]\n"), xtn->name, i, i, i); qse_printf (QSE_T("%s: [% 16d] [% 16d] [% 16d]\n"), xtn->name, i, i, i);
qse_spl_unlock (xtn->spl); qse_spl_unlock (xtn->spl);
i++; i++;
if (!(i % 15)) sched_yield();
/*qse_sleep (&sleep_interval);*/ /*qse_sleep (&sleep_interval);*/
} }