From: Michal Sojka Date: Sun, 12 Oct 2008 07:42:19 +0000 (+0200) Subject: Fixed destroying of ports X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/forb.git/commitdiff_plain/96e5dce1da310fc91916634f201a6f9539aae901 Fixed destroying of ports Now, there is no problem with traversing the forb's peer tree and deleting the peers belonging to a particular port. Peers are added to port's list, so during port destroying we only traverse this list and remove remove the peers found there from forb's tree. --- diff --git a/TODO b/TODO index 4ef62da..bf1e9f9 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,12 @@ -* Create list for peers by port, so it will not be necessary to - traverse the peer tree when destroying ports. - * Add forb_init() parameters: argc, argv and orb_id * More flexible handling of log messages (dynamic registration, parsing of command line parameters). * Error checking of deserialization in skeletons + +* Add FNA as transport protocol (probably with some reliable protocol + on top of FNA) + +* Add routing layer + diff --git a/src/Makefile.omk b/src/Makefile.omk index 80eed2d..34d42e3 100644 --- a/src/Makefile.omk +++ b/src/Makefile.omk @@ -49,7 +49,7 @@ log_domains.inc: $(Q)$(SOURCES_DIR)/ul_log_domains $(SOURCES_DIR) > $@ clean-custom: - $(Q)rm log_domains.inc + -$(Q)rm log_domains.inc # request_gavl.inc: $(SOURCES_DIR)/request_gavl.c # @echo " CPP $@" diff --git a/src/iop.c b/src/iop.c index df48cae..61f6d84 100644 --- a/src/iop.c +++ b/src/iop.c @@ -60,6 +60,7 @@ #include #include "exec_req.h" #include +#include "peer.h" /** Version of the protocol */ #define VER_MAJOR 0 @@ -408,6 +409,8 @@ process_hello(forb_port_t *port, CDR_Codec *codec) forb_peer_get(peer); forb_peer_nolock_insert(forb, peer); } + forb_peer_get(peer); + forb_port_peer_ins_tail(port, peer); fosa_mutex_unlock(&forb->peer_mutex); forb_peer_put(peer); } diff --git a/src/peer.c b/src/peer.c index 321e729..bb2db1b 100644 --- a/src/peer.c +++ b/src/peer.c @@ -53,7 +53,7 @@ GAVL_CUST_NODE_INT_IMP(forb_peer_nolock,/* cust_prefix */ forb_peer_t, /* cust_item_t */ forb_server_id, /* cust_key_t */ peers, /* cust_root_node */ - node, /* cust_item_node */ + gnode, /* cust_item_node */ server_id, /* cust_item_key */ forb_server_id_cmp);/* cust_cmp_fnc */ @@ -87,17 +87,10 @@ void forb_peer_delete_by_port(forb_t *forb, forb_port_t *port) { forb_peer_t *peer; - fosa_mutex_lock(&port->forb->peer_mutex); - /* FIXME: Is gavl_cust_for_each() deletion safe? What about - * recursive locking of mutex. */ -#warning Delete during GAVL traversal is probably not correct. - gavl_cust_for_each(forb_peer_nolock, forb, peer) { - if (peer->port == port) { - forb_peer_nolock_delete(forb, peer); - forb_peer_put(peer); - } + ul_list_for_each_cut(forb_port_peer, port, peer) { + forb_peer_delete(forb, peer); + forb_peer_put(peer); } - fosa_mutex_unlock(&port->forb->peer_mutex); } forb_peer_t * diff --git a/src/peer.h b/src/peer.h index d0a5186..09b9066 100644 --- a/src/peer.h +++ b/src/peer.h @@ -50,6 +50,8 @@ #include #include "port.h" #include "refcnt.h" +#include +#include enum forb_peer_state { FORB_PEER_WANTED, /**< Somebody is waiting for the peer to be discovered. In this state, only @a server_id field is set. */ @@ -69,7 +71,8 @@ enum forb_peer_state { forb_port_t *port; /**< Port of this peer is connected to */ void *addr; /**< Protocol specific address of the peer. */ void *proto_priv; /**< Protocol private data (e.g. info about established connection) */ - gavl_node_t node; /**< Node of port's peers tree */ + gavl_node_t gnode; /**< Node of forb's peers tree */ + ul_list_node_t lnode; /**< Node of port's peer list */ forb_ref_t ref; /**< Reference count */ enum forb_peer_state state; fosa_cond_t cond; /**< Condition variable for waiting after the peer is discovered. Used together with forb::peer_mutex. */ @@ -82,10 +85,16 @@ GAVL_CUST_NODE_INT_DEC(forb_peer_nolock,/* cust_prefix */ forb_peer_t, /* cust_item_t */ forb_server_id, /* cust_key_t */ peers, /* cust_root_node */ - node, /* cust_item_node */ + gnode, /* cust_item_node */ server_id, /* cust_item_key */ forb_server_id_cmp)/* cust_cmp_fnc */ +UL_LIST_CUST_DEC(forb_port_peer, /* cust_prefix */ + forb_port_t, /* cust_head_t */ + forb_peer_t, /* cust_item_t */ + peers, /* cust_head_field */ + lnode) /* cust_node_field */ + forb_peer_t * forb_peer_new(void); diff --git a/src/port.c b/src/port.c index fd79aa8..de4e2ee 100644 --- a/src/port.c +++ b/src/port.c @@ -70,6 +70,8 @@ int forb_register_port(forb_t *forb, forb_port_t *port) port->forb = forb; port->finish = false; + + forb_port_peer_init_head(port); fosa_mutex_lock(&forb->port_mutex); forb_port_insert(forb, port); @@ -138,6 +140,8 @@ void forb_destroy_port(forb_port_t *port) port->proto->port_destroy(port); } + /* Because of no locking of port->peers, this must be called + * after receiver thread is stopped. */ forb_peer_delete_by_port(forb, port); CDR_codec_release_buffer(&port->codec); diff --git a/src/port.h b/src/port.h index f909327..36f5e7e 100644 --- a/src/port.h +++ b/src/port.h @@ -67,7 +67,7 @@ struct forb_port { CDR_Codec codec; /**< Receiving buffer for receiver thread */ void *addr; /**< Port's address in a protocol specific format. */ ul_list_node_t node; /**< Node in forb's port list */ - gavl_cust_root_field_t peers; /**< Peers discovered on this port by discovery protocol */ + ul_list_head_t peers; /**< Peers discovered on this port by discovery protocol */ bool finish; /**< True when the threads should finish their execution, false otherwise. */ };