diff options
author | Fernando Carrijo <fcarrijo@yahoo.com.br> | 2010-08-14 06:52:30 -0300 |
---|---|---|
committer | Fernando Carrijo <fcarrijo@yahoo.com.br> | 2010-08-14 06:52:30 -0300 |
commit | 6b79e8974bd70e5b2d20cbaffc704299a32a9b46 (patch) | |
tree | 1a3bc7c6ca094e5ec538049930d48289a4d04af7 | |
parent | 39c3af6ab4de25c7e5aa890246ca04c4cf84f0fa (diff) |
os: inputthread: Close the input thread with pthread_cancel
This is more portable and more manageable than using syscall.
-rw-r--r-- | os/inputthread.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/os/inputthread.c b/os/inputthread.c index c7e0450e5..a7b45b39d 100644 --- a/os/inputthread.c +++ b/os/inputthread.c @@ -30,13 +30,12 @@ #include <dix-config.h> #endif -#include <pthread.h> - #include <stdio.h> #include <stdlib.h> -#include <sys/syscall.h> #include <unistd.h> #include <errno.h> +#include <pthread.h> + #include <X11/Xpoll.h> #include "inputstr.h" @@ -51,13 +50,13 @@ typedef struct _ThreadDeviceFunc { ThreadDeviceFunc ThreadDevFunc[MAXDEVICES]; +static pthread_t InputThread; + extern fd_set InputThreadFd; extern int NumDevicesThreaded; extern int InputThreadReadPipe; extern int InputThreadWritePipe; -static pid_t tid_generation; - /* * Create connections in the input thread. Must be called by the * DDX implementation. @@ -94,8 +93,6 @@ WaitForInput(void* argument) int i; fd_set ReadyInputDevices; - tid_generation = syscall(__NR_gettid); - FD_ZERO(&ReadyInputDevices); while (1) @@ -138,7 +135,6 @@ WaitForInput(void* argument) void CreateInputThread (void) { - pthread_t input_thread; pthread_attr_t attr; pthread_attr_init(&attr); @@ -154,7 +150,7 @@ CreateInputThread (void) if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0) perror("error setting input thread stack size"); - pthread_create(&input_thread, &attr, &WaitForInput, NULL); + pthread_create(&InputThread, &attr, &WaitForInput, NULL); pthread_attr_destroy (&attr); } @@ -164,9 +160,10 @@ CreateInputThread (void) void CloseInputThread (void) { + pthread_cancel(InputThread); + pthread_join(InputThread, NULL); + RemoveGeneralSocket(InputThreadReadPipe); FD_ZERO(&InputThreadFd); NumDevicesThreaded = 0; - - syscall(__NR_tkill, tid_generation); } |