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;
}
|