[FFmpeg-devel] [PATCH 1/2] lavu: add thread message API.

Lukasz Marek lukasz.m.luki2 at gmail.com
Mon Apr 21 01:04:12 CEST 2014


> +#ifndef AVUTIL_THREADMESSAGE_H
> +#define AVUTIL_THREADMESSAGE_H
> +
> +typedef struct AVThreadMessageQueue AVThreadMessageQueue;
> +
> +typedef enum AVThreadMessageFlags {
> +
> +    /**
> +     * Perform non-blocking operation.
> +     * If this flag is set, send and recv operations are non-blocking and
> +     * return AVERROR(EAGAIN) immediately if they can not proceed.
> +     */
> +    AV_THREAD_MESSAGE_NONBLOCK = 1,
> +
> +} AVThreadMessageFlags;
> +
> +/**
> + * Allocate a new message queue.
> + *
> + * @param mq      pointer to the message queue
> + * @param elsize  size of each element in the queue
> + * @param nelem   minimum number of elements in the queue

hmm, Isn't it a maximum number of elements? You can add that thread will 
be blocked or AVERROR(EAGIAN) will be returned depending on flag when 
queue is full. Here or at send doxy.

> + * @return  >=0 for success; <0 for error, in particular AVERROR(ENOSYS) if
> + *          lavu was built without thread support
> + */
> +int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
> +                                  unsigned elsize,
> +                                  unsigned nelem);
> +
> +/**
> + * Free a message queue.
> + */
> +void av_thread_message_queue_free(AVThreadMessageQueue **mq);

This function is not thread-safe. Second thread may be in the middle of 
sending/receiving a message. In such API it seems to be serious.

> +/**
> + * Send a message on the queue.
> + */
> +int av_thread_message_queue_send(AVThreadMessageQueue *mq,
> +                                 void *msg,
> +                                 unsigned flags);
> +
> +/**
> + * Receive a message from the queue.
> + */
> +int av_thread_message_queue_recv(AVThreadMessageQueue *mq,
> +                                 void *msg,
> +                                 unsigned flags);

It would be nice to have also timeout, but I see w32threads are missing 
pthread_cond_timedwait()

There is no way to get notified there is a message in the queue for 
receiving thread. It has to poll or get blocked. Maybe add a callback 
for it?





More information about the ffmpeg-devel mailing list