blob: c4800cdd194cd298056b67ace3b4eb9498f46118 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include "../parameters/parameters.h"
#include "../knowledge/knowledge.h"
#include "server.h"
static int initialize_worker_collection
(
struct ZoO_server_thread_collection c [const restrict static 1]
)
{
int error;
c->threads = (struct ZoO_server_thread_data *) NULL;
c->threads_capacity = 0;
c->currently_running = 0;
error =
pthread_mutex_init
(
&(c->mutex),
(const pthread_mutexattr_t *) NULL
);
if (error != 0)
{
ZoO_FATAL
(
stderr,
"Unable to initialize worker collection's mutex: %s.",
strerror(error)
);
return -1;
}
error =
pthread_barrier_init
(
&(c->barrier),
(const pthread_barrierattr_t *) NULL,
2
);
if (error != 0)
{
ZoO_FATAL
(
stderr,
"[F] Unable to initialize worker collection's barrier: %s.",
strerror(error)
);
return -1;
}
return 0;
}
void initialize_thread_parameters
(
struct ZoO_server server [const restrict static 1],
const struct ZoO_parameters params [const restrict static 1]
)
{
server->thread_params.thread_collection = &(server->workers);
server->thread_params.server_params = params;
server->thread_params.knowledge = &(server->k);
server->thread_params.socket = -1;
}
int ZoO_server_initialize
(
struct ZoO_server server [const restrict static 1],
const struct ZoO_parameters params [const restrict static 1]
)
{
if (initialize_worker_collection(&(server->workers)) < 0)
{
return -1;
}
if (ZoO_knowledge_initialize(&(server->k)) < 0)
{
return -1;
}
if
(
ZoO_server_socket_open
(
&(server->socket),
ZoO_parameters_get_session_name(params)
) < 0
)
{
return -2;
}
initialize_thread_parameters(server, params);
return 0;
}
|