Rate This Document
Findability
Accuracy
Completeness
Readability

kupl::queue_submit(item)

Submit items to be executed to a queue. Compared with kupl_queue_submit, this interface uses the lambda function to capture the input parameters of the kupl_queue_submit callback, eliminating the need for manual parameter encapsulation and improving interface usability.

Interface Definition

int queue_submit(kupl_queue_h queue, kupl_queue_item_desc_t *desc, const std::function<void(void)> &func);

Parameters

Table 1 Parameter definition

Parameter

Type

Description

Input/Output

queue

kupl_queue_h

Queue for executing items

Input

desc

kupl_queue_item_desc_t

Description of a queue item

Input

func

const std::function<void(void)>

Function pointer to a queue item

Input

Table 2 kupl_queue_item_desc_t data structure

Parameter

Type

Description

field_mask

uint64_t

Mask of valid fields in the structure, similar to the bit flag of kupl_queue_item_desc_field. Fields not specified in this mask will be ignored.

Options:

  • KUPL_QUEUE_ITEM_DESC_FIELD_NAME: The name takes effect.
  • KUPL_QUEUE_ITEM_DESC_FIELD_EGROUP: The egroup takes effect.

func

kupl_queue_item_func_t

Function pointer to a queue item

args

void *

Arguments of a queue item

name

const char *

Name of a queue item

egroup

kupl_egroup_h

Affinity information of a queue item

Return Value

Success: KUPL_OK

Failure: KUPL_ERROR

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h> 
#include <assert.h>
#include "kupl.h" 

int main() 
{ 
    kupl_queue_h queue = kupl_queue_create();
    kupl_queue_item_desc_t desc = {
        .field_mask = KUPL_QUEUE_ITEM_DESC_FIELD_NAME,
        .name = "func_name"
    };
    int ret = kupl::queue_submit(queue, &desc, []() {
        printf("queue submit test\n");
    }); 
    assert(ret == KUPL_OK);
    kupl_queue_wait(queue);
    kupl_queue_destroy(queue);
    return 0;         
}

The execution result is as follows:

queue submit test

The preceding example demonstrates the process of submitting items to a queue and waiting until all tasks in the queue are executed. The kupl_queue_submit is used to submit items to be executed to a queue.