LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
mq.c File Reference

(7c4d7d1 userspace/term: change eyecandy inclusion to use objcopy instead of xxd)

#include <mq.h>
#include <string.h>
#include <tpa.h>
#include <flexarray.h>
#include <panic.h>
#include <errno.h>
#include <scheduler.h>
+ Include dependency graph for mq.c:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MessageQueuePage
 This is the header for a message queue page. More...
 
struct  MessageQueue
 This is the implementation data for a message queue. More...
 

Functions

void init_mq (allocator_t *alloc)
 
uint64_t mq_create (allocator_t *alloc)
 
void mq_destroy (uint64_t mq)
 
static void mq_alloc_page (struct MessageQueue *mq, size_t min_size)
 
uint64_t mq_push (uint64_t mq, struct Message *message)
 
uint64_t mq_pop (uint64_t mq, struct Message *msg)
 
uint64_t mq_peek (uint64_t mq, struct Message *msg)
 
uint64_t mq_notify_teardown (mq_id_t mq, mq_notifier notifier)
 

Variables

static const size_t MessageQueuePageItemsTarget = 16
 Target number of messages per page, muliplied by average message size for allocation size of new pages.
 
static tpa_tmqs
 
static uint64_t next_mq = 1
 

Data Structure Documentation

◆ MessageQueuePage

struct MessageQueuePage

This is the header for a message queue page.

Definition at line 16 of file mq.c.

+ Collaboration diagram for MessageQueuePage:
Data Fields
size_t allocated allocated bytes for the page, excluding header
size_t bytes bytes active in this page (messages not yet popped)
size_t items items active in this page (messages not yet popped)
struct MessageQueuePage * next Pointer to next page.
size_t pop_position first byte of first non-popped message
size_t push_position first free byte in page

◆ MessageQueue

struct MessageQueue

This is the implementation data for a message queue.

Definition at line 37 of file mq.c.

+ Collaboration diagram for MessageQueue:
Data Fields
allocator_t * alloc Allocator for new pages.
size_t average_message_size Average message size, for new page allocation.
size_t bytes Counting active-message bytes.
struct MessageQueuePage * first_page Pointer to first page for popping and peeking.
size_t items Counting active messages.
struct MessageQueuePage * last_page Pointer to last page for pushing.
size_t max_bytes Maximum number of bytes in non-popped messsages in the queue after which mq_push will return false.
size_t max_items Maximum number of items in the queue after which mq_push will return false.
flexarray_t notify_teardown

Function Documentation

◆ init_mq()

void init_mq ( allocator_t alloc)

Definition at line 65 of file mq.c.

References alloc, mqs, and tpa_new().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mq_alloc_page()

static void mq_alloc_page ( struct MessageQueue mq,
size_t  min_size 
)
static

Definition at line 121 of file mq.c.

References MessageQueuePage::allocated, memset(), MessageQueuePageItemsTarget, mq, and MessageQueuePage::next.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mq_create()

uint64_t mq_create ( allocator_t alloc)

Definition at line 69 of file mq.c.

References alloc, MessageQueue::max_items, mq, mqs, new_flexarray(), next_mq, panic_message(), and tpa_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mq_destroy()

void mq_destroy ( uint64_t  mq)

Definition at line 93 of file mq.c.

References MessageQueue::alloc, allocator::dealloc, delete_flexarray(), MessageQueue::first_page, flexarray_get(), flexarray_length(), mq, mqs, MessageQueuePage::next, MessageQueue::notify_teardown, tpa_get(), and tpa_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mq_notify_teardown()

uint64_t mq_notify_teardown ( mq_id_t  mq,
mq_notifier  notifier 
)

Definition at line 242 of file mq.c.

References EEXIST, ENOENT, flexarray_append(), flexarray_get(), flexarray_length(), mq, mqs, MessageQueue::notify_teardown, and tpa_get().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mq_peek()

uint64_t mq_peek ( uint64_t  mq,
struct Message msg 
)

Definition at line 218 of file mq.c.

References EMSGSIZE, ENOENT, ENOMSG, MessageQueue::first_page, MessageQueue::items, memcpy(), mq, mqs, MT_Invalid, MessageQueuePage::pop_position, Message::size, tpa_get(), and Message::type.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mq_pop()

uint64_t mq_pop ( uint64_t  mq,
struct Message msg 
)

Definition at line 190 of file mq.c.

References MessageQueue::alloc, MessageQueuePage::bytes, MessageQueue::bytes, allocator::dealloc, error, MessageQueue::first_page, MessageQueuePage::items, MessageQueue::items, MessageQueue::last_page, mq, mq_peek(), mqs, MessageQueuePage::next, MessageQueuePage::pop_position, Message::size, and tpa_get().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mq_push()

uint64_t mq_push ( uint64_t  mq,
struct Message message 
)

Definition at line 144 of file mq.c.

References MessageQueuePage::allocated, MessageQueue::average_message_size, MessageQueuePage::bytes, MessageQueue::bytes, ENOENT, ENOMEM, MessageQueuePage::items, MessageQueue::items, MessageQueue::last_page, MessageQueue::max_bytes, MessageQueue::max_items, memcpy(), message, wait_data::message_queue, mq, mq_alloc_page(), mqs, MessageQueuePage::push_position, scheduler_waitable_done(), Message::size, tpa_get(), and wait_reason_message.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MessageQueuePageItemsTarget

const size_t MessageQueuePageItemsTarget = 16
static

Target number of messages per page, muliplied by average message size for allocation size of new pages.

Definition at line 10 of file mq.c.

◆ mqs

tpa_t* mqs
static

Definition at line 12 of file mq.c.

◆ next_mq

uint64_t next_mq = 1
static

Definition at line 13 of file mq.c.