aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-03-30 14:22:03 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-03-30 14:24:01 +0200
commitc710a0da4ebcc126275c42a0387ff85b2557e3ae (patch)
treeef27fc3cb68c93475c37965fbcf0b2f8236370ca
parent89c44a872117fb8f64d38cbccf8f36776f2623f6 (diff)
Overall integration of job initialisation
Move the job initialisation from main to jobs. Change-Id: I8f5b54adb62e60592884ff1e3fad9811b5934d47 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-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