nunc-stans.h
Go to the documentation of this file.
1 /* --- BEGIN COPYRIGHT BLOCK ---
2  * Copyright (C) 2015 Red Hat
3  * see files 'COPYING' and 'COPYING.openssl' for use and warranty
4  * information
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Additional permission under GPLv3 section 7:
20  *
21  * If you modify this Program, or any covered work, by linking or
22  * combining it with OpenSSL, or a modified version of OpenSSL licensed
23  * under the OpenSSL license
24  * (https://www.openssl.org/source/license.html), the licensors of this
25  * Program grant you additional permission to convey the resulting
26  * work. Corresponding Source for a non-source form of such a
27  * combination shall include the source code for the parts that are
28  * licensed under the OpenSSL license as well as that of the covered
29  * work.
30  * --- END COPYRIGHT BLOCK ---
31  */
37 #ifdef HAVE_CONFIG_H
38 # include <config.h>
39 #endif
40 
41 #ifndef NS_THRPOOL_H
42 
43 #define NS_THRPOOL_H
44 
46 #include "nspr.h"
47 
54 struct ns_thrpool_t;
61 typedef struct ns_thrpool_t ns_thrpool_t;
62 
74 struct ns_job_t;
75 
82 typedef void (*ns_job_func_t)(struct ns_job_t *);
83 
93 #define NS_JOB_NONE 0x0
94 
115 #define NS_JOB_ACCEPT 0x1
116 
126 #define NS_JOB_CONNECT 0x2
127 
137 #define NS_JOB_READ 0x4
138 
148 #define NS_JOB_WRITE 0x8
149 
159 #define NS_JOB_TIMER 0x10
160 
170 #define NS_JOB_SIGNAL 0x20
171 
193 #define NS_JOB_PERSIST 0x40
194 
212 #define NS_JOB_THREAD 0x80
213 
221 #define NS_JOB_PRESERVE_FD 0x100
222 
240 typedef unsigned short ns_job_type_t;
241 
246 #define NS_JOB_IS_ACCEPT(eee) ((eee)&NS_JOB_ACCEPT)
247 
251 #define NS_JOB_IS_READ(eee) ((eee)&NS_JOB_READ)
252 
256 #define NS_JOB_IS_CONNECT(eee) ((eee)&NS_JOB_CONNECT)
257 
261 #define NS_JOB_IS_WRITE(eee) ((eee)&NS_JOB_WRITE)
262 
266 #define NS_JOB_IS_TIMER(eee) ((eee)&NS_JOB_TIMER)
267 
271 #define NS_JOB_IS_SIGNAL(eee) ((eee)&NS_JOB_SIGNAL)
272 
276 #define NS_JOB_IS_PERSIST(eee) ((eee)&NS_JOB_PERSIST)
277 
281 #define NS_JOB_IS_IO(eee) (NS_JOB_IS_ACCEPT(eee)||NS_JOB_IS_READ(eee)||NS_JOB_IS_CONNECT(eee)||NS_JOB_IS_WRITE(eee))
282 
286 #define NS_JOB_IS_THREAD(eee) ((eee)&NS_JOB_THREAD)
287 
291 #define NS_JOB_IS_PRESERVE_FD(eee) ((eee)&NS_JOB_PRESERVE_FD)
292 
296 #define NS_JOB_SET_READ(eee) ((eee) |= NS_JOB_READ)
297 
300 #define NS_JOB_SET_WRITE(eee) ((eee) |= NS_JOB_WRITE)
301 
304 #define NS_JOB_SET_THREAD(eee) ((eee) |= NS_JOB_THREAD)
305 
308 #define NS_JOB_UNSET_READ(eee) ((eee) &= ~NS_JOB_READ)
309 
312 #define NS_JOB_UNSET_WRITE(eee) ((eee) &= ~NS_JOB_WRITE)
313 
316 #define NS_JOB_UNSET_THREAD(eee) ((eee) &= ~NS_JOB_THREAD)
317 
338  int init_flag;
340  PRInt32 max_threads;
341  PRUint32 stacksize;
343  /* pluggable logging functions */
344  void (*log_fct)(int, const char *, va_list);
345  void (*log_start_fct)( void );
346  void (*log_close_fct)( void );
348  /* pluggable memory functions */
349  void* (*malloc_fct)(size_t);
350  void* (*memalign_fct)(size_t size, size_t alignment);
351  void* (*calloc_fct)(size_t, size_t);
352  void* (*realloc_fct)(void *, size_t);
353  void (*free_fct)(void *);
354 };
355 
372 void ns_thrpool_config_init(struct ns_thrpool_config *tp_config);
373 
403 PRStatus ns_job_done(struct ns_job_t *job);
404 
435 PRStatus
436 ns_create_job(struct ns_thrpool_t *tp, ns_job_type_t job_type, ns_job_func_t func, struct ns_job_t **job);
437 
473 PRStatus ns_add_io_job(struct ns_thrpool_t *tp,
474  PRFileDesc *fd,
475  ns_job_type_t job_type,
476  ns_job_func_t func,
477  void *data,
478  struct ns_job_t **job);
479 
498 PRStatus ns_add_timeout_job(struct ns_thrpool_t *tp,
499  struct timeval *tv,
500  ns_job_type_t job_type,
501  ns_job_func_t func,
502  void *data,
503  struct ns_job_t **job);
504 
546 PRStatus ns_add_io_timeout_job(struct ns_thrpool_t *tp,
547  PRFileDesc *fd,
548  struct timeval *tv,
549  ns_job_type_t job_type,
550  ns_job_func_t func,
551  void *data,
552  struct ns_job_t **job);
553 
572 PRStatus ns_add_signal_job(ns_thrpool_t *tp,
573  PRInt32 signum,
574  ns_job_type_t job_type,
575  ns_job_func_t func,
576  void *data,
577  struct ns_job_t **job);
578 
606 PRStatus ns_add_job(ns_thrpool_t *tp, ns_job_type_t job_type, ns_job_func_t func, void *data, struct ns_job_t **job);
607 
626 PRFileDesc *ns_job_get_fd(struct ns_job_t *job);
627 
647 void *ns_job_get_data(struct ns_job_t *job);
648 
681 PRStatus ns_job_set_data(struct ns_job_t *job, void *data);
682 
701 
722 ns_thrpool_t *ns_job_get_tp(struct ns_job_t *job);
723 
745 
767 PRStatus ns_job_set_done_cb(struct ns_job_t *job, ns_job_func_t func);
768 
785 struct ns_thrpool_t *ns_thrpool_new(struct ns_thrpool_config *config);
786 
798 void ns_thrpool_destroy(struct ns_thrpool_t *tp);
799 
827 void ns_thrpool_shutdown(struct ns_thrpool_t *tp);
828 
839 PRInt32 ns_thrpool_is_shutdown(struct ns_thrpool_t *tp);
840 
857 PRStatus ns_thrpool_wait(struct ns_thrpool_t *tp);
858 
859 
873 PRStatus ns_job_rearm(struct ns_job_t *job);
874 
875 #endif /* NS_THRPOOL_H */
PRStatus ns_thrpool_wait(struct ns_thrpool_t *tp)
ns_job_type_t ns_job_get_output_type(struct ns_job_t *job)
void(* log_start_fct)(void)
Definition: nunc-stans.h:345
PRStatus ns_add_signal_job(ns_thrpool_t *tp, PRInt32 signum, ns_job_type_t job_type, ns_job_func_t func, void *data, struct ns_job_t **job)
PRStatus ns_create_job(struct ns_thrpool_t *tp, ns_job_type_t job_type, ns_job_func_t func, struct ns_job_t **job)
void(* log_close_fct)(void)
Definition: nunc-stans.h:346
void(* log_fct)(int, const char *, va_list)
Definition: nunc-stans.h:344
void ns_thrpool_shutdown(struct ns_thrpool_t *tp)
PRStatus ns_add_io_timeout_job(struct ns_thrpool_t *tp, PRFileDesc *fd, struct timeval *tv, ns_job_type_t job_type, ns_job_func_t func, void *data, struct ns_job_t **job)
PRInt32 max_threads
Definition: nunc-stans.h:340
PRFileDesc * ns_job_get_fd(struct ns_job_t *job)
struct ns_thrpool_t * ns_thrpool_new(struct ns_thrpool_config *config)
PRStatus ns_job_set_done_cb(struct ns_job_t *job, ns_job_func_t func)
PRStatus ns_add_io_job(struct ns_thrpool_t *tp, PRFileDesc *fd, ns_job_type_t job_type, ns_job_func_t func, void *data, struct ns_job_t **job)
Definition: nunc-stans.h:336
void * ns_job_get_data(struct ns_job_t *job)
PRUint32 stacksize
Definition: nunc-stans.h:341
void ns_thrpool_destroy(struct ns_thrpool_t *tp)
PRInt32 ns_thrpool_is_shutdown(struct ns_thrpool_t *tp)
void(* ns_job_func_t)(struct ns_job_t *)
Definition: nunc-stans.h:82
PRStatus ns_add_job(ns_thrpool_t *tp, ns_job_type_t job_type, ns_job_func_t func, void *data, struct ns_job_t **job)
PRStatus ns_job_set_data(struct ns_job_t *job, void *data)
ns_job_type_t ns_job_get_type(struct ns_job_t *job)
PRStatus ns_add_timeout_job(struct ns_thrpool_t *tp, struct timeval *tv, ns_job_type_t job_type, ns_job_func_t func, void *data, struct ns_job_t **job)
struct ns_thrpool_t ns_thrpool_t
Definition: nunc-stans.h:61
void(* free_fct)(void *)
Definition: nunc-stans.h:353
unsigned short ns_job_type_t
Definition: nunc-stans.h:240
void ns_thrpool_config_init(struct ns_thrpool_config *tp_config)
PRStatus ns_job_done(struct ns_job_t *job)
ns_thrpool_t * ns_job_get_tp(struct ns_job_t *job)
PRStatus ns_job_rearm(struct ns_job_t *job)