njn | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- The scheduler. pub_core_scheduler.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
| 10 | Copyright (C) 2000-2005 Julian Seward |
| 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_CORE_SCHEDULER_H |
| 32 | #define __PUB_CORE_SCHEDULER_H |
| 33 | |
| 34 | //-------------------------------------------------------------------- |
| 35 | // PURPOSE: This module is the scheduler, which is the main loop |
| 36 | // controlling the running of all the program's threads. |
| 37 | // It's at the centre of everything. |
| 38 | //-------------------------------------------------------------------- |
| 39 | |
njn | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 40 | /* Allocate a new ThreadState */ |
| 41 | extern ThreadId VG_(alloc_ThreadState)(void); |
| 42 | |
| 43 | /* A thread exits. tid must currently be running. */ |
| 44 | extern void VG_(exit_thread)(ThreadId tid); |
| 45 | |
| 46 | /* Kill a thread. This interrupts whatever a thread is doing, and |
| 47 | makes it exit ASAP. This does not set the exitreason or |
| 48 | exitcode. */ |
| 49 | extern void VG_(kill_thread)(ThreadId tid); |
| 50 | |
njn | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 51 | /* Nuke all threads except tid. */ |
| 52 | extern void VG_(nuke_all_threads_except) ( ThreadId me, |
| 53 | VgSchedReturnCode reason ); |
| 54 | |
| 55 | /* Make a thread the running thread. The thread must previously been |
| 56 | sleeping, and not holding the CPU semaphore. This will set the |
| 57 | thread state to VgTs_Runnable, and the thread will attempt to take |
| 58 | the CPU semaphore. By the time it returns, tid will be the running |
| 59 | thread. */ |
| 60 | extern void VG_(set_running) ( ThreadId tid ); |
| 61 | |
| 62 | /* Set a thread into a sleeping state. Before the call, the thread |
| 63 | must be runnable, and holding the CPU semaphore. When this call |
| 64 | returns, the thread will be set to the specified sleeping state, |
| 65 | and will not be holding the CPU semaphore. Note that another |
| 66 | thread could be running by the time this call returns, so the |
| 67 | caller must be careful not to touch any shared state. It is also |
| 68 | the caller's responsibility to actually block until the thread is |
| 69 | ready to run again. */ |
| 70 | extern void VG_(set_sleeping) ( ThreadId tid, ThreadStatus state ); |
| 71 | |
| 72 | /* Yield the CPU for a while */ |
| 73 | extern void VG_(vg_yield)(void); |
| 74 | |
| 75 | // The scheduler. |
| 76 | extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid ); |
| 77 | |
njn | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 78 | extern void VG_(scheduler_init) ( void ); |
| 79 | |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 80 | /* Stats ... */ |
| 81 | extern void VG_(print_scheduler_stats) ( void ); |
| 82 | |
njn | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 83 | // Longjmp back to the scheduler and thus enter the sighandler immediately. |
| 84 | extern void VG_(resume_scheduler) ( ThreadId tid ); |
| 85 | |
| 86 | /* If true, a fault is Valgrind-internal (ie, a bug) */ |
| 87 | extern Bool VG_(my_fault); |
| 88 | |
njn | 6676d5b | 2005-06-19 18:49:19 +0000 | [diff] [blame^] | 89 | /* Sanity checks which may be done at any time. The scheduler decides when. */ |
| 90 | extern void VG_(sanity_check_general) ( Bool force_expensive ); |
| 91 | |
njn | 278b3d6 | 2005-05-30 23:20:51 +0000 | [diff] [blame] | 92 | #endif // __PUB_CORE_SCHEDULER_H |
| 93 | |
| 94 | /*--------------------------------------------------------------------*/ |
| 95 | /*--- end ---*/ |
| 96 | /*--------------------------------------------------------------------*/ |