c-index-test: Run inside a separate thread iff we have pthread support, to

ensure we at least get some minimal testing of running in a multithreaded
environment (for example, having a reduced stack size).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115200 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2010-09-30 20:39:47 +00:00
Родитель c69e1cf043
Коммит 6edc8001f2
1 изменённых файлов: 55 добавлений и 1 удалений

Просмотреть файл

@ -1478,7 +1478,9 @@ static void print_usage(void) {
" scan-function - scan function bodies (non-PCH)\n\n");
}
int main(int argc, const char **argv) {
/***/
int cindextest_main(int argc, const char **argv) {
clang_enableStackTraces();
if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
return perform_code_completion(argc, argv, 0);
@ -1538,3 +1540,55 @@ int main(int argc, const char **argv) {
print_usage();
return 1;
}
/***/
/* We intentionally run in a separate thread to ensure we at least minimal
* testing of a multithreaded environment (for example, having a reduced stack
* size). */
#include "llvm/Config/config.h"
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
typedef struct thread_info {
int argc;
const char **argv;
int result;
} thread_info;
void *thread_runner(void *client_data_v) {
thread_info *client_data = client_data_v;
client_data->result = cindextest_main(client_data->argc, client_data->argv);
return 0;
}
int main(int argc, const char **argv) {
thread_info client_data;
pthread_t thread;
int res;
client_data.argc = argc;
client_data.argv = argv;
res = pthread_create(&thread, 0, thread_runner, &client_data);
if (res != 0) {
perror("thread creation failed");
return 1;
}
res = pthread_join(thread, 0);
if (res != 0) {
perror("thread join failed");
return 1;
}
return client_data.result;
}
#else
int main(int argc, const char **argv) {
return cindextest_main(argc, argv);
}
#endif