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