blob: e48849217b610a674b05224d48ddecc4691f17f4 [file] [log] [blame]
njn278b3d62005-05-30 23:20:51 +00001
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
njn278b3d62005-05-30 23:20:51 +000040/* Allocate a new ThreadState */
41extern ThreadId VG_(alloc_ThreadState)(void);
42
43/* A thread exits. tid must currently be running. */
44extern 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. */
49extern void VG_(kill_thread)(ThreadId tid);
50
njn278b3d62005-05-30 23:20:51 +000051/* Nuke all threads except tid. */
52extern 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. */
60extern 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. */
70extern void VG_(set_sleeping) ( ThreadId tid, ThreadStatus state );
71
72/* Yield the CPU for a while */
73extern void VG_(vg_yield)(void);
74
75// The scheduler.
76extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid );
77
njn278b3d62005-05-30 23:20:51 +000078extern void VG_(scheduler_init) ( void );
79
njn04e16982005-05-31 00:23:43 +000080/* Stats ... */
81extern void VG_(print_scheduler_stats) ( void );
82
njn278b3d62005-05-30 23:20:51 +000083// Longjmp back to the scheduler and thus enter the sighandler immediately.
84extern void VG_(resume_scheduler) ( ThreadId tid );
85
86/* If true, a fault is Valgrind-internal (ie, a bug) */
87extern Bool VG_(my_fault);
88
njn6676d5b2005-06-19 18:49:19 +000089/* Sanity checks which may be done at any time. The scheduler decides when. */
90extern void VG_(sanity_check_general) ( Bool force_expensive );
91
njn278b3d62005-05-30 23:20:51 +000092#endif // __PUB_CORE_SCHEDULER_H
93
94/*--------------------------------------------------------------------*/
95/*--- end ---*/
96/*--------------------------------------------------------------------*/