From 6564f8403c732ad3a2bf010ca9a2d453e54f5138 Mon Sep 17 00:00:00 2001 From: Tim Prins Date: Thu, 1 Jul 2004 17:45:34 +0000 Subject: [PATCH] Adding functions to initialize a ner peer description. Minor documentation changes This commit was SVN r1530. --- src/mca/oob/base/Makefile.am | 1 + src/mca/oob/base/oob_base_close.c | 1 - src/mca/oob/base/oob_base_open.c | 1 - src/mca/oob/oob.h | 4 +- src/mca/oob/tcp/oob_tcp_peer.c | 75 +++++++++++++++++++++++++++++++ src/mca/oob/tcp/oob_tcp_peer.h | 37 +++++++++++++-- 6 files changed, 112 insertions(+), 7 deletions(-) diff --git a/src/mca/oob/base/Makefile.am b/src/mca/oob/base/Makefile.am index 874f028c99..7b980bcb2e 100644 --- a/src/mca/oob/base/Makefile.am +++ b/src/mca/oob/base/Makefile.am @@ -28,6 +28,7 @@ libmca_oob_base_la_SOURCES = \ oob_base_send_nb.c \ oob_base_pack.c + # Conditionally install the header files if WANT_INSTALL_HEADERS diff --git a/src/mca/oob/base/oob_base_close.c b/src/mca/oob/base/oob_base_close.c index 3ff43ac4df..15a7ea351d 100644 --- a/src/mca/oob/base/oob_base_close.c +++ b/src/mca/oob/base/oob_base_close.c @@ -9,7 +9,6 @@ #include "include/constants.h" #include "mca/mca.h" #include "mca/base/base.h" -#include "mca/oob/oob.h" #include "mca/oob/base/base.h" diff --git a/src/mca/oob/base/oob_base_open.c b/src/mca/oob/base/oob_base_open.c index d874a02086..6d09c66e1e 100644 --- a/src/mca/oob/base/oob_base_open.c +++ b/src/mca/oob/base/oob_base_open.c @@ -6,7 +6,6 @@ #include "mca/mca.h" #include "mca/base/base.h" -#include "mca/oob/oob.h" #include "mca/oob/base/base.h" diff --git a/src/mca/oob/oob.h b/src/mca/oob/oob.h index bb32a351f4..c7b3fff0e2 100644 --- a/src/mca/oob/oob.h +++ b/src/mca/oob/oob.h @@ -56,7 +56,7 @@ extern "C" { #endif /** -* Similiar to unix send(2). +* Similiar to unix writev(2). * * @param peer (IN) Opaque name of peer process. * @param msg (IN) Array of iovecs describing user buffers and lengths. @@ -91,7 +91,7 @@ int mca_oob_send_hton( /** -* Similiar to unix recv(2) +* Similiar to unix readv(2) * * @param peer (IN) Opaque name of peer process or OOB_NAME_ANY for wildcard receive. * @param msg (IN) Array of iovecs describing user buffers and lengths. diff --git a/src/mca/oob/tcp/oob_tcp_peer.c b/src/mca/oob/tcp/oob_tcp_peer.c index ef3562785a..ceb79cc313 100644 --- a/src/mca/oob/tcp/oob_tcp_peer.c +++ b/src/mca/oob/tcp/oob_tcp_peer.c @@ -1,5 +1,13 @@ #include "mca/oob/tcp/oob_tcp_peer.h" + +OBJ_CLASS_INSTANCE( + mca_oob_tcp_peer_t, + ompi_list_item_t, + &mca_oob_tcp_peer_construct, + &mca_oob_tcp_peer_destruct); + + /* * The function to compare 2 peers. Used for the rb tree * @@ -24,3 +32,70 @@ int mca_oob_tcp_peer_comp(void * key1, void * key2) return(0); } +/* + * This is the constructor function for the mca_oob_tcp_peer + * struct. Note that this function and OBJ_NEW should NEVER + * be called directly. Instead, use mca_oob_tcp_add_peer + * + * @param peer a pointer to the mca_oob_tcp_peer_t struct to be initialized + * @retval none + */ +void mca_oob_tcp_peer_construct(mca_oob_tcp_peer_t* peer) +{ + OBJ_CONSTRUCT(&(peer->peer_send), ompi_list_t); + OBJ_CONSTRUCT(&(peer->peer_recv), ompi_list_t); + OBJ_CONSTRUCT(&(peer->peer_lock), ompi_mutex_t); +} + +/* + * This is the destructor function for the mca_oob_tcp_peer + * struct. Note that this function and OBJ_RELEASE should NEVER + * be called directly. Instead, use mca_oob_tcp_del_peer + * + * @param peer a pointer to the mca_oob_tcp_peer_t struct to be destroyed + * @retval none + */ +void mca_oob_tcp_peer_destruct(mca_oob_tcp_peer_t * peer) +{ + OBJ_DESTRUCT(&(peer->peer_send)); + OBJ_DESTRUCT(&(peer->peer_recv)); + OBJ_DESTRUCT(&(peer->peer_lock)); + +} + +/* + * Creates a peer structure and adds to the tree and list. + * + * @param peer_name the name of the peer + * + * @retval pointer to the newly created struture + * @retval NULL if there was a problem + */ +mca_oob_tcp_peer_t * mca_oob_tcp_add_peer(ompi_process_name_t peer_name) +{ + mca_oob_tcp_peer_t * new_peer = OBJ_NEW(mca_oob_tcp_peer_t); + new_peer->peer_name = peer_name; + if(OMPI_SUCCESS != ompi_rb_tree_insert(&mca_oob_tcp_peer_tree, &new_peer, NULL)) { + free(new_peer); + return NULL; + } + ompi_list_prepend(&mca_oob_tcp_peer_list, (ompi_list_item_t *) new_peer); + return new_peer; +} + +/* + * Deletes a peer structure from the tree and lists and frees its memory + * + * @param peer_name the name of the peer + * + * @retval OMPI_SUCCESS + */ +int mca_oob_tcp_del_peer(ompi_process_name_t peer_name) +{ + mca_oob_tcp_peer_t * peer = ompi_rb_tree_find(&mca_oob_tcp_peer_tree, &peer_name); + ompi_rb_tree_delete(&mca_oob_tcp_peer_tree, peer); + ompi_list_remove_item(&mca_oob_tcp_peer_list, (ompi_list_item_t *)peer); + OBJ_RELEASE(peer); + return OMPI_SUCCESS; +} + diff --git a/src/mca/oob/tcp/oob_tcp_peer.h b/src/mca/oob/tcp/oob_tcp_peer.h index d7cb1881ae..735b36d613 100644 --- a/src/mca/oob/tcp/oob_tcp_peer.h +++ b/src/mca/oob/tcp/oob_tcp_peer.h @@ -11,8 +11,12 @@ #include "mca/ns/ns.h" #include "class/ompi_list.h" +#include "class/ompi_rb_tree.h" #include #include "threads/mutex.h" +#include +#include "mca/oob/tcp/oob_tcp.h" + /** * the state of the connection */ @@ -46,10 +50,34 @@ struct mca_oob_tcp_peer_t { mca_oob_tcp_addr_t peer_addr; /**< the address of the peer process */ ompi_mutex_t peer_lock; /**< make sure only one thread accesses it at a time */ ompi_list_t peer_send; /**< list of items to send */ - ompi_list_t peer_recieved; /**< list of items to recieve */ + ompi_list_t peer_recv; /**< list of items to recieve */ }; typedef struct mca_oob_tcp_peer_t mca_oob_tcp_peer_t; - + +#if defined(c_plusplus) || defined(__cplusplus) +extern "C" { +#endif + +/** + * This is the constructor function for the mca_oob_tcp_peer + * struct. Note that this function and OBJ_NEW should NEVER + * be called directly. Instead, use mca_oob_tcp_add_peer + * + * @param peer a pointer to the mca_oob_tcp_peer_t struct to be initialized + * @retval none + */ +void mca_oob_tcp_peer_construct(mca_oob_tcp_peer_t* peer); + +/** + * This is the destructor function for the mca_oob_tcp_peer + * struct. Note that this function and OBJ_RELEASE should NEVER + * be called directly. Instead, use mca_oob_tcp_del_peer + * + * @param peer a pointer to the mca_oob_tcp_peer_t struct to be destroyed + * @retval none + */ +void mca_oob_tcp_peer_destruct(mca_oob_tcp_peer_t * peer); + /** * The function to compare 2 peers. Used for the rb tree * @@ -78,9 +106,12 @@ mca_oob_tcp_peer_t * mca_oob_tcp_add_peer(ompi_process_name_t peer_name); * @param peer_name the name of the peer * * @retval OMPI_SUCCESS - * @retval OMPI_ERROR */ int mca_oob_tcp_del_peer(ompi_process_name_t peer_name); +#if defined(c_plusplus) || defined(__cplusplus) +} +#endif + #endif /* _MCA_OOB_TCP_PEER_H */