db4 isn't working correctly on macppc for me and confirmed by <kili at outback.escape.de> after I posted to misc@ - I think it looks like a problem with the mutex assembly code.

I noticed it when trying to install Cyrus which was looping during the initial 'ctl_cyrusdb -r' at startup, and verified it with /usr/local/share/examples/db4/ex_env.c. (see <http://tinyurl.com/d84gy> for my original posts).

I don't know if it's a correct and/or good solution, but I found <http://cvs.gnome.org/viewcvs/*checkout*/evolution-data-server/libdb/dbinc/mutex.h> which uses slightly different ppc mutex code; from my initial quick testing it looks like this fixes Cyrus for me and makes ex_env.c behave the same as it does on i386.

The relevant part to replace the existing /usr/ports/databases/db/v4/patches/patch-dbinc_mutex_h is below.

--- dbinc/mutex.h.orig  Sat Sep 20 22:40:49 2003
+++ dbinc/mutex.h       Wed Aug 24 01:58:17 2005
@@ -578,33 +578,27 @@
* 'set' mutexes have the value 1, like on Intel; the returned value from * MUTEX_SET() is 1 if the mutex previously had its low bit clear, 0 otherwise.
 */
-#ifdef HAVE_MUTEX_PPC_GCC_ASSEMBLY
-static inline int
-MUTEX_SET(int *tsl)  {
-         int __r;
-         asm volatile (
-"0:                             \n\t"
-"       lwarx   %0,0,%1         \n\t"
-"       cmpwi   %0,0            \n\t"
-"       bne-    1f              \n\t"
-"       stwcx.  %1,0,%1         \n\t"
-"       isync                   \n\t"
-"       beq+    2f              \n\t"
-"       b       0b              \n\t"
-"1:                             \n\t"
-"       li      %1, 0           \n\t"
-"2:                             \n\t"
-         : "=&r" (__r), "+r" (tsl)
-         :
-         : "cr0", "memory");
-         return (int)tsl;
-}
-#endif
-static inline int
-MUTEX_UNSET(tsl_t *tsl) {
-         asm volatile("sync" : : : "memory");
-         return *tsl = 0;
-}
+#define MUTEX_SET(tsl)  ({                     \
+       int __one = 1;                          \
+       int __r;                                \
+       tsl_t *__l = (tsl);                     \
+       asm volatile ("                            \
+0:                                             \
+       lwarx %0,0,%1;                          \
+       cmpwi %0,0;                             \
+       bne 1f;                                 \
+       stwcx. %2,0,%1;                         \
+       bne- 0b;                                \
+       isync;                                  \
+1:"                                               \
+       : "=&r" (__r)                             \
+       : "r" (__l), "r" (__one));          \
+       !(__r & 1);                         \
+})
+#define MUTEX_UNSET(tsl) ({                    \
+       asm volatile("lwsync":::"memory");  \
+       (*(tsl) = 0);                           \
+})
#define MUTEX_INIT(tsl)         MUTEX_UNSET(tsl)
#endif
#endif

Reply via email to