#include <pthread.h>
#include <tr_mq.h>
+#include <tr_debug.h>
/* Messages */
static int tr_mq_msg_destructor(void *object)
return 0;
}
-TR_MQ_MSG *tr_mq_msg_new(TALLOC_CTX *mem_ctx)
+TR_MQ_MSG *tr_mq_msg_new(TALLOC_CTX *mem_ctx, const char *message)
{
TR_MQ_MSG *msg=talloc(mem_ctx, TR_MQ_MSG);
if (msg!=NULL) {
msg->next=NULL;
+ msg->message=talloc_strdup(msg, message);
+ if (msg->message==NULL) {
+ talloc_free(msg);
+ return NULL;
+ }
msg->p=NULL;
talloc_set_destructor((void *)msg, tr_mq_msg_destructor);
}
talloc_free(msg);
}
+const char *tr_mq_msg_get_message(TR_MQ_MSG *msg)
+{
+ return msg->message;
+}
+
void *tr_mq_msg_get_payload(TR_MQ_MSG *msg)
{
return msg->p;
int tr_mq_unlock(TR_MQ *mq)
{
- return pthread_mutex_lock(&(mq->mutex));
+ return pthread_mutex_unlock(&(mq->mutex));
}
static TR_MQ_MSG *tr_mq_get_head(TR_MQ *mq)
/* see if we need to tell someone we became non-empty */
if (was_empty && (notify_cb!=NULL))
- mq->notify_cb(mq, notify_cb_arg);
+ notify_cb(mq, notify_cb_arg);
}
/* caller must free msg via tr_mq_msg_free */
tr_mq_lock(mq);
if (tr_mq_get_head(mq)!=NULL) {
popped=tr_mq_get_head(mq);
- tr_mq_msg_set_next(popped, tr_mq_msg_get_next(popped)); /* popped is the old head */
+ tr_mq_set_head(mq, tr_mq_msg_get_next(popped)); /* popped is the old head */
if (tr_mq_get_head(mq)==NULL)
tr_mq_set_tail(mq, NULL); /* just popped the last element */
}