lib:replace: Add getprogname()
[samba.git] / lib / pthreadpool / pthreadpool_sync.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * sync dummy implementation of the pthreadpool API
4  * Copyright (C) Volker Lendecke 2009
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
20
21 #include "replace.h"
22 #include "pthreadpool.h"
23
24 struct pthreadpool {
25         bool stopped;
26
27         /*
28          * Indicate job completion
29          */
30         int (*signal_fn)(int jobid,
31                          void (*job_fn)(void *private_data),
32                          void *job_fn_private_data,
33                          void *private_data);
34         void *signal_fn_private_data;
35 };
36
37 int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
38                      int (*signal_fn)(int jobid,
39                                       void (*job_fn)(void *private_data),
40                                       void *job_fn_private_data,
41                                       void *private_data),
42                      void *signal_fn_private_data)
43 {
44         struct pthreadpool *pool;
45
46         pool = (struct pthreadpool *)calloc(1, sizeof(struct pthreadpool));
47         if (pool == NULL) {
48                 return ENOMEM;
49         }
50         pool->stopped = false;
51         pool->signal_fn = signal_fn;
52         pool->signal_fn_private_data = signal_fn_private_data;
53
54         *presult = pool;
55         return 0;
56 }
57
58 size_t pthreadpool_max_threads(struct pthreadpool *pool)
59 {
60         return 0;
61 }
62
63 size_t pthreadpool_queued_jobs(struct pthreadpool *pool)
64 {
65         return 0;
66 }
67
68 bool pthreadpool_per_thread_cwd(struct pthreadpool *pool)
69 {
70         return false;
71 }
72
73 int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
74                         void (*fn)(void *private_data), void *private_data)
75 {
76         if (pool->stopped) {
77                 return EINVAL;
78         }
79
80         fn(private_data);
81
82         return pool->signal_fn(job_id, fn, private_data,
83                                pool->signal_fn_private_data);
84 }
85
86 int pthreadpool_restart_check(struct pthreadpool *pool)
87 {
88         if (pool->stopped) {
89                 return EINVAL;
90         }
91
92         return 0;
93 }
94
95 int pthreadpool_restart_check_monitor_fd(struct pthreadpool *pool)
96 {
97         errno = ENOSYS;
98         return -1;
99 }
100
101 int pthreadpool_restart_check_monitor_drain(struct pthreadpool *pool)
102 {
103         return EINVAL;
104 }
105
106 size_t pthreadpool_cancel_job(struct pthreadpool *pool, int job_id,
107                               void (*fn)(void *private_data), void *private_data)
108 {
109         return 0;
110 }
111
112 int pthreadpool_stop(struct pthreadpool *pool)
113 {
114         pool->stopped = true;
115         return 0;
116 }
117
118 int pthreadpool_destroy(struct pthreadpool *pool)
119 {
120         free(pool);
121         return 0;
122 }