int tcpx_conn_mgr_init(struct tcpx_fabric *tcpx_fabric) { int ret; dlist_init(&tcpx_fabric->poll_mgr.list); fastlock_init(&tcpx_fabric->poll_mgr.lock); ret = fd_signal_init(&tcpx_fabric->poll_mgr.signal); if (ret) { FI_WARN(&tcpx_prov, FI_LOG_FABRIC,"signal init failed\n"); goto err; } tcpx_fabric->poll_mgr.run = 1; ret = pthread_create(&tcpx_fabric->conn_mgr_thread, 0, tcpx_conn_mgr_thread, (void *) tcpx_fabric); if (ret) { FI_WARN(&tcpx_prov, FI_LOG_FABRIC, "Failed creating tcpx connection manager thread"); goto err1; } return 0; err1: fd_signal_free(&tcpx_fabric->poll_mgr.signal); err: fastlock_destroy(&tcpx_fabric->poll_mgr.lock); return ret; }
static int util_wait_fd_close(struct fid *fid) { struct util_wait_fd *wait; struct ofi_wait_fd_entry *fd_entry; int ret; wait = container_of(fid, struct util_wait_fd, util_wait.wait_fid.fid); ret = fi_wait_cleanup(&wait->util_wait); if (ret) return ret; fastlock_acquire(&wait->lock); while (!dlist_empty(&wait->fd_list)) { dlist_pop_front(&wait->fd_list, struct ofi_wait_fd_entry, fd_entry, entry); fi_epoll_del(wait->epoll_fd, fd_entry->fd); free(fd_entry); } fastlock_release(&wait->lock); fi_epoll_del(wait->epoll_fd, wait->signal.fd[FI_READ_FD]); fd_signal_free(&wait->signal); fi_epoll_close(wait->epoll_fd); fastlock_destroy(&wait->lock); free(wait); return 0; }
int ofi_wait_fd_open(struct fid_fabric *fabric_fid, struct fi_wait_attr *attr, struct fid_wait **waitset) { struct util_fabric *fabric; struct util_wait_fd *wait; int ret; fabric = container_of(fabric_fid, struct util_fabric, fabric_fid); ret = util_verify_wait_fd_attr(fabric->prov, attr); if (ret) return ret; wait = calloc(1, sizeof(*wait)); if (!wait) return -FI_ENOMEM; ret = fi_wait_init(fabric, attr, &wait->util_wait); if (ret) goto err1; wait->util_wait.signal = util_wait_fd_signal; wait->util_wait.wait_try = util_wait_fd_try; ret = fd_signal_init(&wait->signal); if (ret) goto err2; ret = fi_epoll_create(&wait->epoll_fd); if (ret) goto err3; ret = fi_epoll_add(wait->epoll_fd, wait->signal.fd[FI_READ_FD], FI_EPOLL_IN, &wait->util_wait.wait_fid.fid); if (ret) goto err4; wait->util_wait.wait_fid.fid.ops = &util_wait_fd_fi_ops; wait->util_wait.wait_fid.ops = &util_wait_fd_ops; dlist_init(&wait->fd_list); fastlock_init(&wait->lock); *waitset = &wait->util_wait.wait_fid; return 0; err4: fi_epoll_close(wait->epoll_fd); err3: fd_signal_free(&wait->signal); err2: fi_wait_cleanup(&wait->util_wait); err1: free(wait); return ret; }
static int util_wait_fd_close(struct fid *fid) { struct util_wait_fd *wait; int ret; wait = container_of(fid, struct util_wait_fd, util_wait.wait_fid.fid); ret = fi_wait_cleanup(&wait->util_wait); if (ret) return ret; fi_epoll_del(wait->epoll_fd, wait->signal.fd[FI_READ_FD]); fd_signal_free(&wait->signal); fi_epoll_close(wait->epoll_fd); free(wait); return 0; }
void tcpx_conn_mgr_close(struct tcpx_fabric *tcpx_fabric) { struct poll_fd_info *poll_info; tcpx_fabric->poll_mgr.run = 0; fd_signal_set(&tcpx_fabric->poll_mgr.signal); if (tcpx_fabric->conn_mgr_thread && pthread_join(tcpx_fabric->conn_mgr_thread, NULL)) { FI_DBG(&tcpx_prov, FI_LOG_FABRIC, "cm thread failed to join\n"); } while (!dlist_empty(&tcpx_fabric->poll_mgr.list)) { poll_info = container_of(tcpx_fabric->poll_mgr.list.next, struct poll_fd_info, entry); dlist_remove(&poll_info->entry); assert(poll_info->flags & POLL_MGR_FREE); free(poll_info); } fastlock_destroy(&tcpx_fabric->poll_mgr.lock); fd_signal_free(&tcpx_fabric->poll_mgr.signal); }