2011-08-22
2011-08-22 20:45:39 by Martin Stjernholm <mast@lysator.liu.se>
-
34fe1e8f1d98af1449493dfc636b4d5ca78c8e27
(31 lines)
(+24/-7)
[
Show
| Annotate
]
Branch: 5.2
Keep track of the background_run thread.
Rev: server/base_server/roxen.pike:1.1085
6:
// Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.
// ABS and suicide systems contributed freely by Francesco Chemolli
- constant cvs_version="$Id: roxen.pike,v 1.1084 2011/08/15 14:13:48 grubba Exp $";
+ constant cvs_version="$Id: roxen.pike,v 1.1085 2011/08/22 20:45:39 mast Exp $";
//! @appears roxen
//!
684: Inside #if undefined(NO_SLOW_REQ_BT)
protected void slow_be_after_cb()
{
+ // FIXME: This should try to compensate for delays due to the pike
+ // gc, because it just causes noise here.
#ifdef DEBUG
if (this_thread() != backend_thread) error ("Run from wrong thread.\n");
#endif
1216: Inside #if defined(THREADS)
#ifdef THREADS
protected Thread.Queue bg_queue = Thread.Queue();
- protected int bg_process_running;
+ protected Thread.Thread bg_process_thread;
// Use a time buffer to strike a balance if the server is busy and
// always have at least one busy thread: The maximum waiting time in
1245: Inside #if defined(THREADS)
protected void bg_process_queue()
{
- if (bg_process_running) return;
+ if (bg_process_thread) return;
// Relying on the interpreter lock here.
- bg_process_running = 1;
+ bg_process_thread = this_thread();
int maxbeats =
min (time() - bg_last_busy, bg_time_buffer_max) * (int) (1 / 0.01);
1355: Inside #if defined(THREADS) and #if undefined(NO_SLOW_REQ_BT)
#ifndef NO_SLOW_REQ_BT
if (call_out) monitor->remove_call_out (call_out);
#endif
- bg_process_running = 0;
+ bg_process_thread = 0;
handle (bg_process_queue);
throw (err);
}
- bg_process_running = 0;
+ bg_process_thread = 0;
if (bg_queue->size()) {
handle (bg_process_queue);
// Sleep a short while to encourage a thread switch. This is a
1370:
}
#endif
+ Thread.Thread background_run_thread()
+ //! Returns the thread currently executing the background_run queue,
+ //! or 0 if it isn't being processed.
+ {
+ #ifdef THREADS
+ return bg_process_thread;
+ #else
+ // FIXME: This is not correct. Should return something nonzero when
+ // called from the call out. But noone is running without threads
+ // nowadays anyway.
+ return 0;
+ #endif
+ }
+
mixed background_run (int|float delay, function func, mixed... args)
//! Enqueue a task to run in the background in a way that makes as
//! little impact as possible on the incoming requests. No matter how
1426: Inside #if defined(THREADS)
mixed `()()
{
bg_queue->write (({func, args}));
- if (!bg_process_running)
+ if (!bg_process_thread)
handle (bg_process_queue);
}
};