syslog-ng source
mainloop-worker.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013 Balabit
3  * Copyright (c) 1998-2013 Balázs Scheidler
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 #ifndef MAINLOOP_WORKER_H_INCLUDED
25 #define MAINLOOP_WORKER_H_INCLUDED 1
26 
27 #include "mainloop.h"
28 
29 #include <iv_list.h>
30 
31 #define MAIN_LOOP_MIN_WORKER_THREADS 2
32 #define MAIN_LOOP_MAX_WORKER_THREADS 256
33 
34 typedef enum
35 {
42 
43 /*
44  * A batch callback is registered during the processing of messages in a
45  * given thread. Batch callbacks are invoked when the batch is complete.
46  *
47  * This mechanism is used by LogQueueFifo implementation, that consumes
48  * messages into a per-thread, unlocked queue first and once the whole batch
49  * is in, it grabs a lock and propagates the elements towards the consumer.
50  */
51 
52 typedef struct _WorkerBatchCallback
53 {
54  struct iv_list_head list;
56  gpointer user_data;
58 
59 static inline void
60 worker_batch_callback_init(WorkerBatchCallback *self)
61 {
62  INIT_IV_LIST_HEAD(&self->list);
63 }
64 
68 
69 typedef void (*WorkerExitNotificationFunc)(gpointer user_data);
70 
72 
75 
78 void main_loop_worker_run_gc(void);
81 
82 void main_loop_worker_sync_call(void (*func)(void *user_data), void *user_data);
84 
85 gboolean is_reloading_scheduled(void);
86 void set_reloading_scheduled(gboolean scheduled);
87 
88 gboolean main_loop_worker_job_quit(void);
89 
90 gdouble mainloop_sleep_time(const gdouble delay);
91 /* NOTE: If any of the threads using these and the return value
92 * (a.k.a the value of main_loop_workers_quit) is TURE,
93  * the callers must ensure that the thread will exit as soon as possible, and
94  * never call these function again.
95  * (as the exit condition might not be signaled anymore, and the wait would block forever)
96  */
97 gboolean main_loop_worker_wait_for_exit_until(gdouble wait_time);
99 
100 void main_loop_worker_init(void);
101 void main_loop_worker_deinit(void);
102 
104 void main_loop_worker_allocate_thread_space(gint num_threads);
106 
107 static inline void
108 main_loop_assert_worker_thread(void)
109 {
110 #if SYSLOG_NG_ENABLE_DEBUG
112 #endif
113 }
114 
115 #endif
void main_loop_worker_assert_batch_callbacks_were_processed(void)
Definition: mainloop-worker.c:416
void main_loop_worker_thread_start(MainLoopWorkerType worker_type)
Definition: mainloop-worker.c:263
void set_reloading_scheduled(gboolean scheduled)
Definition: mainloop-worker.c:428
void main_loop_worker_finalize_thread_space(void)
Definition: mainloop-worker.c:552
void main_loop_worker_allocate_thread_space(gint num_threads)
Definition: mainloop-worker.c:546
gboolean is_reloading_scheduled(void)
Definition: mainloop-worker.c:422
void main_loop_worker_deinit(void)
Definition: mainloop-worker.c:574
gint main_loop_worker_get_thread_index(void)
Definition: mainloop-worker.c:77
void(* WorkerExitNotificationFunc)(gpointer user_data)
Definition: mainloop-worker.h:69
void main_loop_worker_run_gc(void)
Definition: mainloop-worker.c:291
MainLoopWorkerType
Definition: mainloop-worker.h:35
@ MLW_THREADED_OUTPUT_WORKER
Definition: mainloop-worker.h:38
@ MLW_THREADED_INPUT_WORKER
Definition: mainloop-worker.h:39
@ MLW_UNKNOWN
Definition: mainloop-worker.h:36
@ MAIN_LOOP_WORKER_TYPE_MAX
Definition: mainloop-worker.h:40
@ MLW_ASYNC_WORKER
Definition: mainloop-worker.h:37
void main_loop_worker_job_complete(void)
Definition: mainloop-worker.c:350
gint main_loop_worker_get_max_number_of_threads(void)
Definition: mainloop-worker.c:540
void main_loop_worker_init(void)
Definition: mainloop-worker.c:565
void main_loop_worker_sync_call(void(*func)(void *user_data), void *user_data)
void main_loop_worker_invoke_batch_callbacks(void)
Definition: mainloop-worker.c:402
gboolean main_loop_worker_is_worker_thread(void)
Definition: mainloop-worker.c:150
void main_loop_worker_register_exit_notification_callback(WorkerExitNotificationFunc func, gpointer user_data)
Definition: mainloop-worker.c:225
void main_loop_worker_thread_stop(void)
Definition: mainloop-worker.c:279
gboolean main_loop_worker_job_quit(void)
Definition: mainloop-worker.c:468
void main_loop_sync_worker_startup_and_teardown(void)
Definition: mainloop-worker.c:526
void main_loop_worker_job_start(void)
Definition: mainloop-worker.c:301
void main_loop_worker_register_batch_callback(WorkerBatchCallback *cb)
Definition: mainloop-worker.c:396
void main_loop_worker_wait_for_exit(void)
Definition: mainloop-worker.c:193
gboolean main_loop_worker_wait_for_exit_until(gdouble wait_time)
Definition: mainloop-worker.c:207
gdouble mainloop_sleep_time(const gdouble delay)
Definition: mainloop-worker.c:201
gpointer(* MainLoopTaskFunc)(gpointer user_data)
Definition: mainloop.h:49
#define self
Definition: rcptid.c:38
Definition: mainloop-worker.h:53
gpointer user_data
Definition: mainloop-worker.h:56
MainLoopTaskFunc func
Definition: mainloop-worker.h:55