Ejemplo n.º 1
0
static int
usdf_fabric_close(fid_t fid)
{
	struct usdf_fabric *fp;
	int ret;
	void *rv;

	fp = fab_fidtou(fid);
	if (atomic_get(&fp->fab_refcnt) > 0) {
		return -FI_EBUSY;
	}
	/* Tell progression thread to exit */
	fp->fab_exit = 1;

	ret = usdf_fabric_wake_thread(fp);
	if (ret != 0) {
		return ret;
	}
	pthread_join(fp->fab_thread, &rv);
	usdf_timer_deinit(fp);
	close(fp->fab_eventfd);
	close(fp->fab_epollfd);
	close(fp->fab_arp_sockfd);

	free(fp);
	return 0;
}
Ejemplo n.º 2
0
/*
 * Set this timer to fire "ms" milliseconds from now.  If the timer is already
 * queued, previous timeout will be discarded.
 *
 * When timer expires, the registered timer callback will be called and
 * the timer entry removed from the queued list.  The timer routine will not
 * be called again until usdf_timer_set() is called again to re-set it.
 * usdf_timer_set() is safe to call from timer service routine.
 */
static inline int
_usdf_timer_do_set(struct usdf_fabric *fp, struct usdf_timer_entry *entry,
		uint32_t ms)
{
	int ret;
	unsigned bucket;

	/* If no timers active, cur_bucket_ms may need catchup */
	++fp->fab_active_timer_count;
	if (fp->fab_active_timer_count == 1) {
		fp->fab_cur_bucket_ms = usdf_get_ms();
		ret = usdf_fabric_wake_thread(fp);
		if (ret != 0) {
			--fp->fab_active_timer_count;
			return ret;
		}
	}

	if (entry->te_flags & USDF_TF_QUEUED) {
		LIST_REMOVE(entry, te_link);
		--fp->fab_active_timer_count;
	}

	// we could make "overflow" bucket...
	if (ms >= USDF_NUM_TIMER_BUCKETS) {
		--fp->fab_active_timer_count;
		return -FI_EINVAL;
	}
	bucket = (fp->fab_cur_bucket + ms) & (USDF_NUM_TIMER_BUCKETS - 1);

	LIST_INSERT_HEAD(&fp->fab_timer_buckets[bucket], entry, te_link);
	entry->te_flags |= USDF_TF_QUEUED;
	return 0;
}
Ejemplo n.º 3
0
static int
usdf_fabric_close(fid_t fid)
{
	struct usdf_fabric *fp;
	int ret;
	void *rv;

	USDF_TRACE("\n");

	fp = fab_fidtou(fid);
	if (ofi_atomic_get32(&fp->fab_refcnt) > 0) {
		return -FI_EBUSY;
	}
	/* Tell progression thread to exit */
	fp->fab_exit = 1;

	free(fp->fab_attr.name);
	free(fp->fab_attr.prov_name);

	if (fp->fab_thread) {
		ret = usdf_fabric_wake_thread(fp);
		if (ret != 0) {
			return ret;
		}
		pthread_join(fp->fab_thread, &rv);
	}
	usdf_timer_deinit(fp);
	if (fp->fab_epollfd != -1) {
		close(fp->fab_epollfd);
	}
	if (fp->fab_eventfd != -1) {
		close(fp->fab_eventfd);
	}
	if (fp->fab_arp_sockfd != -1) {
		close(fp->fab_arp_sockfd);
	}

	free(fp);
	return 0;
}