Provide a method to release the message cache.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-08-27 21:09:10 +02:00
parent 889c707ba1
commit 577d34facf
3 changed files with 18 additions and 0 deletions

View File

@ -99,6 +99,7 @@ static void clock_destroy(struct clock *c)
servo_destroy(c->servo);
mave_destroy(c->avg_delay);
memset(c, 0, sizeof(*c));
msg_cleanup();
}
static int clock_fault_timeout(struct clock *c, int index, int set)

12
msg.c
View File

@ -23,6 +23,7 @@
#include <asm/byteorder.h>
#include "contain.h"
#include "msg.h"
#include "print.h"
#include "tlv.h"
@ -230,6 +231,17 @@ struct ptp_message *msg_allocate(void)
return m;
}
void msg_cleanup(void)
{
struct message_storage *s;
struct ptp_message *m;
while ((m = TAILQ_FIRST(&msg_pool)) != NULL) {
TAILQ_REMOVE(&msg_pool, m, list);
s = container_of(m, struct message_storage, msg);
free(s);
}
}
void msg_get(struct ptp_message *m)
{
m->refcnt++;

5
msg.h
View File

@ -260,6 +260,11 @@ static inline int msg_type(struct ptp_message *m)
*/
struct ptp_message *msg_allocate(void);
/**
* Release all of the memory in the message cache.
*/
void msg_cleanup(void);
/**
* Obtain a reference to a message, increasing its reference count by one.
* @param m A message obtained using @ref msg_allocate().