FreeRTOS C-Addons  1.1.0
C-Addon functionality to FreeRTOS
Data Structures | Typedefs | Functions
workqueue.c File Reference
#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#include "workqueue.h"
#include "queue_simple.h"
Include dependency graph for workqueue.c:

Go to the source code of this file.

Data Structures

struct  pvtWorkItem_t_
 
struct  pvtWorkQueue_t_
 

Typedefs

typedef struct pvtWorkItem_t_ pvtWorkItem_t
 
typedef struct pvtWorkQueue_t_ pvtWorkQueue_t
 

Functions

static void WorkerThread (void *parameters)
 
WorkQueue_t CreateWorkQueueEx (const char *const Name, uint16_t StackSize, UBaseType_t Priority)
 
void DestroyWorkQueue (WorkQueue_t wq)
 
int QueueWorkItem (WorkQueue_t wq, WorkItem_t Function, void *UserData)
 

Typedef Documentation

◆ pvtWorkItem_t

typedef struct pvtWorkItem_t_ pvtWorkItem_t

Work Item, what we actually use internally.

◆ pvtWorkQueue_t

The internal WorkQueue data structure.

Function Documentation

◆ CreateWorkQueueEx()

WorkQueue_t CreateWorkQueueEx ( const char *const  Name,
uint16_t  StackSize,
UBaseType_t  Priority 
)

Create a WorkQueue, specifying all options.

Parameters
NameThe name of the worker thread.
StackSizeThe size of the worker thread stack, in words.
PriorityThe priority of the worker thread.
Returns
A handle, or NULL on error.

Definition at line 255 of file workqueue.c.

◆ DestroyWorkQueue()

void DestroyWorkQueue ( WorkQueue_t  WorkQueue)

Destroy a WorkQueue, if allowed.

Parameters
WorkQueueThe work queue.

Lock

Flag we are all done.

Signal the Worker thead.

Unlock

Definition at line 312 of file workqueue.c.

◆ QueueWorkItem()

int QueueWorkItem ( WorkQueue_t  WorkQueue,
WorkItem_t  WorkItem,
void *  UserData 
)

Add an item of work onto the queue.

Parameters
WorkQueueThe work queue.
WorkItemThe function you want called.
UserDataA value passed back to you.
Returns
pdPASS on success, pdFAIL on error.

Lock the queue

Put the work item on the queue.

Wake the Worker thread up.

Unlock the queue

Definition at line 344 of file workqueue.c.

◆ WorkerThread()

static void WorkerThread ( void *  parameters)
static

Wait to be woken.

Lock the queue

Keep looping until the work items are all done.

Dequeue an item.

Unlock the queue, the lock is really only for the Queue struct.

Recover the actual work item pointer.

And call the function.

All done, free it.

Lock the queue again so we can check if the Queue is empty yet.

Are we being asked to exit? We want to do this while holding the lock.

Unlock now

If we need to exit, then jump out of the task loop.

Thread cleanup here.

Lock this work queue.

Drain the queue and free everything.

Dequeue the node

Recover the work item from the node.

And free it.

Finally unlock

Free the semaphores

We need to save a local copy of our handle.

And free the work queue stat structure itself.

Finally delete ourselves, we won't go past this call.

Definition at line 101 of file workqueue.c.