File: init_unwinder.c

package info (click to toggle)
multipath-tools 0.14.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,088 kB
  • sloc: ansic: 64,885; perl: 1,622; makefile: 742; sh: 732; pascal: 155
file content (40 lines) | stat: -rw-r--r-- 826 bytes parent folder | download
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
#include <pthread.h>
#include <unistd.h>
#include "init_unwinder.h"

static pthread_mutex_t dummy_mtx = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER;
static int dummy_started;

static void *dummy_thread(void *arg __attribute__((unused)))
{
	pthread_mutex_lock(&dummy_mtx);
	dummy_started = 1;
	pthread_cond_broadcast(&dummy_cond);
	pthread_mutex_unlock(&dummy_mtx);
	pause();
	return NULL;
}

int init_unwinder(void)
{
	pthread_t dummy;
	int rc;

	pthread_mutex_lock(&dummy_mtx);

	rc = pthread_create(&dummy, NULL, dummy_thread, NULL);
	if (rc != 0) {
		pthread_mutex_unlock(&dummy_mtx);
		return rc;
	}

	while (!dummy_started)
		pthread_cond_wait(&dummy_cond, &dummy_mtx);

	pthread_mutex_unlock(&dummy_mtx);

	rc = pthread_cancel(dummy);
	pthread_join(dummy, NULL);
	return rc;
}