Speed up SSE4.2 strcasestr by avoiding indirect function call.
[glibc.git] / nptl_db / td_thr_event_getmsg.c
blob70ea6953ed788d117c8eeb3850f22714242a3571
1 /* Retrieve event.
2 Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include "thread_dbP.h"
22 #include <assert.h>
25 td_err_e
26 td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg)
28 td_err_e err;
29 psaddr_t eventbuf, eventnum, eventdata;
30 psaddr_t thp, prevp;
31 void *copy;
33 LOG ("td_thr_event_getmsg");
35 /* Copy the event message buffer in from the inferior. */
36 err = DB_GET_FIELD_ADDRESS (eventbuf, th->th_ta_p, th->th_unique, pthread,
37 eventbuf, 0);
38 if (err == TD_OK)
39 err = DB_GET_STRUCT (copy, th->th_ta_p, eventbuf, td_eventbuf_t);
40 if (err != TD_OK)
41 return err;
43 /* Check whether an event occurred. */
44 err = DB_GET_FIELD_LOCAL (eventnum, th->th_ta_p, copy,
45 td_eventbuf_t, eventnum, 0);
46 if (err != TD_OK)
47 return err;
48 if ((int) (uintptr_t) eventnum == TD_EVENT_NONE)
49 /* Nothing. */
50 return TD_NOMSG;
52 /* Fill the user's data structure. */
53 err = DB_GET_FIELD_LOCAL (eventdata, th->th_ta_p, copy,
54 td_eventbuf_t, eventdata, 0);
55 if (err != TD_OK)
56 return err;
58 msg->msg.data = (uintptr_t) eventdata;
59 msg->event = (uintptr_t) eventnum;
60 msg->th_p = th;
62 /* And clear the event message in the target. */
63 memset (copy, 0, th->th_ta_p->ta_sizeof_td_eventbuf_t);
64 err = DB_PUT_STRUCT (th->th_ta_p, eventbuf, td_eventbuf_t, copy);
65 if (err != TD_OK)
66 return err;
68 /* Get the pointer to the thread descriptor with the last event.
69 If it doesn't match TH, then walk down the list until we find it.
70 We must splice it out of the list so that there is no dangling
71 pointer to it later when it dies. */
72 err = DB_GET_SYMBOL (prevp, th->th_ta_p, __nptl_last_event);
73 if (err != TD_OK)
74 return err;
75 err = DB_GET_VALUE (thp, th->th_ta_p, __nptl_last_event, 0);
76 if (err != TD_OK)
77 return err;
79 while (thp != 0)
81 psaddr_t next;
82 err = DB_GET_FIELD (next, th->th_ta_p, th->th_unique, pthread,
83 nextevent, 0);
84 if (err != TD_OK)
85 return err;
87 if (next == thp)
88 return TD_DBERR;
90 if (thp == th->th_unique)
92 /* PREVP points at this thread, splice it out. */
93 psaddr_t next_nextp;
94 err = DB_GET_FIELD_ADDRESS (next_nextp, th->th_ta_p, next, pthread,
95 nextevent, 0);
96 assert (err == TD_OK); /* We used this field before. */
97 if (prevp == next_nextp)
98 return TD_DBERR;
100 err = _td_store_value (th->th_ta_p,
101 th->th_ta_p->ta_var___nptl_last_event, -1,
102 0, prevp, next);
103 if (err != TD_OK)
104 return err;
106 /* Now clear this thread's own next pointer so it's not dangling
107 when the thread resumes and then chains on for its next event. */
108 return DB_PUT_FIELD (th->th_ta_p, thp, pthread, nextevent, 0, 0);
111 err = DB_GET_FIELD_ADDRESS (prevp, th->th_ta_p, thp, pthread,
112 nextevent, 0);
113 assert (err == TD_OK); /* We used this field before. */
114 thp = next;
117 /* Ack! This should not happen. */
118 return TD_DBERR;