From c7ec88c88adb4f15b154ad125977d9c2c4ae4956 Mon Sep 17 00:00:00 2001 From: "berkeviktor@aol.com" Date: Fri, 2 Apr 2010 07:29:16 +0200 Subject: move additions to own repo, so that patch contains only modifications --- plugins/dns/thread.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 plugins/dns/thread.c (limited to 'plugins/dns/thread.c') diff --git a/plugins/dns/thread.c b/plugins/dns/thread.c new file mode 100644 index 00000000..aa153137 --- /dev/null +++ b/plugins/dns/thread.c @@ -0,0 +1,111 @@ +#include + +#define USE_PTHREAD + +#ifdef WIN32 + +#include +#define pthread_t DWORD +#define pipe(a) _pipe(a,4096,_O_BINARY) + +#else +#ifdef USE_PTHREAD + +#include + +#else + +#include +#include +#include +#define pthread_t int + +#endif +#endif + + +typedef struct +{ + pthread_t threadid; + int pipe_fd[2]; + void *userdata; +} thread; + +thread * +thread_new (void) +{ + thread *th; + + th = calloc (1, sizeof (*th)); + if (!th) + return NULL; + + if (pipe (th->pipe_fd) == -1) + { + free (th); + return NULL; + } + +#ifdef __EMX__ /* os/2 */ + setmode (pipe_fd[0], O_BINARY); + setmode (pipe_fd[1], O_BINARY); +#endif + + return th; +} + +int +thread_start (thread *th, void *(*start_routine)(void *), void *arg) +{ + pthread_t id; + +#ifdef WIN32 + CloseHandle (CreateThread (NULL, 0, + (LPTHREAD_START_ROUTINE)start_routine, + arg, 0, (DWORD *)&id)); +#else +#ifdef USE_PTHREAD + if (pthread_create (&id, NULL, start_routine, arg) != 0) + return 0; +#else + switch (id = fork ()) + { + case -1: + return 0; + case 0: + /* this is the child */ + setuid (getuid ()); + start_routine (arg); + _exit (0); + } +#endif +#endif + + th->threadid = id; + + return 1; +} + +/*void +thread_kill (thread *th) +{ +#ifdef WIN32 + PostThreadMessage (th->threadid, WM_QUIT, 0, 0); +#else +#ifdef USE_PTHREAD + pthread_cancel (th->threadid); + pthread_join (th->threadid, (void *)&th); +#else + kill (th->threadid, SIGKILL); + waitpid (th->threadid, NULL, 0); +#endif +#endif +} + +void +thread_free (thread *th) +{ + close (th->pipe_fd[0]); + close (th->pipe_fd[1]); + free (th); +}*/ -- cgit 1.4.1