cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob 8c3c9b3c6a9930762f4056c83e8d9f20d7195169 1585 bytes (raw)
$ git show HEAD:queue_common.c	# shows this blob on the CLI

 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
 
/*
 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 */
#include "cmogstored.h"

/*
 * access to this should only be called in the main thread, this
 * is currently not thread safe as there's no need for it.
 */
static LIST_HEAD(queue_head, mog_queue) all_queues;

struct mog_queue *mog_queue_init(int queue_fd)
{
	struct mog_fd *mfd;
	struct mog_queue *q;

	/*
	 * Do not bother with epoll_create1(EPOLL_CLOEXEC),
	 * there's no kqueue version of it.  We only create epoll/kqueue
	 * descriptors before we'd ever fork anything
	 */
	CHECK(int, 0, mog_set_cloexec(queue_fd, true));

	mfd = mog_fd_init(queue_fd, MOG_FD_TYPE_QUEUE);
	q = &mfd->as.queue;
	q->queue_fd = queue_fd;
	memset(&q->thrpool, 0, sizeof(struct mog_thrpool));
	LIST_INSERT_HEAD(&all_queues, q, qbuddies);

	return q;
}

void mog_queue_stop(struct mog_queue *keep)
{
	struct mog_queue *queue, *tmp;
	struct mog_fd *mfd;

	LIST_FOREACH_SAFE(queue, &all_queues, qbuddies, tmp) {
		/* keep is usually mog_notify_queue */
		if (queue == keep)
			continue;
		LIST_REMOVE(queue, qbuddies);
		mog_thrpool_quit(&queue->thrpool, queue);
		mfd = mog_fd_of(queue);
		mog_fd_put(mfd);
	}
}

void mog_queue_drop(struct mog_fd *mfd)
{
	switch (mfd->fd_type) {
	case MOG_FD_TYPE_HTTP:
	case MOG_FD_TYPE_HTTPGET:
		mog_http_drop(mfd);
		return;
	case MOG_FD_TYPE_MGMT:
		mog_mgmt_drop(mfd);
		return;
	default:
		syslog(LOG_ERR,
		       "dropping fd_type=%d, functionality may be compromised",
		       mfd->fd_type);
		mog_fd_put(mfd);
	}
}

git clone https://yhbt.net/cmogstored.git