mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
refactor: make dc_jobthread_t safe
This commit is contained in:
committed by
Friedel Ziegelmayer
parent
c7c86f1b03
commit
f671b25cbc
@@ -157,22 +157,20 @@ pub fn dc_context_new(
|
|||||||
bob: Arc::new(RwLock::new(Default::default())),
|
bob: Arc::new(RwLock::new(Default::default())),
|
||||||
last_smeared_timestamp: Arc::new(RwLock::new(0)),
|
last_smeared_timestamp: Arc::new(RwLock::new(0)),
|
||||||
cmdline_sel_chat_id: Arc::new(RwLock::new(0)),
|
cmdline_sel_chat_id: Arc::new(RwLock::new(0)),
|
||||||
sentbox_thread: Arc::new(RwLock::new(unsafe {
|
sentbox_thread: Arc::new(RwLock::new(dc_jobthread_init(
|
||||||
dc_jobthread_init(
|
"SENTBOX",
|
||||||
b"SENTBOX\x00" as *const u8 as *const libc::c_char,
|
"configured_sentbox_folder",
|
||||||
b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char,
|
Imap::new(
|
||||||
Imap::new(
|
cb_get_config,
|
||||||
cb_get_config,
|
cb_set_config,
|
||||||
cb_set_config,
|
cb_precheck_imf,
|
||||||
cb_precheck_imf,
|
cb_receive_imf,
|
||||||
cb_receive_imf,
|
),
|
||||||
),
|
))),
|
||||||
)
|
|
||||||
})),
|
|
||||||
mvbox_thread: Arc::new(RwLock::new(unsafe {
|
mvbox_thread: Arc::new(RwLock::new(unsafe {
|
||||||
dc_jobthread_init(
|
dc_jobthread_init(
|
||||||
b"MVBOX\x00" as *const u8 as *const libc::c_char,
|
"MVBOX",
|
||||||
b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char,
|
"configured_mvbox_folder",
|
||||||
Imap::new(
|
Imap::new(
|
||||||
cb_get_config,
|
cb_get_config,
|
||||||
cb_set_config,
|
cb_set_config,
|
||||||
@@ -284,9 +282,6 @@ pub unsafe fn dc_context_unref(context: &mut Context) {
|
|||||||
dc_close(context);
|
dc_close(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_jobthread_exit(&mut context.sentbox_thread.clone().write().unwrap());
|
|
||||||
dc_jobthread_exit(&mut context.mvbox_thread.clone().write().unwrap());
|
|
||||||
|
|
||||||
free(context.os_name as *mut libc::c_void);
|
free(context.os_name as *mut libc::c_void);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,23 +7,24 @@ use crate::dc_sqlite3::*;
|
|||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
use crate::imap::Imap;
|
use crate::imap::Imap;
|
||||||
use crate::x::*;
|
use crate::x::*;
|
||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct dc_jobthread_t {
|
pub struct dc_jobthread_t {
|
||||||
pub name: *mut libc::c_char,
|
pub name: &'static str,
|
||||||
pub folder_config_name: *mut libc::c_char,
|
pub folder_config_name: &'static str,
|
||||||
pub imap: Imap,
|
pub imap: Imap,
|
||||||
pub state: Arc<(Mutex<JobState>, Condvar)>,
|
pub state: Arc<(Mutex<JobState>, Condvar)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_jobthread_init(
|
pub fn dc_jobthread_init(
|
||||||
name: *const libc::c_char,
|
name: &'static str,
|
||||||
folder_config_name: *const libc::c_char,
|
folder_config_name: &'static str,
|
||||||
imap: Imap,
|
imap: Imap,
|
||||||
) -> dc_jobthread_t {
|
) -> dc_jobthread_t {
|
||||||
dc_jobthread_t {
|
dc_jobthread_t {
|
||||||
name: dc_strdup(name),
|
name,
|
||||||
folder_config_name: dc_strdup(folder_config_name),
|
folder_config_name,
|
||||||
imap,
|
imap,
|
||||||
state: Arc::new((Mutex::new(Default::default()), Condvar::new())),
|
state: Arc::new((Mutex::new(Default::default()), Condvar::new())),
|
||||||
}
|
}
|
||||||
@@ -37,13 +38,6 @@ pub struct JobState {
|
|||||||
using_handle: i32,
|
using_handle: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_jobthread_exit(jobthread: &mut dc_jobthread_t) {
|
|
||||||
free(jobthread.name as *mut libc::c_void);
|
|
||||||
jobthread.name = 0 as *mut libc::c_char;
|
|
||||||
free(jobthread.folder_config_name as *mut libc::c_void);
|
|
||||||
jobthread.folder_config_name = 0 as *mut libc::c_char;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn dc_jobthread_suspend(
|
pub unsafe fn dc_jobthread_suspend(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
jobthread: &dc_jobthread_t,
|
jobthread: &dc_jobthread_t,
|
||||||
@@ -54,7 +48,7 @@ pub unsafe fn dc_jobthread_suspend(
|
|||||||
context,
|
context,
|
||||||
0i32,
|
0i32,
|
||||||
b"Suspending %s-thread.\x00" as *const u8 as *const libc::c_char,
|
b"Suspending %s-thread.\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -73,7 +67,7 @@ pub unsafe fn dc_jobthread_suspend(
|
|||||||
context,
|
context,
|
||||||
0i32,
|
0i32,
|
||||||
b"Unsuspending %s-thread.\x00" as *const u8 as *const libc::c_char,
|
b"Unsuspending %s-thread.\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
|
|
||||||
let &(ref lock, ref cvar) = &*jobthread.state.clone();
|
let &(ref lock, ref cvar) = &*jobthread.state.clone();
|
||||||
@@ -94,7 +88,7 @@ pub unsafe fn dc_jobthread_interrupt_idle(context: &Context, jobthread: &dc_jobt
|
|||||||
context,
|
context,
|
||||||
0,
|
0,
|
||||||
b"Interrupting %s-IDLE...\x00" as *const u8 as *const libc::c_char,
|
b"Interrupting %s-IDLE...\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
|
|
||||||
jobthread.imap.interrupt_idle();
|
jobthread.imap.interrupt_idle();
|
||||||
@@ -131,7 +125,7 @@ pub unsafe fn dc_jobthread_fetch(
|
|||||||
context,
|
context,
|
||||||
0,
|
0,
|
||||||
b"%s-fetch started...\x00" as *const u8 as *const libc::c_char,
|
b"%s-fetch started...\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
jobthread.imap.fetch(context);
|
jobthread.imap.fetch(context);
|
||||||
|
|
||||||
@@ -140,7 +134,7 @@ pub unsafe fn dc_jobthread_fetch(
|
|||||||
context,
|
context,
|
||||||
0i32,
|
0i32,
|
||||||
b"%s-fetch aborted, starting over...\x00" as *const u8 as *const libc::c_char,
|
b"%s-fetch aborted, starting over...\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
jobthread.imap.fetch(context);
|
jobthread.imap.fetch(context);
|
||||||
}
|
}
|
||||||
@@ -148,7 +142,7 @@ pub unsafe fn dc_jobthread_fetch(
|
|||||||
context,
|
context,
|
||||||
0,
|
0,
|
||||||
b"%s-fetch done in %.0f ms.\x00" as *const u8 as *const libc::c_char,
|
b"%s-fetch done in %.0f ms.\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
clock().wrapping_sub(start) as libc::c_double * 1000.0f64
|
clock().wrapping_sub(start) as libc::c_double * 1000.0f64
|
||||||
/ 1000000i32 as libc::c_double,
|
/ 1000000i32 as libc::c_double,
|
||||||
);
|
);
|
||||||
@@ -183,7 +177,9 @@ unsafe fn connect_to_imap(context: &Context, jobthread: &dc_jobthread_t) -> libc
|
|||||||
mvbox_name = dc_sqlite3_get_config(
|
mvbox_name = dc_sqlite3_get_config(
|
||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
jobthread.folder_config_name,
|
CString::new(&jobthread.folder_config_name[..])
|
||||||
|
.unwrap()
|
||||||
|
.as_ptr(),
|
||||||
0 as *const libc::c_char,
|
0 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
if mvbox_name.is_null() {
|
if mvbox_name.is_null() {
|
||||||
@@ -214,7 +210,7 @@ pub unsafe fn dc_jobthread_idle(
|
|||||||
0,
|
0,
|
||||||
b"%s-IDLE will not be started as it was interrupted while not ideling.\x00"
|
b"%s-IDLE will not be started as it was interrupted while not ideling.\x00"
|
||||||
as *const u8 as *const libc::c_char,
|
as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
state.jobs_needed = 0;
|
state.jobs_needed = 0;
|
||||||
return;
|
return;
|
||||||
@@ -246,14 +242,14 @@ pub unsafe fn dc_jobthread_idle(
|
|||||||
context,
|
context,
|
||||||
0i32,
|
0i32,
|
||||||
b"%s-IDLE started...\x00" as *const u8 as *const libc::c_char,
|
b"%s-IDLE started...\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
jobthread.imap.idle(context);
|
jobthread.imap.idle(context);
|
||||||
dc_log_info(
|
dc_log_info(
|
||||||
context,
|
context,
|
||||||
0i32,
|
0i32,
|
||||||
b"%s-IDLE ended.\x00" as *const u8 as *const libc::c_char,
|
b"%s-IDLE ended.\x00" as *const u8 as *const libc::c_char,
|
||||||
jobthread.name,
|
&jobthread.name,
|
||||||
);
|
);
|
||||||
|
|
||||||
jobthread.state.0.lock().unwrap().using_handle = 0;
|
jobthread.state.0.lock().unwrap().using_handle = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user