[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Evil nanosleep hack committed to GNU Chess CVS
From: |
Chess |
Subject: |
Re: Evil nanosleep hack committed to GNU Chess CVS |
Date: |
Sun, 02 Mar 2003 23:03:38 -0600 |
On Thu, 19 Dec 2002 15:26:12 +0000
Simon Waters wrote:
>
> I stuck a 50000000 nanosecond sleep in wait_for_input, in lieu
> of someone sending me a "Posix threads for dummy's (well IQ less
> than 170)" document.
>
Here's an alternative to the nanosecond hack:
I've added a condition_wait to input.c, wait_for_input(),
and I renamed the condition variables.
The condition variable in wait_for_input() is the real input_cond.
The condition variable in input_func() is really a handshake_cond or
wakeup_cond.
Well anyhow, that's my view. :-)
[output from gnu diff]
101a102,104
> static pthread_mutex_t wakeup_mutex = PTHREAD_MUTEX_INITIALIZER;
> static pthread_cond_t wakeup_cond = PTHREAD_COND_INITIALIZER;
>
115c119
< pthread_cond_wait(&input_cond, &input_mutex);
---
> pthread_cond_signal(&input_cond);
116a121,124
>
> pthread_mutex_lock(&wakeup_mutex);
> pthread_cond_wait(&wakeup_cond, &wakeup_mutex);
> pthread_mutex_unlock(&wakeup_mutex);
123,124c131,132
< pthread_mutex_lock(&input_mutex);
< pthread_cond_signal(&input_cond);
---
> pthread_mutex_lock(&wakeup_mutex);
> pthread_cond_signal(&wakeup_cond);
126c134
< pthread_mutex_unlock(&input_mutex);
---
> pthread_mutex_unlock(&wakeup_mutex);
129,130d136
< /* XXX: The following definitely needs improvement. --Lukas */
<
133,141d138
< #ifdef NANOSLEEP
< struct timespec delay, remains;
< delay.tv_sec=0;
< delay.tv_nsec=50000000; /* 50 milliseconds */
< #else
< #ifdef USLEEP
< unsigned long usec=50000 ; /* 50 milliseconds */
< #endif
< #endif
143,150c140,142
<
< #ifdef NANOSLEEP
< nanosleep(&delay,&remains);
< #else
< #ifdef USLEEP
< usleep(usec);
< #endif
< #endif
---
> pthread_mutex_lock(&input_mutex);
> pthread_cond_wait(&input_cond, &input_mutex);
> pthread_mutex_unlock(&input_mutex);
152d143
< // while (input_status == INPUT_NONE) /* Busy loop */ ;
- - - - - - - - - - -
http://web.wt.net/~chess/
- Re: Evil nanosleep hack committed to GNU Chess CVS,
Chess <=