2 /*--------------------------------------------------------------------*/
3 /*--- Scheduler lock support functions sched-lock.c ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2011-2017 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, see <http://www.gnu.org/licenses/>.
25 The GNU General Public License is contained in the file COPYING.
29 #include "pub_core_basics.h"
30 #include "pub_core_libcbase.h"
31 #include "pub_core_mallocfree.h"
32 #include "priv_sema.h"
33 #include "priv_sched-lock.h"
34 #include "priv_sched-lock-impl.h"
36 static struct sched_lock_ops
const *sched_lock_ops
=
37 &ML_(generic_sched_lock_ops
);
39 static struct sched_lock_ops
const *const sched_lock_impl
[] = {
40 [sched_lock_generic
] = &ML_(generic_sched_lock_ops
),
41 #ifdef ENABLE_LINUX_TICKET_LOCK
42 [sched_lock_ticket
] = &ML_(linux_ticket_lock_ops
),
47 * Define which scheduler lock implementation to use.
49 * @param[in] t Scheduler lock type.
51 * @return True if and only if this function succeeded.
53 * @note Must be called before any other sched_lock*() function is invoked.
55 Bool
ML_(set_sched_lock_impl
)(const enum SchedLockType t
)
57 struct sched_lock_ops
const *p
= NULL
;
59 if ((unsigned)t
< sizeof(sched_lock_impl
)/sizeof(sched_lock_impl
[0]))
60 p
= sched_lock_impl
[t
];
66 const HChar
*ML_(get_sched_lock_name
)(void)
68 return (sched_lock_ops
->get_sched_lock_name
)();
71 struct sched_lock
*ML_(create_sched_lock
)(void)
73 return (sched_lock_ops
->create_sched_lock
)();
76 void ML_(destroy_sched_lock
)(struct sched_lock
*p
)
78 return (sched_lock_ops
->destroy_sched_lock
)(p
);
81 int ML_(get_sched_lock_owner
)(struct sched_lock
*p
)
83 return (sched_lock_ops
->get_sched_lock_owner
)(p
);
86 void ML_(acquire_sched_lock
)(struct sched_lock
*p
)
88 return (sched_lock_ops
->acquire_sched_lock
)(p
);
91 void ML_(release_sched_lock
)(struct sched_lock
*p
)
93 return (sched_lock_ops
->release_sched_lock
)(p
);