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

[WIP] REPO: Add the skeleton for id only download

Add the `___worker_update_from_ids` that must be called when the update
is passed with a query with of type ID. With that, the user will be able
to call multiple times the update methods with different ids to queue them.
parent 0e5619dc
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!181Prepare the queued id update + fix add command + FMT
#define __LKT_MODULE_MAIN_SOURCE__ #define __LKT_MODULE_MAIN_SOURCE__
#include <lektor/lktmodule.h> #include <lektor/lktmodule.h>
#include <lektor/stb/ds.h>
#include "worker.h" #include "worker.h"
...@@ -7,6 +8,7 @@ ...@@ -7,6 +8,7 @@
#define REPO_UPDATE_TYPE_COUNT 2 /* Different kinds of download, for some sizes... */ #define REPO_UPDATE_TYPE_COUNT 2 /* Different kinds of download, for some sizes... */
#define REPO_UPDATE_KARA ((unsigned int)(1 << 1)) /* Downloading or rescanning the bakabase */ #define REPO_UPDATE_KARA ((unsigned int)(1 << 1)) /* Downloading or rescanning the bakabase */
#define REPO_UPDATE_FAV ((unsigned int)(1 << 2)) /* Downloading the favorites */ #define REPO_UPDATE_FAV ((unsigned int)(1 << 2)) /* Downloading the favorites */
#define REPO_UPDATE_ALL (REPO_UPDATE_FAV | REPO_UPDATE_KARA) /* Update all flag */
/*********** /***********
* Globals * * Globals *
...@@ -68,8 +70,12 @@ struct module_repo_internal { ...@@ -68,8 +70,12 @@ struct module_repo_internal {
/* Worker threads */ /* Worker threads */
volatile unsigned int updating; volatile unsigned int updating;
bool is_only_updating_from_ids;
pthread_mutex_t mtx; /* Protect the updating field */ pthread_mutex_t mtx; /* Protect the updating field */
struct worker_pool workers; struct worker_pool workers;
/* In the case of `is_only_updating_from_ids`, the list of IDs to download. */
volatile size_t *volatile update_id_stb_list;
}; };
struct update_worker_argument { struct update_worker_argument {
...@@ -99,7 +105,8 @@ struct ___file { ...@@ -99,7 +105,8 @@ struct ___file {
* Some forward declarations * * Some forward declarations *
*****************************/ *****************************/
PRIVATE_FUNCTION void *___worker_update(void UNUSED *worker, void *___repo); PRIVATE_FUNCTION void *___worker_update(void UNUSED *worker, void *___args);
PRIVATE_FUNCTION void *___worker_update_from_ids(void UNUSED *worker, void *___args);
PRIVATE_FUNCTION void *___worker_dry_update(void UNUSED *worker, void *___repo); PRIVATE_FUNCTION void *___worker_dry_update(void UNUSED *worker, void *___repo);
PRIVATE_FUNCTION void *___worker_import_favorites(void *worker, void *___repo); PRIVATE_FUNCTION void *___worker_import_favorites(void *worker, void *___repo);
...@@ -220,6 +227,12 @@ ___write_disk(char *data, size_t size, size_t nmem, void *user) ...@@ -220,6 +227,12 @@ ___write_disk(char *data, size_t size, size_t nmem, void *user)
return realsize; return realsize;
} }
PRIVATE_FUNCTION void
___json_dl_and_handle_for_id(struct module_repo_internal UNUSED *repo, int kara_id)
{
LOG_ERROR("REPO", "To be implemented (debug: handle kara id %d)", kara_id);
}
PRIVATE_FUNCTION int PRIVATE_FUNCTION int
___json_dl(const char *url, char **json) ___json_dl(const char *url, char **json)
{ {
...@@ -626,7 +639,72 @@ end_no_lock: // Failed to take a lock ...@@ -626,7 +639,72 @@ end_no_lock: // Failed to take a lock
"present even if no update is in progress. You need to restart " "present even if no update is in progress. You need to restart "
"lektord to be able to update!"); "lektord to be able to update!");
lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_FINISHED); lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_FINISHED);
free(filter_uri); lkt_uri_free(filter_uri);
return NULL;
}
/* Variat of the ___worker_update function, where we know that the passed
* queries are only ids. Same things as with the former function: the `___args`
* and the `___args->filter_uri` pointers are moved inside the function and will
* be freed by it at the end before returning. */
PRIVATE_FUNCTION void *
___worker_update_from_ids(void UNUSED *worker, void *___args)
{
struct update_worker_argument *arguments = (struct update_worker_argument *)(___args);
struct module_repo_internal *repo = arguments->repo;
struct lkt_uri *filter_uri = arguments->filter_uri;
free(___args);
if (lkt_uri_get_type(filter_uri) != URI_ID) {
LOG_UNREACHABLE;
}
const size_t kara_id = (size_t)lkt_uri_get_value_as_int(filter_uri);
DO_WITH_LOCK(repo->mtx, error_in_locks, {
/* An id only updater is already running */
if (arrlenu(repo->update_id_stb_list) > 0) {
LOG_INFO("REPO", "Add the kara id %zu to the download list", kara_id);
size_t *local_list_ptr = (size_t *)repo->update_id_stb_list;
arrput(local_list_ptr, kara_id);
}
/* No id only updated is already running */
else {
repo->updating |= REPO_UPDATE_KARA;
/* Push the first ID */
{
size_t *local_list_ptr = (size_t *)repo->update_id_stb_list;
arrput(local_list_ptr, kara_id);
}
while (arrlenu(repo->update_id_stb_list) > 0) {
volatile int volatile_local_kara_id =
(volatile int)(volatile size_t)(repo->update_id_stb_list);
const int local_kara_id = (int)volatile_local_kara_id;
DO_WITH_RELAXED_LOCK(repo->mtx, error_in_locks,
{ ___json_dl_and_handle_for_id(repo, local_kara_id); });
/* Pop the first element that was pushed */
{
size_t *local_list_ptr = (size_t *)repo->update_id_stb_list;
arrdel(local_list_ptr, 0);
}
}
repo->updating &= (~REPO_UPDATE_KARA);
}
});
lkt_uri_free(filter_uri);
return NULL;
error_in_locks:
LOG_ERROR("REPO", "Pb in taking or releasing locks, as a security set the flags to "
"'udapting all' to avoid doing some risky things with the "
"repo module...");
repo->updating = REPO_UPDATE_ALL;
lkt_uri_free(filter_uri);
return NULL; return NULL;
} }
...@@ -637,6 +715,7 @@ ___worker_dry_update(void *worker, void *___repo) ...@@ -637,6 +715,7 @@ ___worker_dry_update(void *worker, void *___repo)
struct lkt_uri *null_uri = lkt_uri_new(); struct lkt_uri *null_uri = lkt_uri_new();
lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_PROGRESS); lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_PROGRESS);
/* Should not be needed! */
DO_WITH_LOCK(repo->mtx, end_no_lock, repo->updating |= REPO_UPDATE_KARA); DO_WITH_LOCK(repo->mtx, end_no_lock, repo->updating |= REPO_UPDATE_KARA);
char *json = NULL; char *json = NULL;
......
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