+ m_host_t h = NULL;
+ simdata_host_t h_simdata = NULL;
+ xbt_fifo_item_t item;
+ m_task_t t;
+ int first_time = 1;
+ smx_cond_t cond;
+
+ xbt_assert1((channel>=0) && (channel < msg_global->max_channel),"Invalid channel %d",channel);
+ if(PID) {
+ *PID = -1;
+ }
+
+ if(max_duration==0.0) {
+ *PID = MSG_task_probe_from(channel);
+ MSG_RETURN(MSG_OK);
+ } else {
+ CHECK_HOST();
+ h = MSG_host_self();
+ h_simdata = h->simdata;
+
+ DEBUG2("Probing on channel %d (%s)", channel,h->name);
+ while(!(item = xbt_fifo_get_first_item(h->simdata->mbox[channel]))) {
+ if(max_duration>0) {
+ if(!first_time) {
+ MSG_RETURN(MSG_OK);
+ }
+ }
+ SIMIX_mutex_lock(h_simdata->mutex);
+ xbt_assert1(!(h_simdata->sleeping[channel]),
+ "A process is already blocked on this channel %d", channel);
+ cond = SIMIX_cond_init();
+ h_simdata->sleeping[channel] = cond; /* I'm waiting. Wake me up when you're ready */
+ if(max_duration>0) {
+ SIMIX_cond_wait_timeout(cond,h_simdata->mutex, max_duration);
+ } else {
+ SIMIX_cond_wait(cond,h_simdata->mutex);
+ }
+ SIMIX_cond_destroy(cond);
+ SIMIX_mutex_unlock(h_simdata->mutex);
+ if(SIMIX_host_get_state(h_simdata->host)==0) {
+ MSG_RETURN(MSG_HOST_FAILURE);
+ }
+ h_simdata->sleeping[channel] = NULL;
+ first_time = 0;
+ }
+ if (!item || !(t = xbt_fifo_get_item_content(item))) {
+ MSG_RETURN(MSG_OK);
+ }
+ if(PID) {
+ *PID = MSG_process_get_PID(t->simdata->sender);
+ }
+ MSG_RETURN(MSG_OK);
+ }