static void test_sched (void) { v_printf (" - Test schedule/wait/continue.\r\n"); DDS_schedule (0); DDS_schedule (10); DDS_wait (0); DDS_wait (50); DDS_continue (); }
DDS_Topic DDS_DomainParticipant_find_topic (DDS_DomainParticipant dp, const char *topic_name, DDS_Duration_t *timeout) { Topic_t *tp; #ifdef THREADS_USED int ret; struct timespec ts; TopicWait_t *wp, *xp, *prev_wp; #else Ticks_t d, now, end_time; /* *10ms */ #endif ctrc_begind (DCPS_ID, DCPS_DP_F_TOP, &dp, sizeof (dp)); ctrc_contd (topic_name, strlen (topic_name) + 1); ctrc_contd (timeout, sizeof (DDS_Duration_t)); ctrc_endd (); /* Get Domain Participant. */ if (!domain_ptr (dp, 1, NULL)) { log_printf (DCPS_ID, 0, "find_topic(): domain participant not found!\r\n"); return (NULL); } tp = topic_lookup (&dp->participant, topic_name); if (tp) { if (!lock_take (tp->lock)) { tp->entity.flags |= EF_LOCAL; tp->nlrefs++; lock_release (tp->lock); } lock_release (dp->lock); return ((DDS_Topic) tp); } #ifdef THREADS_USED for (wp = dp->topic_wait; wp; wp = wp->next) if (!strcmp (topic_name, wp->name)) break; if (wp) wp->nthreads++; else { wp = mds_pool_alloc (&dcps_mem_blocks [MB_TOPIC_WAIT]); if (!wp) { lock_release (dp->lock); return (NULL); } wp->next = dp->topic_wait; cond_init (wp->condition); wp->name = topic_name; wp->topic = NULL; wp->nthreads = 1; dp->topic_wait = wp; } duration2timespec (timeout, &ts); do { if (ts.tv_sec || ts.tv_nsec) ret = cond_wait_to (wp->condition, dp->lock, ts); else ret = cond_wait (wp->condition, dp->lock); } while (!wp->topic && !ret); tp = wp->topic; if (!--wp->nthreads) { for (xp = dp->topic_wait, prev_wp = NULL; xp != NULL && xp != wp; prev_wp = xp, xp = xp->next) ; if (prev_wp) prev_wp->next = wp->next; else dp->topic_wait = wp->next; cond_destroy (wp->condition); mds_pool_free (&dcps_mem_blocks [MB_TOPIC_WAIT], wp); } lock_release (dp->lock); #else if (dds_listener_state) { lock_release (dp->lock); return (NULL); } /* Wait until timeout elapsed for discovery to add the topic. */ now = sys_getticks (); if (timeout->sec == DDS_DURATION_INFINITE_SEC || timeout->nanosec == DDS_DURATION_INFINITE_NSEC) end_time = now + 0x7ffffffe; else end_time = now + duration2ticks ((Duration_t *) timeout); for (;;) { d = end_time - now; if (d >= 0x7fffffffUL) break; DDS_schedule (d * TMR_UNIT_MS); tp = topic_lookup (&dp->participant, topic_name); if (tp) { tp->entity.flags |= EF_LOCAL; tp->nlrefs++; break; } now = sys_getticks (); } #endif return (tp); }