Changeset f3b74d1 in mainline
- Timestamp:
- 2024-12-22T22:40:22Z (5 months ago)
- Children:
- 6784abc
- Parents:
- 95158dac
- Location:
- uspace/srv/bd/hr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/hr/fge.c
r95158dac rf3b74d1 41 41 42 42 #include <adt/bitmap.h> 43 #include <adt/circ_buf.h> 43 44 #include <assert.h> 44 45 #include <errno.h> … … 60 61 static errno_t fge_fibril(void *); 61 62 static 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 *);63 static void wu_queue_push(wu_queue_t *, fge_fibril_data_t *); 64 static void wu_queue_pop(wu_queue_t *, fge_fibril_data_t *); 64 65 static ssize_t hr_fpool_get_free_slot(hr_fpool_t *); 65 66 … … 76 77 fibril_condvar_t not_full; 77 78 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; 82 80 } wu_queue_t; 83 81 … … 312 310 fibril_mutex_unlock(&group->lock); 313 311 314 wu_queue_push(&group->pool->queue, executor);312 wu_queue_push(&group->pool->queue, &executor); 315 313 } 316 314 … … 366 364 fibril_mutex_lock(&pool->lock); 367 365 368 while ( pool->queue.size== 0 && !pool->stop) {366 while (circ_buf_nused(&pool->queue.cbuf) == 0 && !pool->stop) { 369 367 fibril_condvar_wait(&pool->queue.not_empty, 370 368 &pool->lock); 371 369 } 372 370 373 if (pool->stop && pool->queue.size== 0) {371 if (pool->stop && circ_buf_nused(&pool->queue.cbuf) == 0) { 374 372 fibril_mutex_unlock(&pool->lock); 375 373 break; 376 374 } 377 375 378 executor = wu_queue_pop(&pool->queue);376 wu_queue_pop(&pool->queue, &executor); 379 377 380 378 fibril_mutex_unlock(&pool->lock); … … 410 408 } 411 409 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);410 static errno_t wu_queue_init(wu_queue_t *queue, size_t nmemb) 411 { 412 queue->fexecs = malloc(sizeof(fge_fibril_data_t) * nmemb); 415 413 if (queue->fexecs == NULL) 416 414 return ENOMEM; 417 415 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 422 419 fibril_mutex_initialize(&queue->lock); 423 420 fibril_condvar_initialize(&queue->not_empty); … … 427 424 } 428 425 429 static void wu_queue_push(wu_queue_t *queue, fge_fibril_data_t executor)426 static void wu_queue_push(wu_queue_t *queue, fge_fibril_data_t *executor) 430 427 { 431 428 fibril_mutex_lock(&queue->lock); 432 429 433 while ( queue->size == queue->capacity)430 while (circ_buf_push(&queue->cbuf, executor) == EAGAIN) 434 431 fibril_condvar_wait(&queue->not_full, &queue->lock); 435 432 436 queue->fexecs[queue->back] = executor;437 queue->back = (queue->back + 1) % queue->capacity;438 queue->size++;439 440 433 fibril_condvar_signal(&queue->not_empty); 441 434 … … 443 436 } 444 437 445 static fge_fibril_data_t wu_queue_pop(wu_queue_t *queue)438 static void wu_queue_pop(wu_queue_t *queue, fge_fibril_data_t *executor) 446 439 { 447 440 fibril_mutex_lock(&queue->lock); 448 441 449 while ( queue->size == 0)442 while (circ_buf_pop(&queue->cbuf, executor) == EAGAIN) 450 443 fibril_condvar_wait(&queue->not_empty, &queue->lock); 451 444 452 fge_fibril_data_t wu = queue->fexecs[queue->front];453 queue->front = (queue->front + 1) % queue->capacity;454 queue->size--;455 456 445 fibril_condvar_signal(&queue->not_full); 457 446 458 447 fibril_mutex_unlock(&queue->lock); 459 return wu;460 448 } 461 449 -
uspace/srv/bd/hr/fge.h
r95158dac rf3b74d1 33 33 /** 34 34 * @file 35 * @brief Fibril group executor36 *37 * Fibril pool with pre-allocated storage allowing38 * execution of groups consisting of multiple work39 * units.40 35 */ 41 36
Note:
See TracChangeset
for help on using the changeset viewer.