unsigned int _is_started:1;
};
-static lms_db_audio_t *_singleton = NULL;
+static struct lms_db_cache _cache = {0, NULL};
static int
_db_create(sqlite3 *db, const char *name, const char *sql)
{
lms_db_audio_t *lda;
- if (_singleton) {
- _singleton->_references++;
- return _singleton;
+ if (lms_db_cache_get(&_cache, db, (void**)&lda) == 0) {
+ lda->_references++;
+ return lda;
}
if (!db)
lda->_references = 1;
lda->db = db;
+ if (lms_db_cache_add(&_cache, db, lda) != 0) {
+ lms_db_audio_free(lda);
+ return NULL;
+ }
+
return lda;
}
int
lms_db_audio_free(lms_db_audio_t *lda)
{
+ int r;
+
if (!lda)
return -1;
if (lda->_references == 0) {
if (lda->get_genre)
lms_db_finalize_stmt(lda->get_genre, "get_genre");
+ r = lms_db_cache_del(&_cache, lda->db, lda);
free(lda);
- _singleton = NULL;
- return 0;
+ return r;
}
static int
unsigned int _is_started:1;
};
-static lms_db_image_t *_singleton = NULL;
+static struct lms_db_cache _cache = {0, NULL};
static int
_db_table_updater_images_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
{
lms_db_image_t *ldi;
- if (_singleton) {
- _singleton->_references++;
- return _singleton;
+ if (lms_db_cache_get(&_cache, db, (void**)&ldi) == 0) {
+ ldi->_references++;
+ return ldi;
}
if (!db)
ldi->_references = 1;
ldi->db = db;
+ if (lms_db_cache_add(&_cache, db, ldi) != 0) {
+ lms_db_image_free(ldi);
+ return NULL;
+ }
+
return ldi;
}
int
lms_db_image_free(lms_db_image_t *ldi)
{
+ int r;
+
if (!ldi)
return -1;
if (ldi->_references == 0) {
if (ldi->insert)
lms_db_finalize_stmt(ldi->insert, "insert");
+ r = lms_db_cache_del(&_cache, ldi->db, ldi);
free(ldi);
- _singleton = NULL;
- return 0;
+ return r;
}
static int
unsigned int _is_started:1;
};
-static lms_db_playlist_t *_singleton = NULL;
+static struct lms_db_cache _cache = {0, NULL};
static int
_db_table_updater_playlists_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
{
lms_db_playlist_t *ldp;
- if (_singleton) {
- _singleton->_references++;
- return _singleton;
+ if (lms_db_cache_get(&_cache, db, (void**)&ldp) == 0) {
+ ldp->_references++;
+ return ldp;
}
if (!db)
ldp->_references = 1;
ldp->db = db;
+ if (lms_db_cache_add(&_cache, db, ldp) != 0) {
+ lms_db_playlist_free(ldp);
+ return NULL;
+ }
+
return ldp;
}
int
lms_db_playlist_free(lms_db_playlist_t *ldp)
{
+ int r;
+
if (!ldp)
return -1;
if (ldp->_references == 0) {
if (ldp->insert)
lms_db_finalize_stmt(ldp->insert, "insert");
+ r = lms_db_cache_del(&_cache, ldp->db, ldp);
free(ldp);
- _singleton = NULL;
- return 0;
+ return r;
}
static int
unsigned int _is_started:1;
};
-static lms_db_video_t *_singleton = NULL;
+static struct lms_db_cache _cache = {0, NULL};
static int
_db_table_updater_videos_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
{
lms_db_video_t *ldv;
- if (_singleton) {
- _singleton->_references++;
- return _singleton;
+ if (lms_db_cache_get(&_cache, db, (void**)&ldv) == 0) {
+ ldv->_references++;
+ return ldv;
}
if (!db)
ldv->_references = 1;
ldv->db = db;
+ if (lms_db_cache_add(&_cache, db, ldv) != 0) {
+ lms_db_video_free(ldv);
+ return NULL;
+ }
+
return ldv;
}
int
lms_db_video_free(lms_db_video_t *ldv)
{
+ int r;
+
if (!ldv)
return -1;
if (ldv->_references == 0) {
if (ldv->insert)
lms_db_finalize_stmt(ldv->insert, "insert");
+ r = lms_db_cache_del(&_cache, ldv->db, ldv);
free(ldv);
- _singleton = NULL;
- return 0;
+ return r;
}
static int