summaryrefslogtreecommitdiff
path: root/src/core/thread_sync.c
blob: 19b430af2b11ab6b6822e78d9ac75638e7a3fe3a (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
/* BSD-2-Clause license
 * 
 * Copyright (c) 2018-2023 NST <www.newinfosec.ru>, sss <sss at dark-alexandr dot net>. 
 * 
 */

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>

#include "globals.h"
#include "thread_sync.h"
#include "thread_impl.h"

static void
remove_ws_backend_from_list(user_pool_msg *pmsg)
{
	if (!LIST_EMPTY(&(g_globals.backends_head)))
	{
		struct backend_s *t1 = LIST_FIRST(&(g_globals.backends_head));
		while (t1)
		{
			if (!t1->backend || t1->backend == pmsg->backend)
			{
				LIST_REMOVE(t1, entries);
				free(t1);
				break;
			}
			t1 = LIST_NEXT(t1, entries);
		}
	}

	free(pmsg->backend);
}

void
pool_message_handler(void *user_data)
{
	user_pool_msg *pmsg = user_data;
	if (!pmsg)
	{
		return;
	}
	switch (pmsg->type)
	{
		case msg_type_destroy_ws_backend_info:
		{
			remove_ws_backend_from_list(pmsg);
		}
		break;
		case msg_type_backend_created:
		{
			struct backend_s *t;
			t = calloc(1, sizeof(struct backend_s));
			if (!t)
			{
				perror("calloc");
				free(pmsg);
				return;
			}
			t->backend = pmsg->backend;
			LIST_INSERT_HEAD(
			    &(g_globals.backends_head), t, entries);
		}
		break;
		default:
			break;
	}
	free(pmsg);
}

void
thread_message_handler(void *user_data)
{
}