< Summary - Backend C Tests - Coverage Report (WSL)

Information
Class: queue_c
Assembly: src.backend.core.data_structures
File(s): ./src/backend/core/data_structures/queue.c
Line coverage
82%
Covered lines: 42
Uncovered lines: 9
Coverable lines: 51
Total lines: 108
Line coverage: 82.3%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 2/18/2026 - 10:50:55 PM Line coverage: 82.3% (42/51) Branch coverage: 75% (3/4) Total lines: 108 2/18/2026 - 10:50:55 PM Line coverage: 82.3% (42/51) Branch coverage: 75% (3/4) Total lines: 108

File(s)

./src/backend/core/data_structures/queue.c

#LineLine coverage
 1/* This file is a template for queue.c. Content will be filled by yagiz on 2025-12-29. */
 2#include <stdio.h>
 3#include <stdlib.h>
 4#include "queue.h"
 5
 6// Internal Helper for Mutex
 97static void lockMutex(Mutex *m) {
 8#if defined(_WIN32) || defined(_WIN64)
 9  EnterCriticalSection(m);
 10#else
 911  pthread_mutex_lock(m);
 12#endif
 913}
 14
 915static void unlockMutex(Mutex *m) {
 16#if defined(_WIN32) || defined(_WIN64)
 17  LeaveCriticalSection(m);
 18#else
 919  pthread_mutex_unlock(m);
 20#endif
 921}
 22
 223static void initMutex(Mutex *m) {
 24#if defined(_WIN32) || defined(_WIN64)
 25  InitializeCriticalSection(m);
 26#else
 227  pthread_mutex_init(m, NULL);
 28#endif
 229}
 30
 031static void destroyMutex(Mutex *m) {
 32#if defined(_WIN32) || defined(_WIN64)
 33  DeleteCriticalSection(m);
 34#else
 035  pthread_mutex_destroy(m);
 36#endif
 037}
 38
 39// Function to initialize the queue
 240void initQueue(Queue *q) {
 241  q->head = 0;
 242  q->tail = 0;
 243  q->count = 0;
 44  // Initialize standard mutex
 245  initMutex(&q->lock);
 246}
 47
 48// Helper to destroy queue resources
 049void destroyQueue(Queue *q) {
 050  destroyMutex(&q->lock);
 051}
 52
 53// Is Queue empty? (Not thread-safe on its own, usually called within lock or for checks)
 54// But for strict safety, we can lock it too.
 355bool isQueueEmpty(Queue *q) {
 356  return (q->count == 0);
 57}
 58
 59// Is Queue full?
 260bool isQueueFull(Queue *q) {
 261  return (q->count == MAX_QUEUE_SIZE);
 62}
 63
 64// Enqueue element (Thread-safe)
 265bool enqueue(Queue *q, SensorData data) {
 266  lockMutex(&q->lock);
 67
 268  if (isQueueFull(q)) {
 069    printf("ERROR: Queue is full! Data lost: %.2f\n", data.value);
 070    unlockMutex(&q->lock);
 071    return false;
 72  }
 73
 74  // Write data to tail
 275  q->items[q->tail] = data;
 76  // Circular Buffer logic
 277  q->tail = (q->tail + 1) % MAX_QUEUE_SIZE;
 278  q->count++;
 279  unlockMutex(&q->lock);
 280  return true;
 81}
 82
 83// Dequeue element (Thread-safe)
 384bool dequeue(Queue *q, SensorData *outData) {
 385  lockMutex(&q->lock);
 86
 387  if (isQueueEmpty(q)) {
 88    // printf("Queue is empty.\n"); // Logging might be noisy
 189    unlockMutex(&q->lock);
 190    return false;
 91  }
 92
 93  // Read data from head
 294  *outData = q->items[q->head];
 95  // Circular Buffer logic
 296  q->head = (q->head + 1) % MAX_QUEUE_SIZE;
 297  q->count--;
 298  unlockMutex(&q->lock);
 299  return true;
 100}
 101
 4102int getQueueSize(Queue *q) {
 103  int size;
 4104  lockMutex(&q->lock);
 4105  size = q->count;
 4106  unlockMutex(&q->lock);
 4107  return size;
 108}

Methods/Properties