File: ipc_stress.cc

package info (click to toggle)
tarantool 1.7.2.385.g952d79e-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,556 kB
  • ctags: 28,405
  • sloc: ansic: 180,313; cpp: 26,044; sh: 15,513; python: 4,893; makefile: 1,412
file content (61 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download
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
#include "memory.h"
#include "fiber.h"
#include "ipc.h"
#include "unit.h"

enum {
	ITERATIONS = 100000,
};

static int
push_f(va_list ap)
{
	struct ipc_channel *channel = va_arg(ap, struct ipc_channel *);

	for (int i = 0; i < ITERATIONS; i++)
		ipc_channel_put(channel, NULL);
	return 0;
}

static int
pop_f(va_list ap)
{
	struct ipc_channel *channel = va_arg(ap, struct ipc_channel *);

	for (int i = 0; i < ITERATIONS; i++) {
		void *ptr;
		ipc_channel_get(channel, &ptr);
	}
	return 0;
}

static int
main_f(va_list ap)
{
	header();
	struct fiber *push = fiber_new_xc("push_f", push_f);
	fiber_set_joinable(push, true);
	struct fiber *pop = fiber_new_xc("pop_f", pop_f);
	fiber_set_joinable(pop, true);
	struct ipc_channel *channel = ipc_channel_new(1);
	fiber_start(push, channel);
	fiber_start(pop, channel);
	fiber_join(push);
	fiber_join(pop);
	ipc_channel_delete(channel);
	ev_break(loop(), EVBREAK_ALL);
	footer();
	return 0;
}

int main()
{
	memory_init();
	fiber_init(fiber_c_invoke);
	struct fiber *main= fiber_new_xc("main", main_f);
	fiber_wakeup(main);
	ev_run(loop(), 0);
	fiber_free();
	memory_free();
	return 0;
}