Use linkedlist macros for UDPTL protocol list.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@74703 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2007-07-11 20:07:07 +00:00
parent 4f84931f12
commit fde3d4b086
2 changed files with 17 additions and 29 deletions

View File

@@ -42,7 +42,7 @@ struct ast_udptl_protocol {
/* Set UDPTL peer */ /* Set UDPTL peer */
int (* const set_udptl_peer)(struct ast_channel *chan, struct ast_udptl *peer); int (* const set_udptl_peer)(struct ast_channel *chan, struct ast_udptl *peer);
const char * const type; const char * const type;
struct ast_udptl_protocol *next; AST_RWLIST_ENTRY(ast_udptl_protocol) list;
}; };
struct ast_udptl; struct ast_udptl;

View File

@@ -170,7 +170,7 @@ struct ast_udptl {
udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1]; udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1];
}; };
static struct ast_udptl_protocol *protos; static AST_RWLIST_HEAD_STATIC(protos, ast_udptl_protocol);
static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, int len); static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, int len);
static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, uint8_t *ifp, int ifp_len); static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, uint8_t *ifp, int ifp_len);
@@ -949,52 +949,40 @@ int ast_udptl_write(struct ast_udptl *s, struct ast_frame *f)
void ast_udptl_proto_unregister(struct ast_udptl_protocol *proto) void ast_udptl_proto_unregister(struct ast_udptl_protocol *proto)
{ {
struct ast_udptl_protocol *cur; AST_RWLIST_WRLOCK(&protos);
struct ast_udptl_protocol *prev; AST_RWLIST_REMOVE(&protos, proto, list);
AST_RWLIST_UNLOCK(&protos);
cur = protos;
prev = NULL;
while (cur) {
if (cur == proto) {
if (prev)
prev->next = proto->next;
else
protos = proto->next;
return;
}
prev = cur;
cur = cur->next;
}
} }
int ast_udptl_proto_register(struct ast_udptl_protocol *proto) int ast_udptl_proto_register(struct ast_udptl_protocol *proto)
{ {
struct ast_udptl_protocol *cur; struct ast_udptl_protocol *cur;
cur = protos; AST_RWLIST_WRLOCK(&protos);
while (cur) { AST_RWLIST_TRAVERSE(&protos, cur, list) {
if (cur->type == proto->type) { if (cur->type == proto->type) {
ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
AST_RWLIST_UNLOCK(&protos);
return -1; return -1;
} }
cur = cur->next;
} }
proto->next = protos; AST_RWLIST_INSERT_TAIL(&protos, proto, list);
protos = proto; AST_RWLIST_UNLOCK(&protos);
return 0; return 0;
} }
static struct ast_udptl_protocol *get_proto(struct ast_channel *chan) static struct ast_udptl_protocol *get_proto(struct ast_channel *chan)
{ {
struct ast_udptl_protocol *cur; struct ast_udptl_protocol *cur = NULL;
cur = protos; AST_RWLIST_RDLOCK(&protos);
while (cur) { AST_RWLIST_TRAVERSE(&protos, cur, list) {
if (cur->type == chan->tech->type) if (cur->type == chan->tech->type)
return cur; break;
cur = cur->next;
} }
return NULL; AST_RWLIST_UNLOCK(&protos);
return cur;
} }
int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc) int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc)