drd: Add a consistency check
[valgrind.git] / coregrind / m_scheduler / sched-lock.c
blobdd25321946edb5f52c9a375932e78525c334d8c5
2 /*--------------------------------------------------------------------*/
3 /*--- Scheduler lock support functions sched-lock.c ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2011-2013 Bart Van Assche <bvanassche@acm.org>.
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
27 The GNU General Public License is contained in the file COPYING.
30 #include "config.h"
31 #include "pub_core_basics.h"
32 #include "pub_core_libcbase.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 static struct sched_lock_ops const *sched_lock_ops =
39 &ML_(generic_sched_lock_ops);
41 static struct sched_lock_ops const *const sched_lock_impl[] = {
42 [sched_lock_generic] = &ML_(generic_sched_lock_ops),
43 #ifdef ENABLE_LINUX_TICKET_LOCK
44 [sched_lock_ticket] = &ML_(linux_ticket_lock_ops),
45 #endif
48 /**
49 * Define which scheduler lock implementation to use.
51 * @param[in] t Scheduler lock type.
53 * @return True if and only if this function succeeded.
55 * @note Must be called before any other sched_lock*() function is invoked.
57 Bool ML_(set_sched_lock_impl)(const enum SchedLockType t)
59 struct sched_lock_ops const *p = NULL;
61 if ((unsigned)t < sizeof(sched_lock_impl)/sizeof(sched_lock_impl[0]))
62 p = sched_lock_impl[t];
63 if (p)
64 sched_lock_ops = p;
65 return !!p;
68 const HChar *ML_(get_sched_lock_name)(void)
70 return (sched_lock_ops->get_sched_lock_name)();
73 struct sched_lock *ML_(create_sched_lock)(void)
75 return (sched_lock_ops->create_sched_lock)();
78 void ML_(destroy_sched_lock)(struct sched_lock *p)
80 return (sched_lock_ops->destroy_sched_lock)(p);
83 int ML_(get_sched_lock_owner)(struct sched_lock *p)
85 return (sched_lock_ops->get_sched_lock_owner)(p);
88 void ML_(acquire_sched_lock)(struct sched_lock *p)
90 return (sched_lock_ops->acquire_sched_lock)(p);
93 void ML_(release_sched_lock)(struct sched_lock *p)
95 return (sched_lock_ops->release_sched_lock)(p);