2 /*--------------------------------------------------------------------*/
3 /*--- The scheduler. pub_core_scheduler.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2010 Julian Seward
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.
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.
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
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PUB_CORE_SCHEDULER_H
32 #define __PUB_CORE_SCHEDULER_H
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 //--------------------------------------------------------------------
40 /* Allocate a new ThreadState */
41 extern ThreadId VG_(alloc_ThreadState)(void);
43 /* A thread exits. tid must currently be running. */
44 extern void VG_(exit_thread)(ThreadId tid);
46 /* 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. */
49 extern void VG_(get_thread_out_of_syscall)(ThreadId tid);
51 /* Nuke all threads except tid. */
52 extern void VG_(nuke_all_threads_except) ( ThreadId me,
53 VgSchedReturnCode reason );
55 /* Make a thread the running thread. The thread must previously been
56 sleeping, and not holding the CPU lock. This will set the
57 thread state to VgTs_Runnable, and the thread will attempt to take
58 the CPU lock. By the time it returns, tid will be the running
60 extern void VG_(acquire_BigLock) ( ThreadId tid, HChar* who );
62 /* Simple version, which simply acquires the lock, but does not mess
63 with the guest state in the same way as the non _LL version
65 extern void VG_(acquire_BigLock_LL) ( HChar* who );
67 /* Set a thread into a sleeping state. Before the call, the thread
68 must be runnable, and holding the CPU lock. When this call
69 returns, the thread will be set to the specified sleeping state,
70 and will not be holding the CPU lock. Note that another
71 thread could be running by the time this call returns, so the
72 caller must be careful not to touch any shared state. It is also
73 the caller's responsibility to actually block until the thread is
74 ready to run again. */
75 extern void VG_(release_BigLock) ( ThreadId tid,
76 ThreadStatus state, HChar* who );
78 /* Matching function to acquire_BigLock_LL. */
79 extern void VG_(release_BigLock_LL) ( HChar* who );
81 /* Yield the CPU for a while. Drops/acquires the lock using the
82 normal (non _LL) functions. */
83 extern void VG_(vg_yield)(void);
86 extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid );
88 // Initialise, phase 1. Zero out VG_(threads), decide on the root
89 // ThreadId and initialise the bigLock.
90 extern ThreadId VG_(scheduler_init_phase1) ( void );
92 // Initialise, phase 2. Is passed the extent of the root thread's
93 // client stack and the root ThreadId decided on by phase 1.
94 extern void VG_(scheduler_init_phase2) ( ThreadId main_tid,
98 // Allows to disable the polling done to detect vgdb input
99 // or to force a poll at next scheduler call.
100 extern void VG_(disable_vgdb_poll) (void );
101 extern void VG_(force_vgdb_poll) ( void );
103 /* nr of bbs done since startup. */
104 extern ULong VG_(bbs_done) (void);
107 extern void VG_(print_scheduler_stats) ( void );
109 /* If False, a fault is Valgrind-internal (ie, a bug) */
110 extern Bool VG_(in_generated_code);
112 /* Sanity checks which may be done at any time. The scheduler decides when. */
113 extern void VG_(sanity_check_general) ( Bool force_expensive );
115 #endif // __PUB_CORE_SCHEDULER_H
117 /*--------------------------------------------------------------------*/
119 /*--------------------------------------------------------------------*/