summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jobs.c31
-rw-r--r--src/jobs.h1
-rw-r--r--src/main.c29
-rwxr-xr-xsrc/tests/test-thread.sh2
4 files changed, 38 insertions, 25 deletions
diff --git a/src/jobs.c b/src/jobs.c
index 8ffd6b61..5d2a29b4 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -911,3 +911,34 @@ struct sd_event *jobs_get_sd_event()
return events ? events->event : NULL;
}
+/**
+ * run the jobs as
+ * @param allowed_count Maximum count of thread for jobs including this one
+ * @param start_count Count of thread to start now, must be lower.
+ * @param waiter_count Maximum count of jobs that can be waiting.
+ * @param start The start routine to activate (can't be NULL)
+ * @return 0 in case of success or -1 in case of error.
+ */
+int jobs_enter(int allowed_count, int start_count, int waiter_count, void (*start)())
+{
+ /* start */
+ if (sig_monitor_init() < 0) {
+ ERROR("failed to initialise signal handlers");
+ return -1;
+ }
+
+ /* init job processing */
+ if (jobs_init(allowed_count, start_count, waiter_count) < 0) {
+ ERROR("failed to initialise threading");
+ return -1;
+ }
+
+ /* queue the start job */
+ if (jobs_queue0(NULL, 0, (void(*)(int))start) < 0) {
+ ERROR("failed to start runnning jobs");
+ return -1;
+ }
+
+ /* turn as processing thread */
+ return jobs_add_me();
+};
diff --git a/src/jobs.h b/src/jobs.h
index 0eceef3d..6eb0a83d 100644
--- a/src/jobs.h
+++ b/src/jobs.h
@@ -73,4 +73,5 @@ extern int jobs_init(int allowed_count, int start_count, int waiter_count);
extern int jobs_add_me();
extern void jobs_terminate();
+extern int jobs_enter(int allowed_count, int start_count, int waiter_count, void (*start)());
diff --git a/src/main.c b/src/main.c
index 9c2f3c56..71b21388 100644
--- a/src/main.c
+++ b/src/main.c
@@ -41,7 +41,6 @@
#include "afb-hsrv.h"
#include "afb-context.h"
#include "afb-hreq.h"
-#include "sig-monitor.h"
#include "jobs.h"
#include "afb-session.h"
#include "verbose.h"
@@ -397,7 +396,7 @@ static int execute_command()
| job for starting the daemon
+--------------------------------------------------------- */
-static void start(int signum)
+static void start()
{
struct afb_hsrv *hsrv;
@@ -495,27 +494,9 @@ int main(int argc, char *argv[])
/* ignore any SIGPIPE */
signal(SIGPIPE, SIG_IGN);
- /* start */
- if (sig_monitor_init() < 0) {
- ERROR("failed to initialise signal handlers");
- return 1;
- }
-
- /* init job processing */
- if (jobs_init(3, 1, 20) < 0) {
- ERROR("failed to initialise threading");
- return 1;
- }
-
- /* queue the start job */
- if (jobs_queue0(NULL, 0, start) < 0) {
- ERROR("failed to start runnning jobs");
- return 1;
- }
-
- /* turn as processing thread */
- jobs_add_me();
- WARNING("hoops returned from jobs_add_me! [report bug]");
- return 0;
+ /* enter job processing */
+ jobs_enter(3, 1, 20, start);
+ WARNING("hoops returned from jobs_enter! [report bug]");
+ return 1;
}
diff --git a/src/tests/test-thread.sh b/src/tests/test-thread.sh
index e353e028..a9e2ee3b 100755
--- a/src/tests/test-thread.sh
+++ b/src/tests/test-thread.sh
@@ -1,4 +1,4 @@
#!/bin/sh
-cc test-thread.c ../afb-thread.c ../verbose.c ../sig-monitor.c ../jobs.c -o test-thread -lrt -lpthread -I../../include -g
+cc test-thread.c ../afb-thread.c ../verbose.c ../sig-monitor.c ../jobs.c -o test-thread -lrt -lpthread -lsystemd I../../include -g
./test-thread