123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #include <stddef.h>
- #include <string.h>
- #include "thread_dbP.h"
- td_err_e
- td_ta_event_getmsg (const td_thragent_t *ta, td_event_msg_t *msg)
- {
-
- static td_thrhandle_t th;
- td_eventbuf_t event;
- psaddr_t addr;
- LOG ("td_ta_event_getmsg");
-
- if (! ta_ok (ta))
- return TD_BADTA;
-
- if (ps_pdread (ta->ph, ta->pthread_last_event,
- &addr, sizeof (void *)) != PS_OK)
- return TD_ERR;
-
- if (addr == 0)
- return TD_NOMSG;
-
- if (ps_pdread (ta->ph,
- ((char *) addr
- + offsetof (struct _pthread_descr_struct, p_eventbuf)),
- &event, sizeof (td_eventbuf_t)) != PS_OK)
- return TD_ERR;
-
- if (event.eventnum == TD_EVENT_NONE)
- {
-
- struct pthread_handle_struct handles[ta->pthread_threads_max];
- int num;
- int i;
-
- if (ps_pdread (ta->ph, ta->pthread_handles_num, &num, sizeof (int))
- != PS_OK)
- return TD_ERR;
-
- if (ps_pdread (ta->ph, ta->handles, handles,
- ta->pthread_threads_max * sizeof (handles[0])) != PS_OK)
- return TD_ERR;
- for (i = 0; i < ta->pthread_threads_max && num > 0; ++i)
- {
- if (handles[i].h_descr == NULL)
-
- continue;
-
- --num;
- if (handles[i].h_descr == addr)
-
- continue;
-
- if (ps_pdread (ta->ph,
- ((char *) handles[i].h_descr
- + offsetof (struct _pthread_descr_struct,
- p_eventbuf)),
- &event, sizeof (td_eventbuf_t)) != PS_OK)
- return TD_ERR;
- if (event.eventnum != TD_EVENT_NONE)
- {
-
- addr = handles[i].h_descr;
- break;
- }
- }
-
- if (event.eventnum == TD_EVENT_NONE)
- return TD_NOMSG;
- }
-
- th.th_ta_p = (td_thragent_t *) ta;
- th.th_unique = addr;
-
- msg->event = event.eventnum;
- msg->th_p = &th;
- msg->msg.data = (uintptr_t) event.eventdata;
-
- memset (&event, '\0', sizeof (td_eventbuf_t));
- if (ps_pdwrite (ta->ph,
- ((char *) addr
- + offsetof (struct _pthread_descr_struct, p_eventbuf)),
- &event, sizeof (td_eventbuf_t)) != PS_OK)
- return TD_ERR;
- return TD_OK;
- }
|