1/* $OpenLDAP$ */
2/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 *
4 * Copyright 1998-2011 The OpenLDAP Foundation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
10 *
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
14 */
15
16#ifndef LDAP_RQ_H
17#define LDAP_RQ_H 1
18
19#include <ldap_cdefs.h>
20
21LDAP_BEGIN_DECL
22
23typedef struct re_s {
24	struct timeval next_sched;
25	struct timeval interval;
26	LDAP_STAILQ_ENTRY(re_s) tnext; /* it includes running */
27	LDAP_STAILQ_ENTRY(re_s) rnext;
28	ldap_pvt_thread_start_t *routine;
29	void *arg;
30	char *tname;
31	char *tspec;
32} re_t;
33
34typedef struct runqueue_s {
35	LDAP_STAILQ_HEAD(l, re_s) task_list;
36	LDAP_STAILQ_HEAD(rl, re_s) run_list;
37	ldap_pvt_thread_mutex_t	rq_mutex;
38} runqueue_t;
39
40LDAP_F( struct re_s* )
41ldap_pvt_runqueue_insert(
42	struct runqueue_s* rq,
43	time_t interval,
44	ldap_pvt_thread_start_t* routine,
45	void *arg,
46	char *tname,
47	char *tspec
48);
49
50LDAP_F( struct re_s* )
51ldap_pvt_runqueue_find(
52	struct runqueue_s* rq,
53	ldap_pvt_thread_start_t* routine,
54	void *arg
55);
56
57LDAP_F( void )
58ldap_pvt_runqueue_remove(
59	struct runqueue_s* rq,
60	struct re_s* entry
61);
62
63LDAP_F( struct re_s* )
64ldap_pvt_runqueue_next_sched(
65	struct runqueue_s* rq,
66	struct timeval* next_run
67);
68
69LDAP_F( void )
70ldap_pvt_runqueue_runtask(
71	struct runqueue_s* rq,
72	struct re_s* entry
73);
74
75LDAP_F( void )
76ldap_pvt_runqueue_stoptask(
77	struct runqueue_s* rq,
78	struct re_s* entry
79);
80
81LDAP_F( int )
82ldap_pvt_runqueue_isrunning(
83	struct runqueue_s* rq,
84	struct re_s* entry
85);
86
87LDAP_F( void )
88ldap_pvt_runqueue_resched(
89	struct runqueue_s* rq,
90	struct re_s* entry,
91	int defer
92);
93
94LDAP_F( int )
95ldap_pvt_runqueue_persistent_backload(
96	struct runqueue_s* rq
97);
98
99LDAP_END_DECL
100
101#endif
102