Skip to content

Commit

Permalink
Remove destruct() from yarn and usage from pigz.
Browse files Browse the repository at this point in the history
Remove destruct() to avoid dependence on pthread_cancel(), where
that thread operation is not available on many platforms. This is
in preparation for providing a Windows port of pigz.
  • Loading branch information
madler committed May 9, 2018
1 parent 176b3ab commit 43752cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
18 changes: 6 additions & 12 deletions pigz.c
Expand Up @@ -3177,6 +3177,8 @@ local void outb_check(void *dummy) {
// write and check threads and return for more decompression while that's going
// on (or just write and check if no threads or if proc == 1).
local int outb(void *desc, unsigned char *buf, unsigned len) {
(void)desc;

#ifndef NOTHREAD
static thread *wr, *ch;

Expand Down Expand Up @@ -3205,14 +3207,8 @@ local int outb(void *desc, unsigned char *buf, unsigned len) {
// if requested with len == 0, clean up -- terminate and join write and
// check threads, free lock
if (len == 0 && outb_write_more != NULL) {
if (desc != NULL) {
destruct(ch);
destruct(wr);
}
else {
join(ch);
join(wr);
}
join(ch);
join(wr);
free_lock(outb_check_more);
free_lock(outb_write_more);
outb_write_more = NULL;
Expand All @@ -3225,8 +3221,6 @@ local int outb(void *desc, unsigned char *buf, unsigned len) {
}
#endif

(void)desc;

// if just one process or no threads, then do it without threads
if (len) {
if (g.decode == 1)
Expand Down Expand Up @@ -3817,7 +3811,7 @@ local void process(char *path) {
punt(err);
complain("skipping: %s", err.why);
drop(err);
outb(&g, NULL, 0);
outb(NULL, NULL, 0);
}
load_end();
return;
Expand Down Expand Up @@ -3918,7 +3912,7 @@ local void process(char *path) {
punt(err);
complain("skipping: %s", err.why);
drop(err);
outb(g.outf, NULL, 0);
outb(NULL, NULL, 0);
if (g.outd != -1 && g.outd != 1) {
close(g.outd);
g.outd = -1;
Expand Down
16 changes: 3 additions & 13 deletions yarn.c
@@ -1,6 +1,6 @@
/* yarn.c -- generic thread operations implemented using pthread functions
* Copyright (C) 2008, 2011, 2012, 2015 Mark Adler
* Version 1.4 19 Jan 2015 Mark Adler
* Copyright (C) 2008, 2011, 2012, 2015, 2018 Mark Adler
* Version 1.5 8 May 2018 Mark Adler
* For conditions of distribution and use, see copyright notice in yarn.h
*/

Expand All @@ -19,6 +19,7 @@
Fix documentation in yarn.h for yarn_prefix
1.4 19 Jan 2015 Allow yarn_abort() to avoid error message to stderr
Accept and do nothing for NULL argument to free_lock()
1.5 8 May 2018 Remove destruct() to avoid use of pthread_cancel()
*/

/* for thread portability */
Expand Down Expand Up @@ -367,14 +368,3 @@ int join_all(void)
release(&(threads_lock));
return count;
}

/* cancel and join the thread -- the thread will cancel when it gets to a file
operation, a sleep or pause, or a condition wait */
void destruct(thread *off_course)
{
int ret;

if ((ret = pthread_cancel(off_course->id)) != 0)
fail(ret);
join(off_course);
}
9 changes: 2 additions & 7 deletions yarn.h
@@ -1,6 +1,6 @@
/* yarn.h -- generic interface for thread operations
* Copyright (C) 2008, 2011, 2012, 2015 Mark Adler
* Version 1.4 19 Jan 2015 Mark Adler
* Copyright (C) 2008, 2011, 2012, 2015, 2018 Mark Adler
* Version 1.5 8 May 2018 Mark Adler
*/

/*
Expand Down Expand Up @@ -63,10 +63,6 @@
the count of the number of threads joined (join_all() should only be
called from the main thread, and should only be called after any calls
of join() have completed)
destruct(thread) - terminate the thread in mid-execution and join it
(depending on the implementation, the termination may not be immediate,
but may wait for the thread to execute certain thread or file i/o
operations)
-- Lock functions --
Expand Down Expand Up @@ -118,7 +114,6 @@ typedef struct thread_s thread;
thread *launch(void (*)(void *), void *);
void join(thread *);
int join_all(void);
void destruct(thread *);

typedef struct lock_s lock;
lock *new_lock(long);
Expand Down

0 comments on commit 43752cc

Please sign in to comment.