[pypy-commit] stmgc c7-refactor: Add dprintf from stmgc/c4.
arigo
noreply at buildbot.pypy.org
Wed Feb 19 17:50:16 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: c7-refactor
Changeset: r787:c924c44d3852
Date: 2014-02-19 14:32 +0100
http://bitbucket.org/pypy/stmgc/changeset/c924c44d3852/
Log: Add dprintf from stmgc/c4.
diff --git a/c7/demo/Makefile b/c7/demo/Makefile
--- a/c7/demo/Makefile
+++ b/c7/demo/Makefile
@@ -20,7 +20,8 @@
# note that 'build' is optimized but still contains all asserts
debug-%: %.c ${H_FILES} ${C_FILES}
- clang -I.. -pthread -g $< -o debug-$* -Wall -Werror ../stmgc.c
+ clang -I.. -pthread -DSTM_DEBUGPRINT -g $< -o debug-$* \
+ -Wall -Werror ../stmgc.c
build-%: %.c ${H_FILES} ${C_FILES}
clang -I.. -pthread -g -O1 $< -o build-$* -Wall ../stmgc.c
release-%: %.c ${H_FILES} ${C_FILES}
diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -2,8 +2,6 @@
# error "must be compiled via stmgc.c"
#endif
-#include <unistd.h>
-
static uint8_t write_locks[READMARKER_END - READMARKER_START];
@@ -121,6 +119,8 @@
STM_SEGMENT->jmpbuf_ptr = jmpbuf;
STM_PSEGMENT->shadowstack_at_start_of_transaction = tl->shadowstack;
+ dprintf(("start_transaction\n"));
+
mutex_unlock();
uint8_t old_rv = STM_SEGMENT->transaction_read_version;
@@ -241,6 +241,8 @@
goto restart;
/* cannot abort any more from here */
+ dprintf(("commit_transaction\n"));
+
assert(STM_PSEGMENT->transaction_state != TS_MUST_ABORT);
STM_SEGMENT->jmpbuf_ptr = NULL;
@@ -316,6 +318,8 @@
static void abort_with_mutex(void)
{
+ dprintf(("~~~ ABORT\n"));
+
switch (STM_PSEGMENT->transaction_state) {
case TS_REGULAR:
case TS_MUST_ABORT:
diff --git a/c7/stm/fprintcolor.c b/c7/stm/fprintcolor.c
new file mode 100644
--- /dev/null
+++ b/c7/stm/fprintcolor.c
@@ -0,0 +1,33 @@
+/* ------------------------------------------------------------ */
+#ifdef STM_DEBUGPRINT
+/* ------------------------------------------------------------ */
+
+
+int dprintfcolor(void)
+{
+ return 31 + STM_SEGMENT->segment_num % 6;
+}
+
+int threadcolor_printf(const char *format, ...)
+{
+ char buffer[2048];
+ va_list ap;
+ int result;
+ int size = (int)sprintf(buffer, "\033[%dm", dprintfcolor());
+ assert(size >= 0);
+
+ va_start(ap, format);
+ result = vsnprintf(buffer + size, 2000, format, ap);
+ assert(result >= 0);
+ va_end(ap);
+
+ strcpy(buffer + size + result, "\033[0m");
+ fputs(buffer, stderr);
+
+ return result;
+}
+
+
+/* ------------------------------------------------------------ */
+#endif
+/* ------------------------------------------------------------ */
diff --git a/c7/stm/fprintcolor.h b/c7/stm/fprintcolor.h
new file mode 100644
--- /dev/null
+++ b/c7/stm/fprintcolor.h
@@ -0,0 +1,27 @@
+/* ------------------------------------------------------------ */
+#ifdef STM_DEBUGPRINT
+/* ------------------------------------------------------------ */
+
+
+#include <stdarg.h>
+
+
+#define dprintf(args) threadcolor_printf args
+int dprintfcolor(void);
+
+int threadcolor_printf(const char *format, ...)
+ __attribute__((format (printf, 1, 2)));
+
+
+/* ------------------------------------------------------------ */
+#else
+/* ------------------------------------------------------------ */
+
+
+#define dprintf(args) do { } while(0)
+#define dprintfcolor() 0
+
+
+/* ------------------------------------------------------------ */
+#endif
+/* ------------------------------------------------------------ */
diff --git a/c7/stmgc.c b/c7/stmgc.c
--- a/c7/stmgc.c
+++ b/c7/stmgc.c
@@ -10,6 +10,7 @@
#include "stm/largemalloc.h"
#include "stm/nursery.h"
#include "stm/contention.h"
+#include "stm/fprintcolor.h"
#include "stm/misc.c"
#include "stm/list.c"
@@ -23,3 +24,4 @@
#include "stm/setup.c"
#include "stm/core.c"
#include "stm/contention.c"
+#include "stm/fprintcolor.c"
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -271,7 +271,9 @@
}
''', sources=source_files,
- define_macros=[('STM_TESTS', '1'), ('STM_NO_COND_WAIT', '1')],
+ define_macros=[('STM_TESTS', '1'),
+ ('STM_NO_COND_WAIT', '1'),
+ ('STM_DEBUGPRINT', '1')],
undef_macros=['NDEBUG'],
include_dirs=[parent_dir],
extra_compile_args=['-g', '-O0', '-Werror'],
More information about the pypy-commit
mailing list