X-Git-Url: http://git.liburcu.org/?p=userspace-rcu.git;a=blobdiff_plain;f=urcu-checker.c;fp=urcu-checker.c;h=234bd9bc68e72ffb45ef5ef12e4ffe6723b6f3e4;hp=0000000000000000000000000000000000000000;hb=791151d0b8f0314496cf18c822c071b1dd5791ea;hpb=e4749953c309cb418cd583cdd80b6dd0b2c4161f diff --git a/urcu-checker.c b/urcu-checker.c new file mode 100644 index 0000000..234bd9b --- /dev/null +++ b/urcu-checker.c @@ -0,0 +1,68 @@ +/* + * urcu-checker.c + * + * Userspace RCU library checker + * + * Copyright (c) 2014 Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include + +#define URCU_DEBUG_STACK_LEN 10 + +struct urcu_debug_entry { + void *ip; + int depth; +}; + +struct urcu_debug_stack { + struct urcu_debug_entry stack[URCU_DEBUG_STACK_LEN]; + int stackend; +}; + +static DEFINE_URCU_TLS(struct urcu_debug_stack, rcu_debug_stack); + +void rcu_read_lock_debug(void) +{ + struct urcu_debug_stack *r = &URCU_TLS(rcu_debug_stack); + + r->stack[r->stackend++].ip = __builtin_return_address(0); +} + +void rcu_read_unlock_debug(void) +{ + struct urcu_debug_stack *r = &URCU_TLS(rcu_debug_stack); + + assert(r->stackend != 0); + r->stack[--r->stackend].ip = NULL; +} + +void rcu_read_ongoing_check_debug(const char *func) +{ + struct urcu_debug_stack *r = &URCU_TLS(rcu_debug_stack); + + if (r->stackend == 0) { + fprintf(stderr, "URCU LOCKED CHECK failure: %p\n", + __builtin_return_address(0)); + abort(); + } +}