summaryrefslogtreecommitdiff
path: root/usr/src/cmd/bhyve/test/tests/mevent/mevent.c
blob: 51c94a4c095d8375bbb0b7c13bf1bca6d7273a83 (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
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2018 Joyent, Inc.
 */

#include "../../../mevent.c"
#include "testlib.h"

/*
 * Returns by reference the number of events on the global and change lists.
 *
 * Used by tests that wish to ensure that the event count changes as suggested
 * by mevent_add() and mevent_delete().  Note that a delete does not immediately
 * delete an event.  Events that are pending delete are included in the change
 * list until the next pass through the change list to process pending changes.
 */
void
test_mevent_count_lists(int *ret_global, int *ret_change, int *ret_del_pending)
{
	struct mevent *mevp;
	int global = 0;
	int change = 0;
	int del_pending = 0;

	mevent_qlock();

	LIST_FOREACH(mevp, &global_head, me_list) {
		global++;
		VERBOSE(("on global: type %d fd %d state %d", mevp->me_type,
		    mevp->me_fd, mevp->me_state));
	}

	LIST_FOREACH(mevp, &change_head, me_list) {
		change++;
		if (mevp->me_state == EV_DELETE) {
			del_pending++;
		}
		VERBOSE(("on change: type %d fd %d state %d", mevp->me_type,
		    mevp->me_fd, mevp->me_state));
	}

	mevent_qunlock();

	*ret_global = global;
	*ret_change = change;
	*ret_del_pending = del_pending;
}

void
set_mevent_file_poll_interval_ms(int ms)
{
	mevent_file_poll_interval_ms = ms;
}