Skip to content

Commit

Permalink
Refactor db_state code
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed May 24, 2015
1 parent 0701990 commit 566eb77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
7 changes: 4 additions & 3 deletions runloop_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ typedef struct nbio_handle

typedef struct database_state_handle
{
struct string_list *list;
size_t list_index;
size_t entry_index;
uint32_t crc;
uint8_t *buf;
} database_state_handle_t;

typedef struct db_handle
{
struct string_list *list;
size_t list_index;
size_t entry_index;
database_state_handle_t state;
database_info_handle_t *handle;
msg_queue_t *msg_queue;
Expand Down
30 changes: 12 additions & 18 deletions tasks/task_database.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,16 @@ static int database_info_iterate_playlist(
else
{
ssize_t ret;
uint32_t crc, target_crc = 0;
int read_from = read_file(name, (void**)&db_state->buf, &ret);

(void)target_crc;

if (read_from != 1 || ret <= 0)
return 0;


#ifdef HAVE_ZLIB
crc = zlib_crc32_calculate(db_state->buf, ret);

RARCH_LOG("CRC32: 0x%x .\n", (unsigned)crc);
db_state->crc = zlib_crc32_calculate(db_state->buf, ret);
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)db_state->crc);
#endif

}


Expand Down Expand Up @@ -168,8 +163,9 @@ static void rarch_main_data_db_cleanup_state(void *data)

void rarch_main_data_db_iterate(bool is_thread, void *data)
{
data_runloop_t *runloop = (data_runloop_t*)data;
database_info_handle_t *db = runloop ? runloop->db.handle : NULL;
data_runloop_t *runloop = (data_runloop_t*)data;
database_info_handle_t *db = runloop ? runloop->db.handle : NULL;
database_state_handle_t *db_state = runloop ? &runloop->db.state : NULL;
const char *name = db ? db->list->elems[db->list_ptr].data : NULL;

if (!db || !runloop)
Expand All @@ -178,16 +174,14 @@ void rarch_main_data_db_iterate(bool is_thread, void *data)
switch (db->status)
{
case DATABASE_STATUS_ITERATE_BEGIN:
if (!runloop->db.list)
{
runloop->db.list = dir_list_new_special(NULL, DIR_LIST_DATABASES);
runloop->db.list_index = 0;
runloop->db.entry_index = 0;
}
if (db_state && !db_state->list)
db_state->list = dir_list_new_special(NULL, DIR_LIST_DATABASES);
db->status = DATABASE_STATUS_ITERATE_START;
break;
case DATABASE_STATUS_ITERATE_START:
rarch_main_data_db_cleanup_state(data);
db_state->list_index = 0;
db_state->entry_index = 0;
database_info_iterate_start(db, name);
break;
case DATABASE_STATUS_ITERATE:
Expand All @@ -206,9 +200,9 @@ void rarch_main_data_db_iterate(bool is_thread, void *data)
}
break;
case DATABASE_STATUS_FREE:
if (runloop->db.list)
dir_list_free(runloop->db.list);
runloop->db.list = NULL;
if (db_state->list)
dir_list_free(db_state->list);
db_state->list = NULL;
rarch_main_data_db_cleanup_state(data);
database_info_free(db);
if (runloop->db.handle)
Expand Down

0 comments on commit 566eb77

Please sign in to comment.