Changeset f3b74d1 in mainline


Ignore:
Timestamp:
2024-12-22T22:40:22Z (5 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
6784abc
Parents:
95158dac
Message:

hr: fge: use libc queue <adt/circ_buf.h>

Location:
uspace/srv/bd/hr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/fge.c

    r95158dac rf3b74d1  
    4141
    4242#include <adt/bitmap.h>
     43#include <adt/circ_buf.h>
    4344#include <assert.h>
    4445#include <errno.h>
     
    6061static errno_t fge_fibril(void *);
    6162static errno_t wu_queue_init(wu_queue_t *, size_t);
    62 static void wu_queue_push(wu_queue_t *, fge_fibril_data_t);
    63 static fge_fibril_data_t wu_queue_pop(wu_queue_t *);
     63static void wu_queue_push(wu_queue_t *, fge_fibril_data_t *);
     64static void wu_queue_pop(wu_queue_t *, fge_fibril_data_t *);
    6465static ssize_t hr_fpool_get_free_slot(hr_fpool_t *);
    6566
     
    7677        fibril_condvar_t not_full;
    7778        fge_fibril_data_t *fexecs;
    78         size_t capacity;
    79         size_t size;
    80         size_t front;
    81         size_t back;
     79        circ_buf_t cbuf;
    8280} wu_queue_t;
    8381
     
    312310        fibril_mutex_unlock(&group->lock);
    313311
    314         wu_queue_push(&group->pool->queue, executor);
     312        wu_queue_push(&group->pool->queue, &executor);
    315313}
    316314
     
    366364                fibril_mutex_lock(&pool->lock);
    367365
    368                 while (pool->queue.size == 0 && !pool->stop) {
     366                while (circ_buf_nused(&pool->queue.cbuf) == 0 && !pool->stop) {
    369367                        fibril_condvar_wait(&pool->queue.not_empty,
    370368                            &pool->lock);
    371369                }
    372370
    373                 if (pool->stop && pool->queue.size == 0) {
     371                if (pool->stop && circ_buf_nused(&pool->queue.cbuf) == 0) {
    374372                        fibril_mutex_unlock(&pool->lock);
    375373                        break;
    376374                }
    377375
    378                 executor = wu_queue_pop(&pool->queue);
     376                wu_queue_pop(&pool->queue, &executor);
    379377
    380378                fibril_mutex_unlock(&pool->lock);
     
    410408}
    411409
    412 static errno_t wu_queue_init(wu_queue_t *queue, size_t capacity)
    413 {
    414         queue->fexecs = malloc(sizeof(fge_fibril_data_t) * capacity);
     410static errno_t wu_queue_init(wu_queue_t *queue, size_t nmemb)
     411{
     412        queue->fexecs = malloc(sizeof(fge_fibril_data_t) * nmemb);
    415413        if (queue->fexecs == NULL)
    416414                return ENOMEM;
    417415
    418         queue->capacity = capacity;
    419         queue->size = 0;
    420         queue->front = 0;
    421         queue->back = 0;
     416        circ_buf_init(&queue->cbuf, queue->fexecs, nmemb,
     417            sizeof(fge_fibril_data_t));
     418
    422419        fibril_mutex_initialize(&queue->lock);
    423420        fibril_condvar_initialize(&queue->not_empty);
     
    427424}
    428425
    429 static void wu_queue_push(wu_queue_t *queue, fge_fibril_data_t executor)
     426static void wu_queue_push(wu_queue_t *queue, fge_fibril_data_t *executor)
    430427{
    431428        fibril_mutex_lock(&queue->lock);
    432429
    433         while (queue->size == queue->capacity)
     430        while (circ_buf_push(&queue->cbuf, executor) == EAGAIN)
    434431                fibril_condvar_wait(&queue->not_full, &queue->lock);
    435432
    436         queue->fexecs[queue->back] = executor;
    437         queue->back = (queue->back + 1) % queue->capacity;
    438         queue->size++;
    439 
    440433        fibril_condvar_signal(&queue->not_empty);
    441434
     
    443436}
    444437
    445 static fge_fibril_data_t wu_queue_pop(wu_queue_t *queue)
     438static void wu_queue_pop(wu_queue_t *queue, fge_fibril_data_t *executor)
    446439{
    447440        fibril_mutex_lock(&queue->lock);
    448441
    449         while (queue->size == 0)
     442        while (circ_buf_pop(&queue->cbuf, executor) == EAGAIN)
    450443                fibril_condvar_wait(&queue->not_empty, &queue->lock);
    451444
    452         fge_fibril_data_t wu = queue->fexecs[queue->front];
    453         queue->front = (queue->front + 1) % queue->capacity;
    454         queue->size--;
    455 
    456445        fibril_condvar_signal(&queue->not_full);
    457446
    458447        fibril_mutex_unlock(&queue->lock);
    459         return wu;
    460448}
    461449
  • uspace/srv/bd/hr/fge.h

    r95158dac rf3b74d1  
    3333/**
    3434 * @file
    35  * @brief Fibril group executor
    36  *
    37  * Fibril pool with pre-allocated storage allowing
    38  * execution of groups consisting of multiple work
    39  * units.
    4035 */
    4136
Note: See TracChangeset for help on using the changeset viewer.