cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / queue_common.c
blob8c3c9b3c6a9930762f4056c83e8d9f20d7195169
1 /*
2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 */
5 #include "cmogstored.h"
7 /*
8 * access to this should only be called in the main thread, this
9 * is currently not thread safe as there's no need for it.
11 static LIST_HEAD(queue_head, mog_queue) all_queues;
13 struct mog_queue *mog_queue_init(int queue_fd)
15 struct mog_fd *mfd;
16 struct mog_queue *q;
19 * Do not bother with epoll_create1(EPOLL_CLOEXEC),
20 * there's no kqueue version of it. We only create epoll/kqueue
21 * descriptors before we'd ever fork anything
23 CHECK(int, 0, mog_set_cloexec(queue_fd, true));
25 mfd = mog_fd_init(queue_fd, MOG_FD_TYPE_QUEUE);
26 q = &mfd->as.queue;
27 q->queue_fd = queue_fd;
28 memset(&q->thrpool, 0, sizeof(struct mog_thrpool));
29 LIST_INSERT_HEAD(&all_queues, q, qbuddies);
31 return q;
34 void mog_queue_stop(struct mog_queue *keep)
36 struct mog_queue *queue, *tmp;
37 struct mog_fd *mfd;
39 LIST_FOREACH_SAFE(queue, &all_queues, qbuddies, tmp) {
40 /* keep is usually mog_notify_queue */
41 if (queue == keep)
42 continue;
43 LIST_REMOVE(queue, qbuddies);
44 mog_thrpool_quit(&queue->thrpool, queue);
45 mfd = mog_fd_of(queue);
46 mog_fd_put(mfd);
50 void mog_queue_drop(struct mog_fd *mfd)
52 switch (mfd->fd_type) {
53 case MOG_FD_TYPE_HTTP:
54 case MOG_FD_TYPE_HTTPGET:
55 mog_http_drop(mfd);
56 return;
57 case MOG_FD_TYPE_MGMT:
58 mog_mgmt_drop(mfd);
59 return;
60 default:
61 syslog(LOG_ERR,
62 "dropping fd_type=%d, functionality may be compromised",
63 mfd->fd_type);
64 mog_fd_put(mfd);