Skip to content

Commit

Permalink
Minor: assign thread name; fix compilation warnings
Browse files Browse the repository at this point in the history
* Don't capture static global variables into closures
* Keep _GNU_SOURCE in order
  • Loading branch information
seriyps committed Oct 26, 2024
1 parent 5f72b95 commit d01af96
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef DRM_H
#define DRM_H

#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
Expand Down
4 changes: 2 additions & 2 deletions src/dvr.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -90,6 +89,7 @@ void Dvr::enqueue_dvr_command(dvr_rpc rpc) {
}

void *Dvr::__THREAD__(void *param) {
pthread_setname_np(pthread_self(), "__DVR");
((Dvr *)param)->loop();
return nullptr;
}
Expand Down Expand Up @@ -225,4 +225,4 @@ extern "C" {
dvr->stop_recording();
}
}
}
}
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void *__FRAME_THREAD__(void *param)
int i, ret;
MppFrame frame = NULL;
uint64_t last_frame_time;
pthread_setname_np(pthread_self(), "__FRAME");

while (!frm_eos) {
struct timespec ts, ats;
Expand Down Expand Up @@ -249,6 +250,8 @@ void *__DISPLAY_THREAD__(void *param)
float min_latency = 1844674407370955161; // almost MAX_uint64_t
float max_latency = 0;
struct timespec fps_start, fps_end;

pthread_setname_np(pthread_self(), "__DISPLAY");
clock_gettime(CLOCK_MONOTONIC, &fps_start);

while (!frm_eos) {
Expand Down Expand Up @@ -379,7 +382,7 @@ void read_gstreamerpipe_stream(MppPacket *packet, int gst_udp_port, const VideoC
GstRtpReceiver receiver(gst_udp_port, codec);
long long bytes_received = 0;
uint64_t period_start=0;
auto cb=[&packet,&decoder_stalled_count, &bytes_received, &period_start](std::shared_ptr<std::vector<uint8_t>> frame){
auto cb=[&packet,/*&decoder_stalled_count,*/ &bytes_received, &period_start](std::shared_ptr<std::vector<uint8_t>> frame){
// Let the gst pull thread run at quite high priority
static bool first= false;
if(first){
Expand Down
3 changes: 3 additions & 0 deletions src/mavlink.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _GNU_SOURCE
#include <sys/prctl.h>
#include <errno.h>
#include <fcntl.h>
Expand All @@ -9,6 +10,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>

#include <arpa/inet.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -83,6 +85,7 @@ int mavlink_port = 14550;
int mavlink_thread_signal = 0;

void* __MAVLINK_THREAD__(void* arg) {
pthread_setname_np(pthread_self(), "__MAVLINK");
printf("Starting mavlink thread...\n");
// Create socket
int fd = socket(AF_INET, SOCK_DGRAM, 0);
Expand Down
4 changes: 3 additions & 1 deletion src/osd.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

#define _GNU_SOURCE
#include "osd.h"

#include "drm.h"
#include <cairo.h>
#include <pthread.h>
#include "mavlink.h"
#include "icons/icons.h"

Expand Down Expand Up @@ -303,6 +304,7 @@ cairo_surface_t * surface_from_embedded_png(const unsigned char * png, size_t le

void *__OSD_THREAD__(void *param) {
osd_thread_params *p = param;
pthread_setname_np(pthread_self(), "__OSD");
fps_icon = surface_from_embedded_png(framerate_icon, framerate_icon_length);
lat_icon = surface_from_embedded_png(latency_icon, latency_icon_length);
net_icon = surface_from_embedded_png(bandwidth_icon, bandwidth_icon_length);
Expand Down

0 comments on commit d01af96

Please sign in to comment.