td_thr_event_getmsg.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Retrieve event.
  2. Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <stddef.h>
  17. #include <string.h>
  18. #include "thread_dbP.h"
  19. td_err_e
  20. td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg)
  21. {
  22. td_eventbuf_t event;
  23. LOG ("td_thr_event_getmsg");
  24. /* If the thread descriptor has not yet been created there cannot be
  25. any event. */
  26. if (th->th_unique == NULL)
  27. return TD_NOMSG;
  28. /* Read the even structure from the target. */
  29. if (ps_pdread (th->th_ta_p->ph,
  30. ((char *) th->th_unique
  31. + offsetof (struct _pthread_descr_struct, p_eventbuf)),
  32. &event, sizeof (td_eventbuf_t)) != PS_OK)
  33. return TD_ERR; /* XXX Other error value? */
  34. /* Check whether an event occurred. */
  35. if (event.eventnum == TD_EVENT_NONE)
  36. /* Nothing. */
  37. return TD_NOMSG;
  38. /* Fill the user's data structure. */
  39. msg->event = event.eventnum;
  40. msg->th_p = th;
  41. msg->msg.data = (uintptr_t) event.eventdata;
  42. /* And clear the event message in the target. */
  43. memset (&event, '\0', sizeof (td_eventbuf_t));
  44. if (ps_pdwrite (th->th_ta_p->ph,
  45. ((char *) th->th_unique
  46. + offsetof (struct _pthread_descr_struct, p_eventbuf)),
  47. &event, sizeof (td_eventbuf_t)) != PS_OK)
  48. return TD_ERR; /* XXX Other error value? */
  49. return TD_OK;
  50. }