td_thr_event_getmsg.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <stddef.h>
  18. #include <string.h>
  19. #include "thread_dbP.h"
  20. td_err_e
  21. td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg)
  22. {
  23. td_eventbuf_t event;
  24. LOG ("td_thr_event_getmsg");
  25. /* If the thread descriptor has not yet been created there cannot be
  26. any event. */
  27. if (th->th_unique == NULL)
  28. return TD_NOMSG;
  29. /* Read the even structure from the target. */
  30. if (ps_pdread (th->th_ta_p->ph,
  31. ((char *) th->th_unique
  32. + offsetof (struct _pthread_descr_struct, p_eventbuf)),
  33. &event, sizeof (td_eventbuf_t)) != PS_OK)
  34. return TD_ERR; /* XXX Other error value? */
  35. /* Check whether an event occurred. */
  36. if (event.eventnum == TD_EVENT_NONE)
  37. /* Nothing. */
  38. return TD_NOMSG;
  39. /* Fill the user's data structure. */
  40. msg->event = event.eventnum;
  41. msg->th_p = th;
  42. msg->msg.data = (uintptr_t) event.eventdata;
  43. /* And clear the event message in the target. */
  44. memset (&event, '\0', sizeof (td_eventbuf_t));
  45. if (ps_pdwrite (th->th_ta_p->ph,
  46. ((char *) th->th_unique
  47. + offsetof (struct _pthread_descr_struct, p_eventbuf)),
  48. &event, sizeof (td_eventbuf_t)) != PS_OK)
  49. return TD_ERR; /* XXX Other error value? */
  50. return TD_OK;
  51. }