From 50ee8cabcc0784038cf2d0f776a1730875c38172 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 29 Oct 2018 04:38:47 +0000 Subject: [PATCH] added qse_spl_trylock() for powerpc --- qse/include/qse/si/spl.h | 70 ++++++++++++++++++++++++++++++++++++++++ qse/lib/si/Makefile.am | 2 +- qse/lib/si/Makefile.in | 2 +- qse/lib/xli/Makefile.am | 1 + 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/qse/include/qse/si/spl.h b/qse/include/qse/si/spl.h index 74ec4ff5..c826e9da 100644 --- a/qse/include/qse/si/spl.h +++ b/qse/include/qse/si/spl.h @@ -184,6 +184,76 @@ asm void qse_spl_unlock (qse_spl_t* spl) #endif } +#elif defined(__GNUC__) && (defined(__POWERPC__) || defined(__powerpc) || defined(__powerpc__) || defined(__ppc)) + + static QSE_INLINE int qse_spl_trylock (qse_spl_t* spl) + { + + /* lwarx RT, RA, RB + * RT Specifies target general-purpose register where result of operation is stored. + * RA Specifies source general-purpose register for EA calculation. + * RB Specifies source general-purpose register for EA calculation. + * + * If general-purpose register (GPR) RA = 0, the effective address (EA) is the + * content of GPR RB. Otherwise, the EA is the sum of the content of GPR RA + * plus the content of GPR RB. + + * The lwarx instruction loads the word from the location in storage specified + * by the EA into the target GPR RT. In addition, a reservation on the memory + * location is created for use by a subsequent stwcx. instruction. + + * The lwarx instruction has one syntax form and does not affect the + * Fixed-Point Exception Register. If the EA is not a multiple of 4, + * the results are boundedly undefined. + */ + + unsigned int rc; + + __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 */ + #if 1 + "lwsync\n" + #else + "isync\n" + #endif + "__exit:\n" + : "=&r"(rc) + : "r"(spl) + : "cr0", "memory" + ); + + return rc; + } + static QSE_INLINE void qse_spl_lock (qse_spl_t* spl) + { + int x; + do + { + x = qse_spl_trylock(spl); + } + while (x); + } + static QSE_INLINE void qse_spl_unlock (qse_spl_t* spl) + { + __asm__ volatile ( + #if 1 + "lwsync\n" + #else + "sync\n" + #endif + : + : + : "memory" + ); + *spl = 0; + } #elif defined(QSE_SPL_NO_UNSUPPORTED_ERROR) /* don't raise the compile time error */ diff --git a/qse/lib/si/Makefile.am b/qse/lib/si/Makefile.am index 581a3ef1..0455df40 100644 --- a/qse/lib/si/Makefile.am +++ b/qse/lib/si/Makefile.am @@ -60,6 +60,6 @@ libqsesixx_la_SOURCES = \ TcpServer.cpp \ Thread.cpp libqsesixx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined -libqsesixx_la_LIBADD = -lqsecmnxx -lqsecmn +libqsesixx_la_LIBADD = -lqsecmnxx -lqsesi -lqsecmn endif diff --git a/qse/lib/si/Makefile.in b/qse/lib/si/Makefile.in index 1e232592..b205afe8 100644 --- a/qse/lib/si/Makefile.in +++ b/qse/lib/si/Makefile.in @@ -477,7 +477,7 @@ libqsesi_la_LIBADD = -lqsecmn $(PTHREAD_LIBS) $(SSL_LIBS) @ENABLE_CXX_TRUE@ Thread.cpp @ENABLE_CXX_TRUE@libqsesixx_la_LDFLAGS = -L. -L../cmn -version-info 1:0:0 -no-undefined -@ENABLE_CXX_TRUE@libqsesixx_la_LIBADD = -lqsecmnxx -lqsecmn +@ENABLE_CXX_TRUE@libqsesixx_la_LIBADD = -lqsesi -lqsecmnxx -lqsecmn all: all-am .SUFFIXES: diff --git a/qse/lib/xli/Makefile.am b/qse/lib/xli/Makefile.am index b28c13ce..0e5799a4 100644 --- a/qse/lib/xli/Makefile.am +++ b/qse/lib/xli/Makefile.am @@ -16,6 +16,7 @@ libqsexli_la_LIBADD = -lqsesi -lqsecmn if ENABLE_CXX lib_LTLIBRARIES += libqsexlixx.la libqsexlixx_la_SOURCES = SkvEnv.cpp +libqsexlixx_la_LDFLAGS = -L. -L../cmn -L../si -version-info 1:0:0 -no-undefined libqsexlixx_la_LIBADD = -lqsecmnxx -lqsexli -lqsesi -lqsecmn endif