- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / tcmalloc / vendor / src / base / thread_lister.h
1 /* Copyright (c) 2005-2007, Google Inc.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * ---
31  * Author: Markus Gutschke
32  */
33
34 #ifndef _THREAD_LISTER_H
35 #define _THREAD_LISTER_H
36
37 #include <stdarg.h>
38 #include <sys/types.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 typedef int (*ListAllProcessThreadsCallBack)(void *parameter,
45                                              int num_threads,
46                                              pid_t *thread_pids,
47                                              va_list ap);
48
49 /* This function gets the list of all linux threads of the current process
50  * passes them to the 'callback' along with the 'parameter' pointer; at the
51  * call back call time all the threads are paused via
52  * PTRACE_ATTACH.
53  * The callback is executed from a separate thread which shares only the
54  * address space, the filesystem, and the filehandles with the caller. Most
55  * notably, it does not share the same pid and ppid; and if it terminates,
56  * the rest of the application is still there. 'callback' is supposed to do
57  * or arrange for ResumeAllProcessThreads. This happens automatically, if
58  * the thread raises a synchronous signal (e.g. SIGSEGV); asynchronous
59  * signals are blocked. If the 'callback' decides to unblock them, it must
60  * ensure that they cannot terminate the application, or that
61  * ResumeAllProcessThreads will get called.
62  * It is an error for the 'callback' to make any library calls that could
63  * acquire locks. Most notably, this means that most system calls have to
64  * avoid going through libc. Also, this means that it is not legal to call
65  * exit() or abort().
66  * We return -1 on error and the return value of 'callback' on success.
67  */
68 int ListAllProcessThreads(void *parameter,
69                           ListAllProcessThreadsCallBack callback, ...);
70
71 /* This function resumes the list of all linux threads that
72  * ListAllProcessThreads pauses before giving to its callback.
73  * The function returns non-zero if at least one thread was
74  * suspended and has now been resumed.
75  */
76 int ResumeAllProcessThreads(int num_threads, pid_t *thread_pids);
77
78 #ifdef __cplusplus
79 }
80 #endif
81
82 #endif  /* _THREAD_LISTER_H */