blob: 848ec0b4fc6c48673f46491b96616cf8cc5e1866 [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
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2000-2007 Julian Seward
njn278b3d62005-05-30 23:20:51 +000011 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
sewardjf54342a2006-10-17 01:51:24 +000046/* If 'tid' is blocked in a syscall, send it SIGVGKILL so as to get it
47 out of the syscall and onto doing the next thing, whatever that is.
48 If it isn't blocked in a syscall, has no effect on the thread. */
49extern void VG_(get_thread_out_of_syscall)(ThreadId tid);
njn278b3d62005-05-30 23:20:51 +000050
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
sewardjf54342a2006-10-17 01:51:24 +000056 sleeping, and not holding the CPU lock. This will set the
njn278b3d62005-05-30 23:20:51 +000057 thread state to VgTs_Runnable, and the thread will attempt to take
sewardjf54342a2006-10-17 01:51:24 +000058 the CPU lock. By the time it returns, tid will be the running
njn278b3d62005-05-30 23:20:51 +000059 thread. */
sewardjad0a3a82006-12-17 18:58:55 +000060extern void VG_(acquire_BigLock) ( ThreadId tid, HChar* who );
njn278b3d62005-05-30 23:20:51 +000061
62/* Set a thread into a sleeping state. Before the call, the thread
sewardjf54342a2006-10-17 01:51:24 +000063 must be runnable, and holding the CPU lock. When this call
njn278b3d62005-05-30 23:20:51 +000064 returns, the thread will be set to the specified sleeping state,
sewardjf54342a2006-10-17 01:51:24 +000065 and will not be holding the CPU lock. Note that another
njn278b3d62005-05-30 23:20:51 +000066 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. */
sewardjad0a3a82006-12-17 18:58:55 +000070extern void VG_(release_BigLock) ( ThreadId tid, ThreadStatus state, HChar* who );
njn278b3d62005-05-30 23:20:51 +000071
72/* Yield the CPU for a while */
73extern void VG_(vg_yield)(void);
74
75// The scheduler.
76extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid );
77
sewardj45f4e7c2005-09-27 19:20:21 +000078// Initialise. Is passed the extent of the root thread's client stack.
79extern void VG_(scheduler_init) ( Addr clstack_end, SizeT clstack_size );
njn278b3d62005-05-30 23:20:51 +000080
njn04e16982005-05-31 00:23:43 +000081/* Stats ... */
82extern void VG_(print_scheduler_stats) ( void );
83
sewardj0ec07f32006-01-12 12:32:32 +000084/* If False, a fault is Valgrind-internal (ie, a bug) */
85extern Bool VG_(in_generated_code);
njn278b3d62005-05-30 23:20:51 +000086
njn6676d5b2005-06-19 18:49:19 +000087/* Sanity checks which may be done at any time. The scheduler decides when. */
88extern void VG_(sanity_check_general) ( Bool force_expensive );
89
njn278b3d62005-05-30 23:20:51 +000090#endif // __PUB_CORE_SCHEDULER_H
91
92/*--------------------------------------------------------------------*/
93/*--- end ---*/
94/*--------------------------------------------------------------------*/