text
stringlengths
0
357
dc_log_info(jobthread->context, 0, "%s-fetch done in %.0f ms.", jobthread->name, (double)(clock()-start)*1000.0/CLOCKS_PER_SEC);
cleanup:
pthread_mutex_lock(&jobthread->mutex);
jobthread->using_handle = 0;
pthread_mutex_unlock(&jobthread->mutex);
}
void dc_jobthread_idle(dc_jobthread_t* jobthread, int use_network)
{
if (jobthread==NULL) {
return;
}
pthread_mutex_lock(&jobthread->mutex);
if (jobthread->jobs_needed) {
dc_log_info(jobthread->context, 0, "%s-IDLE will not be started as it was interrupted while not ideling.", jobthread->name);
jobthread->jobs_needed = 0;
pthread_mutex_unlock(&jobthread->mutex);
return;
}
if (jobthread->suspended) {
while (jobthread->idle_condflag==0) {
// unlock mutex -> wait -> lock mutex
pthread_cond_wait(&jobthread->idle_cond, &jobthread->mutex);
}
jobthread->idle_condflag = 0;
pthread_mutex_unlock(&jobthread->mutex);
return;
}
jobthread->using_handle = 1;
pthread_mutex_unlock(&jobthread->mutex);
if (!use_network || jobthread->imap==NULL) {
pthread_mutex_lock(&jobthread->mutex);
jobthread->using_handle = 0;
while (jobthread->idle_condflag==0) {
// unlock mutex -> wait -> lock mutex
pthread_cond_wait(&jobthread->idle_cond, &jobthread->mutex);
}
jobthread->idle_condflag = 0;
pthread_mutex_unlock(&jobthread->mutex);
return;
}
connect_to_imap(jobthread);
dc_log_info(jobthread->context, 0, "%s-IDLE started...", jobthread->name);
dc_imap_idle(jobthread->imap);
dc_log_info(jobthread->context, 0, "%s-IDLE ended.", jobthread->name);
pthread_mutex_lock(&jobthread->mutex);
jobthread->using_handle = 0;
pthread_mutex_unlock(&jobthread->mutex);
}
void dc_jobthread_interrupt_idle(dc_jobthread_t* jobthread)
{
if (jobthread==NULL) {
return;
}
pthread_mutex_lock(&jobthread->mutex);
// when we're not in idle, make sure not to enter it
jobthread->jobs_needed = 1;
pthread_mutex_unlock(&jobthread->mutex);
dc_log_info(jobthread->context, 0, "Interrupting %s-IDLE...", jobthread->name);
if (jobthread->imap) {
dc_imap_interrupt_idle(jobthread->imap);
}
// in case we're not IMAP-ideling, also raise the signal
pthread_mutex_lock(&jobthread->mutex);
jobthread->idle_condflag = 1;
pthread_cond_signal(&jobthread->idle_cond);
pthread_mutex_unlock(&jobthread->mutex);
}
```
Filename: dc_jsmn.c
```c
/*
Copyright (c) 2010 Serge A. Zaitsev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.