From 9bbbbc508caa9b20327121e6d1088f1da39c23f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Crist=C3=B3v=C3=A3o=20Cruz?= Date: Tue, 6 Apr 2010 12:46:49 +0100 Subject: [PATCH] Introduced debug function print_mutexes. --- funnysort.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/funnysort.c b/funnysort.c index 6f24f76..89878c4 100644 --- a/funnysort.c +++ b/funnysort.c @@ -50,6 +50,7 @@ void pick_item (unsigned int, unsigned int, board_t *, item_t *); void poke_item (unsigned int, unsigned int, board_t *, item_t); void print_board (board_t *); void print_item (unsigned int, unsigned int, item_t); +void print_mutexes (board_t *board); void *launch_sorter (void *); void setup_board(board_t *); @@ -429,6 +430,22 @@ void count_items(board_t *board, item_t *item, unsigned int *nitems) *nitems = count; } +void print_mutexes(board_t *board) +{ + int line, column; + + for (line = 0; line < board->height; ++line) { + for (column = 0; column < board->width; ++column) { + print_item(line, column, board->surface[line][column]); + if (pthread_mutex_trylock((board->lock)[line]+column) == 0) { + printf("U"); + } else { + printf("L"); + } + } + } +} + int main (int argc, char *argv[]) { board_t board; @@ -463,6 +480,7 @@ int main (int argc, char *argv[]) printf("THE END"); count_items(&board, &item, &nitems_finish); + print_mutexes(&board); /* make shure the sorters didn't ate items (they can have one with * themselves) */ -- 2.11.4.GIT