Skip to content

Commit

Permalink
Use struct deque instead of deprecated struct circlebuf
Browse files Browse the repository at this point in the history
  • Loading branch information
norihiro committed Apr 16, 2024
1 parent 0f2d9d1 commit 42f1960
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/obs-vnc-source-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void *vncsrc_create(obs_data_t *settings, obs_source_t *source)
obs_source_set_async_unbuffered(source, true);

pthread_mutex_init(&src->config_mutex, NULL);
circlebuf_init(&src->interacts);
deque_init(&src->interacts);
pthread_mutex_init(&src->interact_mutex, NULL);

vncsrc_update(src, settings);
Expand All @@ -44,7 +44,7 @@ static void vncsrc_destroy(void *data)
vncsrc_thread_stop(src);

vncsrc_config_destroy_member(&src->config);
circlebuf_free(&src->interacts);
deque_free(&src->interacts);
bfree(src);
}

Expand Down Expand Up @@ -215,7 +215,7 @@ static inline void queue_interaction(struct vnc_source *src, struct vncsrc_inter
{
debug("queuing interaction event: type=%d\n", interact->type);
if (!pthread_mutex_lock(&src->interact_mutex)) {
circlebuf_push_back(&src->interacts, interact, sizeof(*interact));
deque_push_back(&src->interacts, interact, sizeof(*interact));
pthread_mutex_unlock(&src->interact_mutex);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/obs-vnc-source-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ static inline void rfbc_interact(struct vnc_source *src, rfbClient *client, stru
}

struct vncsrc_interaction_event_s ie;
circlebuf_pop_front(&src->interacts, &ie, sizeof(ie));
deque_pop_front(&src->interacts, &ie, sizeof(ie));
if (src->interacts.size > 0)
cont = 1;
pthread_mutex_unlock(&src->interact_mutex);
Expand Down Expand Up @@ -781,7 +781,7 @@ static void *thread_main(void *data)
if (!pthread_mutex_trylock(&src->interact_mutex)) {
// discard interaction queue
while (src->interacts.size >= sizeof(struct vncsrc_interaction_event_s))
circlebuf_pop_front(&src->interacts, NULL,
deque_pop_front(&src->interacts, NULL,
sizeof(struct vncsrc_interaction_event_s));
pthread_mutex_unlock(&src->interact_mutex);
}
Expand Down
14 changes: 12 additions & 2 deletions src/obs-vnc-source.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@

#include <obs.h>
#include <util/threading.h>
#include <util/circlebuf.h>
#include <rfb/rfbconfig.h>

#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(30, 0, 0)
#include <util/deque.h>
#else
#include <util/circlebuf.h>
#define deque_pop_front circlebuf_pop_front
#define deque_push_back circlebuf_push_back
#define deque_init circlebuf_init
#define deque_free circlebuf_free
#define deque circlebuf
#endif

enum vnc_encodings_e {
ve_tight = 1,
ve_zrle = 2,
Expand Down Expand Up @@ -95,7 +105,7 @@ struct vnc_source
void *fb_vnc; // for 8-bit and 16-bit

pthread_mutex_t interact_mutex;
struct circlebuf interacts;
struct deque interacts;

// threads
pthread_t thread;
Expand Down

0 comments on commit 42f1960

Please sign in to comment.