Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
tryfinally committed Dec 5, 2020
1 parent 93bebd9 commit f178ba0
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/arch/macosx/pthread_queue.c
@@ -1,7 +1,7 @@
/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -34,9 +34,9 @@ Inspired by c-pthread-queue by Matthew Dickinson
#include <csp/arch/posix/pthread_queue.h>

pthread_queue_t * pthread_queue_create(int length, size_t item_size) {

pthread_queue_t * q = malloc(sizeof(pthread_queue_t));

if (q != NULL) {
q->buffer = malloc(length*item_size);
if (q->buffer != NULL) {
Expand All @@ -57,7 +57,7 @@ pthread_queue_t * pthread_queue_create(int length, size_t item_size) {
}

return q;

}

void pthread_queue_delete(pthread_queue_t * q) {
Expand All @@ -73,7 +73,7 @@ void pthread_queue_delete(pthread_queue_t * q) {
}

int pthread_queue_enqueue(pthread_queue_t * queue, const void * value, uint32_t timeout) {

int ret;

/* Calculate timeout */
Expand Down Expand Up @@ -107,23 +107,23 @@ int pthread_queue_enqueue(pthread_queue_t * queue, const void * value, uint32_t
}
}

/* Coby object from input buffer */
/* Copy object from input buffer */
memcpy(queue->buffer+(queue->in * queue->item_size), value, queue->item_size);
queue->items++;
queue->in = (queue->in + 1) % queue->size;
pthread_mutex_unlock(&(queue->mutex));

/* Nofify blocked threads */
pthread_cond_broadcast(&(queue->cond_empty));

return PTHREAD_QUEUE_OK;

}

int pthread_queue_dequeue(pthread_queue_t * queue, void * buf, uint32_t timeout) {

int ret;

/* Calculate timeout */
struct timespec ts;
clock_serv_t cclock;
Expand All @@ -133,17 +133,17 @@ int pthread_queue_dequeue(pthread_queue_t * queue, void * buf, uint32_t timeout)
mach_port_deallocate(mach_task_self(), cclock);
ts.tv_sec = mts.tv_sec;
ts.tv_nsec = mts.tv_nsec;

uint32_t sec = timeout / 1000;
uint32_t nsec = (timeout - 1000 * sec) * 1000000;

ts.tv_sec += sec;

if (ts.tv_nsec + nsec > 1000000000)
ts.tv_sec++;

ts.tv_nsec = (ts.tv_nsec + nsec) % 1000000000;

/* Get queue lock */
pthread_mutex_lock(&(queue->mutex));
while (queue->items == 0) {
Expand All @@ -154,25 +154,25 @@ int pthread_queue_dequeue(pthread_queue_t * queue, void * buf, uint32_t timeout)
}
}

/* Coby object to output buffer */
/* Copy object to output buffer */
memcpy(buf, queue->buffer+(queue->out * queue->item_size), queue->item_size);
queue->items--;
queue->out = (queue->out + 1) % queue->size;
pthread_mutex_unlock(&(queue->mutex));

/* Nofify blocked threads */
pthread_cond_broadcast(&(queue->cond_full));

return PTHREAD_QUEUE_OK;

}

int pthread_queue_items(pthread_queue_t * queue) {

pthread_mutex_lock(&(queue->mutex));
int items = queue->items;
pthread_mutex_unlock(&(queue->mutex));

return items;

}

0 comments on commit f178ba0

Please sign in to comment.