summaryrefslogtreecommitdiff
path: root/src/evanix.c
blob: e83d0ea21ccb443d321bc7f649a79f914af7b293 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdlib.h>
#include <string.h>

#include "build.h"
#include "queue.h"
#include "util.h"

int main(void)
{
	struct queue_thread *queue_thread = NULL;
	struct build_thread *build_thread = NULL;
	FILE *stream = NULL;
	int ret = 0;

	ret = jobs_init(&stream);
	if (ret < 0)
		goto out_free;

	ret = queue_thread_new(&queue_thread, stream);
	if (ret < 0) {
		free(stream);
		goto out_free;
	}

	ret = build_thread_new(&build_thread, queue_thread->queue);
	if (ret < 0) {
		free(stream);
		goto out_free;
	}

	ret = pthread_create(&queue_thread->tid, NULL, queue_thread_entry,
			     queue_thread);
	if (ret < 0) {
		print_err("%s", strerror(ret));
		goto out_free;
	}

	ret = pthread_create(&build_thread->tid, NULL, build_thread_entry,
			     build_thread);
	if (ret < 0) {
		print_err("%s", strerror(ret));
		goto out_free;
	}

	ret = pthread_join(queue_thread->tid, NULL);
	if (ret < 0) {
		print_err("%s", strerror(ret));
		goto out_free;
	}

	ret = pthread_join(build_thread->tid, NULL);
	if (ret < 0) {
		print_err("%s", strerror(ret));
		goto out_free;
	}

out_free:
	queue_thread_free(queue_thread);
	free(build_thread);
	exit(ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}