Don't include pub_tool_tooliface.h in priv_types_n_macros.h
[valgrind.git] / coregrind / m_scheduler / sched-lock-generic.c
blob93e8ffe6a2f107a5c76d41b13a5caac01c06770a
2 /*--------------------------------------------------------------------*/
3 /*--- Generic scheduler lock implementation sched-lock-generic.c ---*/
4 /*--- ---*/
5 /*--- This implementation does not guarantee fair scheduling on ---*/
6 /*--- multicore systems but is sufficient to make the Valgrind ---*/
7 /*--- scheduler work reasonably. ---*/
8 /*--------------------------------------------------------------------*/
11 This file is part of Valgrind, a dynamic binary instrumentation
12 framework.
14 Copyright (C) 2011-2017 Bart Van Assche <bvanassche@acm.org>.
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation; either version 2 of the
19 License, or (at your option) any later version.
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, see <http://www.gnu.org/licenses/>.
29 The GNU General Public License is contained in the file COPYING.
32 #include "pub_core_basics.h"
33 #include "pub_core_mallocfree.h"
34 #include "priv_sema.h"
35 #include "priv_sched-lock.h"
36 #include "priv_sched-lock-impl.h"
38 struct sched_lock {
39 vg_sema_t sema;
42 static const HChar *get_sched_lock_name(void)
44 return "generic";
47 static struct sched_lock *create_sched_lock(void)
49 struct sched_lock *p;
51 p = VG_(malloc)("sched_lock", sizeof(*p));
52 ML_(sema_init)(&p->sema);
53 return p;
56 static void destroy_sched_lock(struct sched_lock *p)
58 ML_(sema_deinit)(&p->sema);
59 VG_(free)(p);
62 static int get_sched_lock_owner(struct sched_lock *p)
64 return p->sema.owner_lwpid;
67 static void acquire_sched_lock(struct sched_lock *p)
69 ML_(sema_down)(&p->sema, False);
72 static void release_sched_lock(struct sched_lock *p)
74 ML_(sema_up)(&p->sema, False);
77 const struct sched_lock_ops ML_(generic_sched_lock_ops) = {
78 .get_sched_lock_name = get_sched_lock_name,
79 .create_sched_lock = create_sched_lock,
80 .destroy_sched_lock = destroy_sched_lock,
81 .get_sched_lock_owner = get_sched_lock_owner,
82 .acquire_sched_lock = acquire_sched_lock,
83 .release_sched_lock = release_sched_lock,