Skip to content
Extraits de code Groupes Projets
Vérifiée Valider c59180e2 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Completing the registre, seems to have solved the pb with just volatile

integers... Still keeping the reg if one day lektor will be multi
threaded.
parent 88043182
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!33Registre
...@@ -79,6 +79,7 @@ CREATE TABLE IF NOT EXISTS queue ...@@ -79,6 +79,7 @@ CREATE TABLE IF NOT EXISTS queue
-- - `single` whether only one kara loops -- - `single` whether only one kara loops
-- - `current` the position in the queue of the kara being played -- - `current` the position in the queue of the kara being played
-- - `elapsed` the number of seconds from the beginning of the current kara -- - `elapsed` the number of seconds from the beginning of the current kara
-- - `duration` the total duration of the playing kara
CREATE TABLE IF NOT EXISTS queue_state CREATE TABLE IF NOT EXISTS queue_state
( id INTEGER PRIMARY KEY DEFAULT 42 CHECK(id = 42) ( id INTEGER PRIMARY KEY DEFAULT 42 CHECK(id = 42)
, volume INTEGER NOT NULL DEFAULT 100 CHECK(0 <= volume AND volume <= 100) , volume INTEGER NOT NULL DEFAULT 100 CHECK(0 <= volume AND volume <= 100)
...@@ -89,6 +90,7 @@ CREATE TABLE IF NOT EXISTS queue_state ...@@ -89,6 +90,7 @@ CREATE TABLE IF NOT EXISTS queue_state
, consume INTEGER NOT NULL DEFAULT 0 , consume INTEGER NOT NULL DEFAULT 0
, current INTEGER CHECK(current > 0) , current INTEGER CHECK(current > 0)
, duration INTEGER CHECK(duration >= 0) , duration INTEGER CHECK(duration >= 0)
, elapsed INTEGER CHECK(elapsed >= 0)
); );
INSERT INTO queue_state (id) VALUES (42); INSERT INTO queue_state (id) VALUES (42);
......
...@@ -3,7 +3,19 @@ ...@@ -3,7 +3,19 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
typedef struct reg_s reg_t; struct reg_cell {
uint64_t key;
volatile void *value;
volatile bool empty;
struct reg_cell *next_cell;
volatile unsigned int *atomic;
};
typedef struct {
struct reg_cell *cells;
volatile unsigned int *atomic;
volatile int *read_count;
} reg_t;
typedef enum { typedef enum {
reg_code_ok = 0, reg_code_ok = 0,
...@@ -12,9 +24,6 @@ typedef enum { ...@@ -12,9 +24,6 @@ typedef enum {
reg_code_busy = 3, reg_code_busy = 3,
} reg_code; } reg_code;
/* Initializer for the register. */
#define REG_INIT { .cells = NULL, .atomic = 0, .read_count = 0 }
/* Create an empty slot in the register. */ /* Create an empty slot in the register. */
reg_code reg_empty(reg_t *reg, uint64_t *key, void *value); reg_code reg_empty(reg_t *reg, uint64_t *key, void *value);
......
...@@ -3,20 +3,6 @@ ...@@ -3,20 +3,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <sched.h> #include <sched.h>
struct reg_cell {
uint64_t key;
volatile void *value;
volatile bool empty;
struct reg_cell *next_cell;
volatile unsigned int *atomic;
};
struct reg_s {
struct reg_cell *cells;
volatile unsigned int *atomic;
volatile int *read_count;
};
#if defined(i686_ARCH) || defined(x86_64_ARCH) #if defined(i686_ARCH) || defined(x86_64_ARCH)
static inline int static inline int
......
...@@ -30,6 +30,8 @@ struct module_x11_window { ...@@ -30,6 +30,8 @@ struct module_x11_window {
/* Mpv related */ /* Mpv related */
mpv_handle *mpv; mpv_handle *mpv;
volatile int mpv_time_pos; // Don't write it in the database //
volatile int mpv_duration; // Because don't need to be persistent //
}; };
/* /*
...@@ -224,7 +226,7 @@ lmpv_free(mpv_handle **ctx) ...@@ -224,7 +226,7 @@ lmpv_free(mpv_handle **ctx)
static bool static bool
lmpv_handle(struct lkt_win *win, sqlite3 *db, long long int *mpd_idle_events) lmpv_handle(struct lkt_win *win, sqlite3 *db, long long int *mpd_idle_events)
{ {
int ao_volume, mpv_duration; int ao_volume;
struct lkt_queue_state state; struct lkt_queue_state state;
bool sta = false; bool sta = false;
struct module_x11_window *win_x11 = win->window; struct module_x11_window *win_x11 = win->window;
...@@ -271,8 +273,13 @@ lmpv_handle(struct lkt_win *win, sqlite3 *db, long long int *mpd_idle_events) ...@@ -271,8 +273,13 @@ lmpv_handle(struct lkt_win *win, sqlite3 *db, long long int *mpd_idle_events)
// File duration // // File duration //
if (!strcmp(prop->name, "duration") if (!strcmp(prop->name, "duration")
&& prop->format == MPV_FORMAT_INT64) { && prop->format == MPV_FORMAT_INT64) {
mpv_duration = *(int *) prop->data; win_x11->mpv_duration = *(int *) prop->data;
database_config(db, "duration", mpv_duration); database_config(db, "duration", prop->data);
}
if (!strcmp(prop->name, "time-pos")
&& prop->format == MPV_FORMAT_INT64) {
win_x11->mpv_time_pos = *(int *) prop->data;
database_config(db, "elapsed", prop->data);
} }
// Pause state // // Pause state //
if (!strcmp(prop->name, "pause") if (!strcmp(prop->name, "pause")
...@@ -343,6 +350,9 @@ lmpv_new(unsigned long int wid) ...@@ -343,6 +350,9 @@ lmpv_new(unsigned long int wid)
if ((status = mpv_observe_property(ctx, 0, "duration", MPV_FORMAT_INT64)) < 0) if ((status = mpv_observe_property(ctx, 0, "duration", MPV_FORMAT_INT64)) < 0)
goto error; goto error;
if ((status = mpv_observe_property(ctx, 0, "time-pos", MPV_FORMAT_INT64)) < 0)
goto error;
if ((status = mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG)) < 0) if ((status = mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG)) < 0)
goto error; goto error;
...@@ -539,19 +549,8 @@ module_x11_get_duration(struct lkt_win *const win, int *dur_sec) ...@@ -539,19 +549,8 @@ module_x11_get_duration(struct lkt_win *const win, int *dur_sec)
if (win == NULL || win->window == NULL) if (win == NULL || win->window == NULL)
return false; return false;
mpv_handle *ctx = ((struct module_x11_window *) win->window)->mpv; struct module_x11_window *win_x11 = win->window;
int status; *dur_sec = win_x11->mpv_duration;
if (!ctx) {
fprintf(stderr, " ! module_x11_get_duration: failed due to missing mpv ctx\n");
return false;
}
if ((status = mpv_get_property(ctx, "duration", MPV_FORMAT_INT64, dur_sec)) < 0) {
fprintf(stderr, " ! module_x11_get_duration: Failed to get property 'duration': %s\n",
mpv_error_string(status));
return false;
}
return true; return true;
} }
...@@ -562,19 +561,8 @@ module_x11_get_elapsed(struct lkt_win *const win, int *elapsed_sec) ...@@ -562,19 +561,8 @@ module_x11_get_elapsed(struct lkt_win *const win, int *elapsed_sec)
if (win == NULL || win->window == NULL) if (win == NULL || win->window == NULL)
return false; return false;
mpv_handle *ctx = ((struct module_x11_window *) win->window)->mpv; struct module_x11_window *win_x11 = win->window;
int status; *elapsed_sec = win_x11->mpv_time_pos;
if (!ctx) {
fprintf(stderr, " ! module_x11_get_elapsed: failed due to missing mpv ctx\n");
return false;
}
if ((status = mpv_get_property(ctx, "time-pos", MPV_FORMAT_INT64, elapsed_sec)) < 0) {
fprintf(stderr, " ! module_x11_get_elapsed: Failed to get property 'time-pos': %s\n",
mpv_error_string(status));
return false;
}
return true; return true;
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter