added some more code to spl.h

This commit is contained in:
hyung-hwan 2018-01-31 14:50:40 +00:00
parent be51ae8e61
commit b7e540d6cf
3 changed files with 52 additions and 2 deletions

View File

@ -51,7 +51,7 @@ public:
#if defined(QSE_SUPPORT_SPL) #if defined(QSE_SUPPORT_SPL)
SpinLock() QSE_CPP_NOEXCEPT: flag(QSE_SPL_INIT) {} SpinLock() QSE_CPP_NOEXCEPT: flag(QSE_SPL_INIT) {}
#else #else
SpinLock() QSE_CPP_NOEXCEPT: flag(0) {} SpinLock() QSE_CPP_NOEXCEPT: flag(ATOMIC_FLAG_INIT) {}
#endif #endif
bool tryock() QSE_CPP_NOEXCEPT bool tryock() QSE_CPP_NOEXCEPT

View File

@ -135,6 +135,56 @@ asm void qse_spl_unlock (qse_spl_t* spl)
} }
#endif #endif
#elif defined(__GNUC__) && (defined(__x86_64) || defined(__amd64) || defined(__i386) || defined(i386))
static QSE_INLINE int qse_spl_trylock (qse_spl_t* spl)
{
register int x = 1;
__asm__ volatile (
"xchgl %0, (%2)\n"
: "=r"(x)
: "0"(x), "r"(spl)
: "memory"
);
return !x;
}
static QSE_INLINE void qse_spl_lock (qse_spl_t* spl)
{
register int x = 1;
do
{
__asm__ volatile (
"xchgl %0, (%2)\n"
: "=r"(x)
: "0"(x), "r"(spl)
: "memory"
);
}
while (x);
}
static QSE_INLINE void qse_spl_unlock (qse_spl_t* spl)
{
#if defined(__x86_64) || defined(__amd64)
__asm__ volatile (
"mfence\n\t"
"movl $0, (%0)\n"
:
:"r"(spl)
:"memory"
);
#else
__asm__ volatile (
"movl $0, (%0)\n"
:
:"r"(spl)
:"memory"
);
#endif
}
#elif defined(QSE_SPL_NO_UNSUPPORTED_ERROR) #elif defined(QSE_SPL_NO_UNSUPPORTED_ERROR)
/* don't raise the compile time error */ /* don't raise the compile time error */
#undef QSE_SUPPORT_SPL #undef QSE_SUPPORT_SPL

View File

@ -34,7 +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++;
//sleep (1); /*sleep (1);*/
} }
return i; return i;