1/* Copyright 2016 Google Inc.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. */
14
15#ifndef NSYNC_PUBLIC_NSYNC_DEBUG_H_
16#define NSYNC_PUBLIC_NSYNC_DEBUG_H_
17
18/* Debugging operations for mutexes and condition variables.
19
20 These operations should not be relied upon for normal functionality. The
21 implementation may be slow, output formats may change, and the
22 implementation is free to yield the empty string. */
23
24#include "nsync_cpp.h"
25#include "nsync_mu.h"
26#include "nsync_cv.h"
27
28NSYNC_CPP_START_
29
30/* Place in buf[0,..,n-1] a nul-terminated, human readable string indicative of
31 some of the internal state of the mutex or condition variable, and return
32 buf. If n>=4, buffer overflow is indicated by placing the characters "..."
33 at the end of the string.
34
35 The *_and_waiters() variants attempt to output the waiter lists in addition
36 to the basic state. These variants may acquire internal locks and follow
37 internal pointers. Thus, they are riskier if invoked in an address space
38 whose overall health is uncertain. */
39char *nsync_mu_debug_state (nsync_mu *mu, char *buf, int n);
40char *nsync_cv_debug_state (nsync_cv *cv, char *buf, int n);
41char *nsync_mu_debug_state_and_waiters (nsync_mu *mu, char *buf, int n);
42char *nsync_cv_debug_state_and_waiters (nsync_cv *cv, char *buf, int n);
43
44/* Like nsync_*_debug_state_and_waiters(), but ignoring all locking and safety
45 considerations, and using an internal, possibly static buffer that may be
46 overwritten by subsequent or concurrent calls to these routines. These
47 variants should be used only from an interactive debugger, when all other
48 threads are stopped; the debugger is expected to recover from errors. */
49char *nsync_mu_debugger (nsync_mu *mu);
50char *nsync_cv_debugger (nsync_cv *cv);
51
52NSYNC_CPP_END_
53
54#endif /*NSYNC_PUBLIC_NSYNC_DEBUG_H_*/
55