* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
- *
- * Copyright © 2006 Pierre Habouzit
+ */
+/*
+ * Copyright © 2007 Pierre Habouzit
*/
#include <pthread.h>
static int epollfd = -1;
static job_array jobs;
+static pthread_mutex_t mx;
+static pthread_t el_thread;
static int el_job_setemode(job_t *w, el_mode emode)
{
return nr;
}
+void el_lock(void)
+{
+ pthread_mutex_lock(&mx);
+}
+
+void el_unlock(void)
+{
+ pthread_mutex_unlock(&mx);
+}
+
int el_dispatch(int timeout)
{
struct epoll_event events[FD_SETSIZE];
mutt_exit(EXIT_FAILURE);
}
+ el_lock();
while (--count >= 0) {
job_t *w = events[count].data.ptr;
int event = events[count].events;
break;
}
}
+ el_unlock();
return 0;
}
-void *el_loop(void *data)
+static void *el_loop(void *data)
{
time_t sec = time(NULL);
continue;
sec = now.tv_sec;
now.tv_sec -= 10;
+
+ el_lock();
for (int i = jobs.len - 1; i >= 0; --i) {
job_t *w = jobs.arr[i];
- if (timercmp(&now, &w->mru, >))
+ if (timercmp(&now, &w->mru, >)) {
IGNORE(w->m->on_event(w, EL_EVT_WAKEUP));
+ }
}
+ el_unlock();
}
}
void el_initialize(void)
{
+ pthread_mutexattr_t attr;
+
+ pthread_mutexattr_init(&attr);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+ pthread_mutex_init(&mx, &attr);
+ pthread_mutexattr_destroy(&attr);
+
gnutls_global_init();
epollfd = epoll_create(1024);
if (epollfd < 0) {
mutt_exit(EXIT_FAILURE);
}
job_array_init(&jobs);
+ pthread_create(&el_thread, NULL, &el_loop, NULL);
}
void el_shutdown(void)
{
+ pthread_cancel(el_thread);
+ pthread_join(el_thread, NULL);
job_array_wipe(&jobs);
close(epollfd);
gnutls_global_deinit();
+ pthread_mutex_destroy(&mx);
}