summaryrefslogtreecommitdiff
path: root/wg.c
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-03-11 19:34:18 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-03-11 19:34:18 -0500
commita0a8aaf5170eab149ee0fed4d7846e0df856a2e4 (patch)
tree8e301f0c0279bdd5b592f1c63004b650fab3470f /wg.c
parent77f1df1a250d958317c930e6f3a36edf42f11d09 (diff)
split into separate executables
Diffstat (limited to 'wg.c')
-rw-r--r--wg.c43
1 files changed, 0 insertions, 43 deletions
diff --git a/wg.c b/wg.c
deleted file mode 100644
index 3208aa1..0000000
--- a/wg.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <unistd.h>
-#include <error.h>
-#include <errno.h>
-
-#include "wg.h"
-
-/* Thread management tools modeled on https://golang.org/pkg/sync/#WaitGroup */
-
-/* pthread_cond_t is overly complicated. Just use a self-pipe. */
-
-void wg_init(struct wg *wg) {
- wg->count = 0;
- pthread_mutex_init(&wg->lock, NULL);
- int fds[2];
- if (pipe(fds) != 0)
- error(1, errno, "pipe");
- wg->fd_wait = fds[0];
- wg->fd_signal = fds[1];
-}
-
-void wg_add(struct wg *wg, unsigned int n) {
- pthread_mutex_lock(&wg->lock);
- wg->count += n;
- pthread_mutex_unlock(&wg->lock);
-}
-
-void wg_sub(struct wg *wg, unsigned int n) {
- pthread_mutex_lock(&wg->lock);
- wg->count -= n;
- if (wg->count == 0)
- write(wg->fd_signal, " ", 1);
- pthread_mutex_unlock(&wg->lock);
-}
-
-void wg_wait(struct wg *wg) {
- char b;
- retry:
- if (read(wg->fd_wait, &b, 1) == -1) {
- if (errno == EINTR)
- goto retry;
- error(1, errno, "wg_wait");
- }
-}