+#if DEBUG
+volatile
+#endif
+jit_word_t lock;
+pthread_t tids[4];
+
+#if DEBUG
+int debug_offset(void)
+{
+ int i;
+ pthread_t self = pthread_self();
+ for (i = 0; i < 4; ++i)
+ if (tids[i] == self)
+ return i;
+ return -1;
+}
+
+void debug_spin(void)
+{
+ printf(" spin %d : %ld\n", debug_offset(), lock);
+}
+
+void debug_lock(void)
+{
+ printf(" lock %d : %ld\n", debug_offset(), lock);
+}
+
+void debug_unlock(void)
+{
+ printf("unlock %d : %ld\n", debug_offset(), lock);
+}
+#define DEBUG_SPIN() jit_calli(debug_spin)
+#define DEBUG_LOCK() jit_calli(debug_lock)
+#define DEBUG_UNLOCK() jit_calli(debug_unlock)
+#else
+#define DEBUG_SPIN() /**/
+#define DEBUG_LOCK() /**/
+#define DEBUG_UNLOCK() /**/
+#endif
+