Commit b5840714 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Add a simple condition variable for fill level of outgoing queue.

parent 4eb78040
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
find_package (Threads)

add_subdirectory(prrt)
add_library(PRRT prrt/socket.c prrt/block.c prrt/block.h prrt/packet.c prrt/packet.h)
add_library(PRRT prrt/socket.c prrt/block.c prrt/block.h prrt/packet.c prrt/packet.h prrt/feedback_receiver.c prrt/feedback_receiver.h prrt/data_transmitter.c prrt/data_transmitter.h)
add_library(UTIL util/common.c util/common.h)

add_executable(sender sender.c)
+21 −0
Original line number Diff line number Diff line
#include <unistd.h>
#include "data_transmitter.h"
#include "socket.h"

void * send_data_loop(void *ptr) {
    prrt_socket *sock_ptr = ptr;
    while(1) {
        pthread_mutex_lock(&sock_ptr->is_data_available);
        while(sock_ptr->packets_count == 0) {
            pthread_cond_wait(&sock_ptr->is_data_available_cv, &sock_ptr->is_data_available);
        }
        // TODO: take a packet from the list and send it

        sock_ptr->packets_count--;
        printf("TAKING OUT (NOW: %d)\n", sock_ptr->packets_count);


        pthread_mutex_unlock(&sock_ptr->is_data_available);
        usleep(1000);
    }
}
+6 −0
Original line number Diff line number Diff line
#ifndef PRRT_DATA_TRANSMITTER_H
#define PRRT_DATA_TRANSMITTER_H

void * send_data_loop(void *ptr);

#endif //PRRT_DATA_TRANSMITTER_H
+20 −0
Original line number Diff line number Diff line
#include <string.h>
#include <unistd.h>
#include "feedback_receiver.h"
#include "../defines.h"
#include "socket.h"

void *receive_feedback_loop(void *ptr) {
    char bufin[MAX_PAYLOAD_LENGTH];

    prrt_socket *sock_ptr = ptr;

    while(1) {
        memset(bufin, 0, MAX_PAYLOAD_LENGTH);
        prrt_packet *t = prrt_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
        if(t != NULL) {
            delete_packet(t);
        }
        usleep(1000);
    }
}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
#ifndef PRRT_FEEDBACK_RECEIVER_H
#define PRRT_FEEDBACK_RECEIVER_H

void *receive_feedback_loop(void *ptr);

#endif //PRRT_FEEDBACK_RECEIVER_H
Loading