rem: if (t->state == B_THREAD_SUSPENDED) { t->state = t->next_state = B_THREAD_READY; thread_enqueue_run_q(t); } else if (t->state == B_THREAD_WAITING) sem_interrupt_thread(t);
add: if (thread->state == B_THREAD_SUSPENDED) { thread->state = thread->next_state = B_THREAD_READY; scheduler_enqueue_in_run_queue(thread); } else if (thread->state == B_THREAD_WAITING) sem_interrupt_thread(thread);
context: send_signal_etc(pid_t tid, uint sig, uint32 flags){	int state;	struct thread *t, *main_t;		if ((sig < 1) || (sig > MAX_SIGNO))		return B_BAD_VALUE;		state = disable_interrupts();	GRAB_THREAD_LOCK();		t = thread_get_thread_struct_locked(tid);	if (!t) {		RELEASE_THREAD_LOCK();		restore_interrupts(state);		return B_BAD_THREAD_ID;	}	// XXX check permission		// Signals to kernel threads will only wake them up	if (t->team == team_get_kernel_team()) {		if (t->state == B_THREAD_SUSPENDED) {			t->state = t->next_state = B_THREAD_READY;			thread_enqueue_run_q(t);		}	}	else {		t->sig_pending |= (1L << (sig - 1));				switch (sig) {			case SIGKILL:				// Forward KILLTHR to the main thread of the team				main_t = t->team->main_thread;				main_t->sig_pending |= (1L << (SIGKILLTHR - 1));				// Wake up main thread				if (main_t->state == B_THREAD_SUSPENDED) {					main_t->state = main_t->next_state = B_THREAD_READY;					thread_enqueue_run_q(main_t);				} else if (main_t->state == B_THREAD_WAITING)					sem_interrupt_thread(main_t);				// Fallthrough			case SIGKILLTHR:				// Wake up suspended threads and interrupt waiting ones				if (t->state == B_THREAD_SUSPENDED) {					t->state = t->next_state = B_THREAD_READY;					thread_enqueue_run_q(t);				} else if (t->state == B_THREAD_WAITING)					sem_interrupt_thread(t);				break;			case SIGCONT:				// Wake up thread if it was suspended				if (t->state == B_THREAD_SUSPENDED) {					t->state = t->next_state = B_THREAD_READY;					thread_enqueue_run_q(t);				}				break;			default:				if (t->sig_pending & ((~t->sig_block_mask) | (1L << (SIGCHLD - 1)))) {					// Interrupt thread if it was waiting					if (t->state == B_THREAD_WAITING)						sem_interrupt_thread(t);				}				break;		}	}		if (!(flags & B_DO_NOT_RESCHEDULE))		resched(); //XXX really here, while interrupts are disabled?		RELEASE_THREAD_LOCK();	restore_interrupts(state);		return B_OK;}