Index: include/asterisk/rtp.h =================================================================== --- include/asterisk/rtp.h (revision 7719) +++ include/asterisk/rtp.h (working copy) @@ -26,13 +26,14 @@ #ifndef _ASTERISK_RTP_H #define _ASTERISK_RTP_H +#include + #include "asterisk/frame.h" #include "asterisk/io.h" #include "asterisk/sched.h" #include "asterisk/channel.h" +#include "asterisk/linkedlists.h" -#include - #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif @@ -56,7 +57,7 @@ int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs, int nat_active); int (* const get_codec)(struct ast_channel *chan); const char * const type; - struct ast_rtp_protocol *next; + AST_LIST_ENTRY(ast_rtp_protocol) list; }; /*! Index: rtp.c =================================================================== --- rtp.c (revision 7719) +++ rtp.c (working copy) @@ -149,7 +149,7 @@ struct sockaddr_in them; }; -static struct ast_rtp_protocol *protos = NULL; +static AST_LIST_HEAD_STATIC(protos, ast_rtp_protocol); int ast_rtp_fd(struct ast_rtp *rtp) { @@ -746,13 +746,13 @@ { struct ast_rtp_protocol *cur; - cur = protos; - while(cur) { - if (cur->type == chan->type) { + AST_LIST_LOCK(&protos); + AST_LIST_TRAVERSE(&protos, cur, list) { + if (cur->type == chan->type) return cur; - } - cur = cur->next; } + AST_LIST_UNLOCK(&protos); + return NULL; } @@ -1536,37 +1536,35 @@ /*--- ast_rtp_proto_unregister: Unregister interface to channel driver */ void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto) { - struct ast_rtp_protocol *cur, *prev; + struct ast_rtp_protocol *cur; - cur = protos; - prev = NULL; - while(cur) { + AST_LIST_LOCK(&protos); + AST_LIST_TRAVERSE_SAFE_BEGIN(&protos, cur, list) { if (cur == proto) { - if (prev) - prev->next = proto->next; - else - protos = proto->next; - return; + AST_LIST_REMOVE_CURRENT(&protos, list); + break; } - prev = cur; - cur = cur->next; } + AST_LIST_TRAVERSE_SAFE_END + AST_LIST_UNLOCK(&protos); } /*--- ast_rtp_proto_register: Register interface to channel driver */ int ast_rtp_proto_register(struct ast_rtp_protocol *proto) { struct ast_rtp_protocol *cur; - cur = protos; - while(cur) { + + AST_LIST_LOCK(&protos); + AST_LIST_TRAVERSE(&protos, cur, list) { if (cur->type == proto->type) { ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); + AST_LIST_UNLOCK(&protos); return -1; } - cur = cur->next; } - proto->next = protos; - protos = proto; + AST_LIST_INSERT_HEAD(&protos, proto, list); + AST_LIST_UNLOCK(&protos); + return 0; }