Back to index

glibc  2.9
td_thr_event_getmsg.c
Go to the documentation of this file.
00001 /* Retrieve event.
00002    Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stddef.h>
00022 #include <string.h>
00023 
00024 #include "thread_dbP.h"
00025 
00026 
00027 td_err_e
00028 td_thr_event_getmsg (const td_thrhandle_t *th, td_event_msg_t *msg)
00029 {
00030   td_eventbuf_t event;
00031 
00032   LOG ("td_thr_event_getmsg");
00033 
00034   /* If the thread descriptor has not yet been created there cannot be
00035      any event.  */
00036   if (th->th_unique == NULL)
00037     return TD_NOMSG;
00038 
00039   /* Read the even structure from the target.  */
00040   if (ps_pdread (th->th_ta_p->ph,
00041                ((char *) th->th_unique
00042                 + offsetof (struct _pthread_descr_struct, p_eventbuf)),
00043                &event, sizeof (td_eventbuf_t)) != PS_OK)
00044     return TD_ERR;   /* XXX Other error value?  */
00045 
00046   /* Check whether an event occurred.  */
00047   if (event.eventnum == TD_EVENT_NONE)
00048     /* Nothing.  */
00049     return TD_NOMSG;
00050 
00051   /* Fill the user's data structure.  */
00052   msg->event = event.eventnum;
00053   msg->th_p = th;
00054   msg->msg.data = (uintptr_t) event.eventdata;
00055 
00056   /* And clear the event message in the target.  */
00057   memset (&event, '\0', sizeof (td_eventbuf_t));
00058   if (ps_pdwrite (th->th_ta_p->ph,
00059                 ((char *) th->th_unique
00060                  + offsetof (struct _pthread_descr_struct, p_eventbuf)),
00061                 &event, sizeof (td_eventbuf_t)) != PS_OK)
00062     return TD_ERR;   /* XXX Other error value?  */
00063 
00064   return TD_OK;
00065 }