2011-07-22 Kwok Cheung Yeung <kcy@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / common / ptid.c
1 /* The ptid_t type and common functions operating on it.
2
3 Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
5 2009, 2010, 2011 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "ptid.h"
23
24 /* Oft used ptids */
25 ptid_t null_ptid = { 0, 0, 0 };
26 ptid_t minus_one_ptid = { -1, 0, 0 };
27
28 /* Create a ptid given the necessary PID, LWP, and TID components. */
29
30 ptid_t
31 ptid_build (int pid, long lwp, long tid)
32 {
33 ptid_t ptid;
34
35 ptid.pid = pid;
36 ptid.lwp = lwp;
37 ptid.tid = tid;
38 return ptid;
39 }
40
41 /* Create a ptid from just a pid. */
42
43 ptid_t
44 pid_to_ptid (int pid)
45 {
46 return ptid_build (pid, 0, 0);
47 }
48
49 /* Fetch the pid (process id) component from a ptid. */
50
51 int
52 ptid_get_pid (ptid_t ptid)
53 {
54 return ptid.pid;
55 }
56
57 /* Fetch the lwp (lightweight process) component from a ptid. */
58
59 long
60 ptid_get_lwp (ptid_t ptid)
61 {
62 return ptid.lwp;
63 }
64
65 /* Fetch the tid (thread id) component from a ptid. */
66
67 long
68 ptid_get_tid (ptid_t ptid)
69 {
70 return ptid.tid;
71 }
72
73 /* ptid_equal() is used to test equality of two ptids. */
74
75 int
76 ptid_equal (ptid_t ptid1, ptid_t ptid2)
77 {
78 return (ptid1.pid == ptid2.pid
79 && ptid1.lwp == ptid2.lwp
80 && ptid1.tid == ptid2.tid);
81 }
82
83 /* Returns true if PTID represents a process. */
84
85 int
86 ptid_is_pid (ptid_t ptid)
87 {
88 if (ptid_equal (minus_one_ptid, ptid))
89 return 0;
90 if (ptid_equal (null_ptid, ptid))
91 return 0;
92
93 return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
94 }
This page took 0.035448 seconds and 5 git commands to generate.