All Data Structures Files Functions Variables Typedefs Macros
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 #define NS_JOB_DISABLE_ONLY 0x200
241 
259 typedef unsigned short ns_job_type_t;
260 
265 #define NS_JOB_IS_ACCEPT(eee) ((eee)&NS_JOB_ACCEPT)
266 
270 #define NS_JOB_IS_READ(eee) ((eee)&NS_JOB_READ)
271 
275 #define NS_JOB_IS_CONNECT(eee) ((eee)&NS_JOB_CONNECT)
276 
280 #define NS_JOB_IS_WRITE(eee) ((eee)&NS_JOB_WRITE)
281 
285 #define NS_JOB_IS_TIMER(eee) ((eee)&NS_JOB_TIMER)
286 
290 #define NS_JOB_IS_SIGNAL(eee) ((eee)&NS_JOB_SIGNAL)
291 
295 #define NS_JOB_IS_PERSIST(eee) ((eee)&NS_JOB_PERSIST)
296 
300 #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))
301 
305 #define NS_JOB_IS_THREAD(eee) ((eee)&NS_JOB_THREAD)
306 
310 #define NS_JOB_IS_PRESERVE_FD(eee) ((eee)&NS_JOB_PRESERVE_FD)
311 
315 #define NS_JOB_IS_DISABLE_ONLY(eee) ((eee)&NS_JOB_DISABLE_ONLY)
316 
320 #define NS_JOB_SET_READ(eee) ((eee) |= NS_JOB_READ)
321 
324 #define NS_JOB_SET_WRITE(eee) ((eee) |= NS_JOB_WRITE)
325 
328 #define NS_JOB_SET_THREAD(eee) ((eee) |= NS_JOB_THREAD)
329 
332 #define NS_JOB_UNSET_READ(eee) ((eee) &= ~NS_JOB_READ)
333 
336 #define NS_JOB_UNSET_WRITE(eee) ((eee) &= ~NS_JOB_WRITE)
337 
340 #define NS_JOB_UNSET_THREAD(eee) ((eee) &= ~NS_JOB_THREAD)
341 
344 #define NS_JOB_UNSET_DISABLE_ONLY(eee) ((eee) &= ~NS_JOB_DISABLE_ONLY)
345 
366  int init_flag;
368  PRInt32 initial_threads;
369  PRInt32 max_threads;
370  PRUint32 stacksize;
371  PRUint32 event_queue_size;
372  PRUint32 work_queue_size;
374  /* pluggable logging functions */
375  void (*log_fct)(int, const char *, va_list);
376  void (*log_start_fct)();
377  void (*log_close_fct)();
379  /* pluggable memory functions */
380  void* (*malloc_fct)(size_t);
381  void* (*calloc_fct)(size_t, size_t);
382  void* (*realloc_fct)(void *, size_t);
383  void (*free_fct)(void *);
384 };
385 
402 void ns_thrpool_config_init(struct ns_thrpool_config *tp_config);
403 
430 void ns_job_done(struct ns_job_t *job);
431 
467 PRStatus ns_add_io_job(struct ns_thrpool_t *tp,
468  PRFileDesc *fd,
469  ns_job_type_t job_type,
470  ns_job_func_t func,
471  void *data,
472  struct ns_job_t **job);
473 
492 PRStatus ns_add_timeout_job(struct ns_thrpool_t *tp,
493  struct timeval *tv,
494  ns_job_type_t job_type,
495  ns_job_func_t func,
496  void *data,
497  struct ns_job_t **job);
498 
540 PRStatus ns_add_io_timeout_job(struct ns_thrpool_t *tp,
541  PRFileDesc *fd,
542  struct timeval *tv,
543  ns_job_type_t job_type,
544  ns_job_func_t func,
545  void *data,
546  struct ns_job_t **job);
547 
566 PRStatus ns_add_signal_job(ns_thrpool_t *tp,
567  PRInt32 signum,
568  ns_job_type_t job_type,
569  ns_job_func_t func,
570  void *data,
571  struct ns_job_t **job);
572 
600 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);
601 
620 PRFileDesc *ns_job_get_fd(struct ns_job_t *job);
621 
641 void *ns_job_get_data(struct ns_job_t *job);
642 
661 
682 ns_thrpool_t *ns_job_get_tp(struct ns_job_t *job);
683 
705 
722 struct ns_thrpool_t *ns_thrpool_new(struct ns_thrpool_config *config);
723 
735 void ns_thrpool_destroy(struct ns_thrpool_t *tp);
736 
764 void ns_thrpool_shutdown(struct ns_thrpool_t *tp);
765 
776 PRInt32 ns_thrpool_is_shutdown(struct ns_thrpool_t *tp);
777 
794 PRStatus ns_thrpool_wait(struct ns_thrpool_t *tp);
795 
796 
813 void ns_job_rearm(struct ns_job_t *job);
854 void ns_job_modify(struct ns_job_t *job, ns_job_type_t job_type);
855 
856 #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)
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)
void(* ns_job_func_t)(struct ns_job_t *)
Definition: nunc-stans.h:82
void ns_job_done(struct ns_job_t *job)
void(* log_close_fct)()
Definition: nunc-stans.h:377
PRUint32 event_queue_size
Definition: nunc-stans.h:371
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:369
PRFileDesc * ns_job_get_fd(struct ns_job_t *job)
struct ns_thrpool_t * ns_thrpool_new(struct ns_thrpool_config *config)
void ns_job_rearm(struct ns_job_t *job)
void(* log_start_fct)()
Definition: nunc-stans.h:376
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:364
void ns_job_modify(struct ns_job_t *job, ns_job_type_t job_type)
void * ns_job_get_data(struct ns_job_t *job)
PRUint32 stacksize
Definition: nunc-stans.h:370
void ns_thrpool_destroy(struct ns_thrpool_t *tp)
PRInt32 ns_thrpool_is_shutdown(struct ns_thrpool_t *tp)
void(* log_fct)(int, const char *, va_list)
Definition: nunc-stans.h:375
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)
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
unsigned short ns_job_type_t
Definition: nunc-stans.h:259
void(* free_fct)(void *)
Definition: nunc-stans.h:383
void ns_thrpool_config_init(struct ns_thrpool_config *tp_config)
PRUint32 work_queue_size
Definition: nunc-stans.h:372
ns_thrpool_t * ns_job_get_tp(struct ns_job_t *job)
PRInt32 initial_threads
Definition: nunc-stans.h:368