1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 02:29:28 +02:00

rework static ongoing-functions

This commit is contained in:
B. Petersen 2018-07-02 16:03:32 +02:00
parent 951266872b
commit 23e39cd16e
5 changed files with 18 additions and 14 deletions

View file

@ -381,7 +381,7 @@ void dc_job_do_DC_JOB_CONFIGURE_IMAP(dc_context_t* context, dc_job_t* job)
ongoing_allocated_here = 1; ongoing_allocated_here = 1;
#define PROGRESS(p) \ #define PROGRESS(p) \
if( dc_shall_stop_ongoing ) { goto cleanup; } \ if( context->m_shall_stop_ongoing ) { goto cleanup; } \
context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, (p)<1? 1 : ((p)>999? 999 : (p)), 0); context->m_cb(context, DC_EVENT_CONFIGURE_PROGRESS, (p)<1? 1 : ((p)>999? 999 : (p)), 0);
if( !dc_sqlite3_is_open(context->m_sql) ) { if( !dc_sqlite3_is_open(context->m_sql) ) {
@ -739,21 +739,19 @@ int dc_is_configured(dc_context_t* context)
* Request an ongoing process to start. * Request an ongoing process to start.
* Returns 0=process started, 1=not started, there is running another process * Returns 0=process started, 1=not started, there is running another process
*/ */
static int s_ongoing_running = 0;
int dc_shall_stop_ongoing = 1; /* the value 1 avoids dc_stop_ongoing_process() from stopping already stopped threads */
int dc_alloc_ongoing(dc_context_t* context) int dc_alloc_ongoing(dc_context_t* context)
{ {
if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) { if( context == NULL || context->m_magic != DC_CONTEXT_MAGIC ) {
return 0; return 0;
} }
if( s_ongoing_running || dc_shall_stop_ongoing == 0 ) { if( context->m_ongoing_running || context->m_shall_stop_ongoing == 0 ) {
dc_log_warning(context, 0, "There is already another ongoing process running."); dc_log_warning(context, 0, "There is already another ongoing process running.");
return 0; return 0;
} }
s_ongoing_running = 1; context->m_ongoing_running = 1;
dc_shall_stop_ongoing = 0; context->m_shall_stop_ongoing = 0;
return 1; return 1;
} }
@ -768,8 +766,8 @@ void dc_free_ongoing(dc_context_t* context)
return; return;
} }
s_ongoing_running = 0; context->m_ongoing_running = 0;
dc_shall_stop_ongoing = 1; /* avoids dc_stop_ongoing_process() to stop the thread */ context->m_shall_stop_ongoing = 1; /* avoids dc_stop_ongoing_process() to stop the thread */
} }
@ -803,10 +801,10 @@ void dc_stop_ongoing_process(dc_context_t* context)
return; return;
} }
if( s_ongoing_running && dc_shall_stop_ongoing==0 ) if( context->m_ongoing_running && context->m_shall_stop_ongoing==0 )
{ {
dc_log_info(context, 0, "Signaling the ongoing process to stop ASAP."); dc_log_info(context, 0, "Signaling the ongoing process to stop ASAP.");
dc_shall_stop_ongoing = 1; context->m_shall_stop_ongoing = 1;
} }
else else
{ {

View file

@ -116,6 +116,8 @@ dc_context_t* dc_context_new(dc_callback_t cb, void* userdata, const char* os_na
context->m_smtp = dc_smtp_new(context); context->m_smtp = dc_smtp_new(context);
context->m_os_name = dc_strdup_keep_null(os_name); context->m_os_name = dc_strdup_keep_null(os_name);
context->m_shall_stop_ongoing = 1; /* the value 1 avoids dc_stop_ongoing_process() from stopping already stopped threads */
dc_pgp_init(context); dc_pgp_init(context);
/* Random-seed. An additional seed with more random data is done just before key generation /* Random-seed. An additional seed with more random data is done just before key generation

View file

@ -112,6 +112,10 @@ struct _dc_context
// time smearing - to keep messages in order, we may modify the time by some seconds // time smearing - to keep messages in order, we may modify the time by some seconds
time_t m_last_smeared_timestamp; time_t m_last_smeared_timestamp;
pthread_mutex_t m_smear_critical; pthread_mutex_t m_smear_critical;
// handling ongoing processes initiated by the user
int m_ongoing_running;
int m_shall_stop_ongoing;
}; };

View file

@ -468,7 +468,7 @@ char* dc_initiate_key_transfer(dc_context_t* context)
if( !dc_alloc_ongoing(context) ) { if( !dc_alloc_ongoing(context) ) {
return 0; /* no cleanup as this would call dc_free_ongoing() */ return 0; /* no cleanup as this would call dc_free_ongoing() */
} }
#define CHECK_EXIT if( dc_shall_stop_ongoing ) { goto cleanup; } #define CHECK_EXIT if( context->m_shall_stop_ongoing ) { goto cleanup; }
if( (setup_code=dc_create_setup_code(context)) == NULL ) { /* this may require a keypair to be created. this may take a second ... */ if( (setup_code=dc_create_setup_code(context)) == NULL ) { /* this may require a keypair to be created. this may take a second ... */
goto cleanup; goto cleanup;
@ -917,7 +917,7 @@ static int export_backup(dc_context_t* context, const char* dir)
stmt = dc_sqlite3_prepare(dest_sql, "INSERT INTO backup_blobs (file_name, file_content) VALUES (?, ?);"); stmt = dc_sqlite3_prepare(dest_sql, "INSERT INTO backup_blobs (file_name, file_content) VALUES (?, ?);");
while( (dir_entry=readdir(dir_handle))!=NULL ) while( (dir_entry=readdir(dir_handle))!=NULL )
{ {
if( dc_shall_stop_ongoing ) { if( context->m_shall_stop_ongoing ) {
delete_dest_file = 1; delete_dest_file = 1;
goto cleanup; goto cleanup;
} }
@ -1051,7 +1051,7 @@ static int import_backup(dc_context_t* context, const char* backup_to_import)
stmt = dc_sqlite3_prepare(context->m_sql, "SELECT file_name, file_content FROM backup_blobs ORDER BY id;"); stmt = dc_sqlite3_prepare(context->m_sql, "SELECT file_name, file_content FROM backup_blobs ORDER BY id;");
while( sqlite3_step(stmt) == SQLITE_ROW ) while( sqlite3_step(stmt) == SQLITE_ROW )
{ {
if( dc_shall_stop_ongoing ) { if( context->m_shall_stop_ongoing ) {
goto cleanup; goto cleanup;
} }

View file

@ -433,7 +433,7 @@ uint32_t dc_join_securejoin(dc_context_t* context, const char* qr)
int ret_chat_id = 0; int ret_chat_id = 0;
int ongoing_allocated = 0; int ongoing_allocated = 0;
#define CHECK_EXIT if( dc_shall_stop_ongoing ) { goto cleanup; } #define CHECK_EXIT if( context->m_shall_stop_ongoing ) { goto cleanup; }
uint32_t contact_chat_id = 0; uint32_t contact_chat_id = 0;
dc_lot_t* qr_scan = NULL; dc_lot_t* qr_scan = NULL;
int join_vg = 0; int join_vg = 0;