blob: f6378e0da4ca8027671f3e78ba83aa0026acdbc9 (
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
|
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include "server.h"
static void initialize
(
struct ZoO_server_worker worker [const restrict static 1],
void * input
)
{
memcpy
(
(void *) &(worker->params),
(const void *) input,
sizeof(struct ZoO_server_thread_parameters)
);
pthread_barrier_wait(&(worker->params.thread_collection->barrier));
worker->buffer = (char *) NULL;
worker->buffer_capacity = 0;
worker->buffer_length = 0;
}
static void finalize
(
struct ZoO_server_worker worker [const restrict static 1]
)
{
pthread_mutex_lock(&(worker->params.thread_collection->mutex));
worker->params.thread_collection->threads[worker->params.thread_id].state =
ZoO_SERVER_JOINING_THREAD;
pthread_mutex_unlock(&(worker->params.thread_collection->mutex));
}
void * ZoO_server_worker_main (void * input)
{
struct ZoO_server_worker worker;
initialize(&worker, input);
while (ZoO_server_is_running())
{
if (ZoO_server_worker_receive(&worker) < 0)
{
break;
}
if (ZoO_server_worker_handle_request(&worker) < 0)
{
break;
}
}
finalize(&worker);
return NULL;
}
|