2002-09-14
2002-09-14 02:58:33 by Martin Stjernholm <mast@lysator.liu.se>
-
7ee4aa785dd022e28f73084fa4d79e2eef4d3c66
(29 lines)
(+22/-7)
[
Show
| Annotate
]
Branch: 7.9
Added fallback to clock() in check_threads if gethrtime doesn't exist, to
avoid very frequent context switches. Put the gethrtime check behind the
divisor check since gethrtime isn't entirely cheap.
Rev: src/pike_threadlib.h:1.20
Rev: src/threads.c:1.184
1:
#include "global.h"
- RCSID("$Id: threads.c,v 1.183 2002/09/14 02:50:50 mast Exp $");
+ RCSID("$Id: threads.c,v 1.184 2002/09/14 02:58:33 mast Exp $");
PMOD_EXPORT int num_threads = 1;
PMOD_EXPORT int threads_disabled = 0;
197:
pthread_attr_t small_pattr;
#endif
PMOD_EXPORT ptrdiff_t thread_storage_offset;
+ #ifdef USE_CLOCK_FOR_SLICES
+ PMOD_EXPORT clock_t thread_start_clock = 0;
+ #endif
struct thread_starter
{
618: Inside #if undefined(HAVE_NO_YIELD)
/* If we have no yield we can't cut calls here since it's possible
* that a thread switch will take place only occasionally in the
* window below. */
- #ifdef HAVE_GETHRTIME
- static long long last_;
- if( gethrtime()-last_ < 50000000 ) /* 0.05s slice */
- return;
- last_ = gethrtime();
- #else
+
static int div_;
if(div_++ & 255)
return;
-
+ #ifdef HAVE_GETHRTIME
+ {
+ static hrtime_t last_ = 0;
+ hrtime_t now = gethrtime();
+ if( now-last_ < 50000000 ) /* 0.05s slice */
+ return;
+ last_ = now;
+ }
+ #elif defined (USE_CLOCK_FOR_SLICES)
+ if (clock() - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20))
+ return;
#endif
#endif
645:
th_yield();
THREADS_DISALLOW();
+ #ifdef USE_CLOCK_FOR_SLICES
+ /* Must set the base time for the slice here since clock() returns
+ * thread local time. */
+ thread_start_clock = clock();
+ #endif
+
DO_IF_DEBUG(
if(thread_for_id(th_self()) != Pike_interpreter.thread_id) {
debug_list_all_threads();