diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-07 17:40:43 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2010-12-07 17:40:43 -0500 |
commit | 2dfd49894f8638f166654885081a24228d7b41c8 (patch) | |
tree | 63d74fb0788df8db25928e8f10a679ddf2cc5b13 | |
parent | 38fc568607fcad4de5bf198d5182a73eb18d7e98 (diff) | |
download | NetNuke2-2dfd49894f8638f166654885081a24228d7b41c8.tar.gz |
For each pass attempt to lock the mutex. If the mutex locks then write, if not, wait for cputime.
-rw-r--r-- | src/nukectl.c | 27 |
1 files 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); |