From 2dfd49894f8638f166654885081a24228d7b41c8 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 7 Dec 2010 17:40:43 -0500 Subject: For each pass attempt to lock the mutex. If the mutex locks then write, if not, wait for cputime. --- src/nukectl.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/nukectl.c b/src/nukectl.c index d2853cb..82d9e94 100644 --- a/src/nukectl.c +++ b/src/nukectl.c @@ -69,13 +69,9 @@ void* wipe(void* device) { pthread_mutex_lock(&lock_global); d->blksz = blksz_override; - d->blks = (d->blks / d->blksz); + //d->blks = (d->blks / d->blksz); pthread_mutex_unlock(&lock_global); } - else - { - d->blks = d->blksz * d->blks; - } int fd = open(d->path, O_WRONLY | O_SYNC); if(fd < 0) @@ -86,15 +82,24 @@ void* wipe(void* device) COM(self, "%s, block size %d, blocks %llu, total bytes %llu\n", d->path, d->blksz, d->blks, d->sz); srand(nngetseed()); - while(bytes_written < d->sz) + while(bytes_written <= d->sz) { - if(verbose_flag) + if((pthread_mutex_trylock(&lock_global))) { - percent = (long double)((bytes_written / (long double)d->sz) * 100); - printf("%s: %llu of %llu (%0.2Lf%%)\n", d->path, bytes_written, d->sz, percent); - } + //COM(self, "tid %X %X got lock_global\n", pthread_self()); + if(verbose_flag) + { + percent = (long double)((bytes_written / (long double)d->sz) * 100); + printf("%s: %llu of %llu (%0.2Lf%%)\n", d->path, bytes_written, d->sz, percent); + } - bytes_written += nnwrite(fd, d->blksz); + bytes_written += nnwrite(fd, d->blksz); + pthread_mutex_unlock(&lock_global); + } + else + { + //COM(self, "tid %X %X did not get lock_global\n", pthread_self()); + } } COM(self, "%s complete\n", d->path); pthread_exit(NULL); -- cgit