From: <vl...@us...> - 2007-07-05 16:23:43
|
Revision: 144 http://svn.sourceforge.net/scst/?rev=144&view=rev Author: vlnb Date: 2007-07-05 09:23:09 -0700 (Thu, 05 Jul 2007) Log Message: ----------- trace_buf_lock implemented Modified Paths: -------------- trunk/usr/fileio/debug.c trunk/usr/fileio/debug.h trunk/usr/fileio/fileio.c Modified: trunk/usr/fileio/debug.c =================================================================== --- trunk/usr/fileio/debug.c 2007-07-05 14:39:37 UTC (rev 143) +++ trunk/usr/fileio/debug.c 2007-07-05 16:23:09 UTC (rev 144) @@ -20,6 +20,8 @@ #include <stdio.h> #include <time.h> +#include <pthread.h> +#include <string.h> #include "debug.h" @@ -30,14 +32,14 @@ #define TRACE_BUF_SIZE 512 static char trace_buf[TRACE_BUF_SIZE]; -//static spinlock_t trace_buf_lock = SPIN_LOCK_UNLOCKED; +static pthread_spinlock_t trace_buf_lock; int debug_print_prefix(unsigned long trace_flag, const char *func, int line) { int i = 0; -// spin_lock_irqsave(&trace_buf_lock, flags); + pthread_spin_lock(&trace_buf_lock); if (trace_flag & TRACE_TIME) { struct tm t; @@ -58,7 +60,7 @@ if (i > 0) PRINTN("%s", trace_buf); -// spin_unlock_irqrestore(&trace_buf_lock, flags); + pthread_spin_unlock(&trace_buf_lock); return i; } @@ -72,7 +74,7 @@ if (buf == NULL) return; -// spin_lock_irqsave(&trace_buf_lock, flags); + pthread_spin_lock(&trace_buf_lock); PRINT(" (h)___0__1__2__3__4__5__6__7__8__9__A__B__C__D__E__F"); for (z = 0, z1 = 0, i = 0; z < len; z++) { @@ -113,8 +115,26 @@ PRINT("%s", trace_buf); } -// spin_unlock_irqrestore(&trace_buf_lock, flags); + pthread_spin_unlock(&trace_buf_lock); return; } +int debug_init(void) +{ + int res; + + res = pthread_spin_init(&trace_buf_lock, PTHREAD_PROCESS_PRIVATE); + if (res != 0) { + res = errno; + PRINT_ERROR_PR("pthread_spin_init() failed: %s", strerror(res)); + } + + return res; +} + +void debug_done(void) +{ + pthread_spin_destroy(&trace_buf_lock); +} + #endif /* DEBUG || TRACING */ Modified: trunk/usr/fileio/debug.h =================================================================== --- trunk/usr/fileio/debug.h 2007-07-05 14:39:37 UTC (rev 143) +++ trunk/usr/fileio/debug.h 2007-07-05 16:23:09 UTC (rev 144) @@ -64,6 +64,9 @@ extern unsigned long trace_flag; +extern int debug_init(void); +extern void debug_done(void); + extern int debug_print_prefix(unsigned long trace_flag, const char *func, int line); extern void debug_print_buffer(const void *data, int len); Modified: trunk/usr/fileio/fileio.c =================================================================== --- trunk/usr/fileio/fileio.c 2007-07-05 14:39:37 UTC (rev 143) +++ trunk/usr/fileio/fileio.c 2007-07-05 16:23:09 UTC (rev 144) @@ -166,6 +166,10 @@ setlinebuf(stdout); + res = debug_init(); + if (res != 0) + goto out; + app_name = argv[0]; memset(&dev, 0, sizeof(dev)); @@ -254,7 +258,7 @@ #endif case 'v': printf("%s version %s\n", app_name, VERSION_STR); - goto out; + goto out_done; default: goto out_usage; } @@ -276,7 +280,7 @@ res = errno; PRINT_ERROR_PR("Unable to open file %s (%s)", dev.file_name, strerror(res)); - goto out; + goto out_done; } dev.file_size = lseek64(fd, 0, SEEK_END); @@ -367,7 +371,7 @@ res = dev.scst_usr_fd; PRINT_ERROR_PR("Unable to open SCST device %s (%s)", DEV_USER_PATH DEV_USER_NAME, strerror(res)); - goto out; + goto out_done; } memset(&desc, 0, sizeof(desc)); @@ -479,10 +483,13 @@ out_close: close(dev.scst_usr_fd); +out_done: + debug_done(); + out: return res; out_usage: usage(); - goto out; + goto out_done; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |