Branch: Tag:

2004-12-30

2004-12-30 13:50:35 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Don't pass exit codes to handle_error().
Added Thread()->kill().

Rev: src/threads.c:1.241
Rev: src/threads.h:1.130

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: threads.c,v 1.240 2004/09/18 20:50:56 nilsson Exp $ + || $Id: threads.c,v 1.241 2004/12/30 13:50:35 grubba Exp $   */      #ifndef CONFIGURE_TEST
853:       if(SETJMP(back))    { -  if(throw_severity < THROW_EXIT) +  if(throw_severity <= THROW_ERROR)    call_handle_error();    if(throw_severity == THROW_EXIT)    {
1713:   static void check_thread_interrupt(struct callback *foo,    void *bar, void *gazonk)   { -  if (Pike_interpreter.thread_state->flags & THREAD_FLAG_INTR) { -  Pike_interpreter.thread_state->flags &= ~THREAD_FLAG_INTR; +  if (Pike_interpreter.thread_state->flags & THREAD_FLAG_SIGNAL_MASK) { +  if (Pike_interpreter.thread_state->flags & THREAD_FLAG_TERM) { +  throw_severity = THROW_THREAD_EXIT; +  } else { +  throw_severity = THROW_ERROR; +  } +  Pike_interpreter.thread_state->flags &= ~THREAD_FLAG_SIGNAL_MASK;    if (!--num_pending_interrupts) {    remove_callback(foo);    thread_interrupt_callback = NULL;    } -  +  if (throw_severity == THROW_ERROR) {    Pike_error("Interrupted.\n"); -  +  } else { +  push_int(-1); +  assign_svalue(&throw_value, Pike_sp-1); +  pike_throw();    }    } -  + }      /*! @decl void interrupt()    *! @decl void interrupt(string msg)
1739:    /* FIXME: The msg argument is not supported yet. */    pop_n_elems(args);    -  if (!(THIS_THREAD->flags & THREAD_FLAG_INTR)) { +  if (!(THIS_THREAD->flags & THREAD_FLAG_SIGNAL_MASK)) {    THIS_THREAD->flags |= THREAD_FLAG_INTR;    num_pending_interrupts++;    if (!thread_interrupt_callback) {
1751:    push_int(0);   }    + /*! @decl void kill() +  *! +  *! Interrupt the thread, and terminate it. +  *! +  *! @note +  *! Interrupts are asynchronous, and are currently not queued. +  */ + static void f_thread_id_kill(INT32 args) + { +  pop_n_elems(args); +  +  if (!(THIS_THREAD->flags & THREAD_FLAG_SIGNAL_MASK)) { +  num_pending_interrupts++; +  if (!thread_interrupt_callback) { +  thread_interrupt_callback = +  add_to_callback(&evaluator_callbacks, check_thread_interrupt, 0, 0); +  } +  /* FIXME: Actually interrupt the thread. */ +  } +  THIS_THREAD->flags |= THREAD_FLAG_TERM; +  push_int(0); + } +    void init_thread_obj(struct object *o)   {    MEMSET(&THIS_THREAD->state, 0, sizeof(struct Pike_interpreter));
1771:      void exit_thread_obj(struct object *o)   { -  if (THIS_THREAD->flags & THREAD_FLAG_INTR) { -  Pike_interpreter.thread_state->flags &= ~THREAD_FLAG_INTR; +  if (THIS_THREAD->flags & THREAD_FLAG_SIGNAL_MASK) { +  Pike_interpreter.thread_state->flags &= ~THREAD_FLAG_SIGNAL_MASK;    if (!--num_pending_interrupts) {    remove_callback(thread_interrupt_callback);    thread_interrupt_callback = NULL;
2202:    ADD_FUNCTION("id_number",f_thread_id_id_number,tFunc(tNone,tInt),0);    ADD_FUNCTION("interrupt", f_thread_id_interrupt,    tFunc(tOr(tVoid,tStr), tVoid), 0); +  ADD_FUNCTION("kill", f_thread_id_kill, tFunc(tNone, tVoid), 0);    set_gc_recurse_callback(thread_was_recursed);    set_gc_check_callback(thread_was_checked);    set_init_callback(init_thread_obj);