get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/35172/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 35172,
    "url": "http://patches.dpdk.org/api/patches/35172/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180214145330.4679-2-zhiyong.yang@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20180214145330.4679-2-zhiyong.yang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180214145330.4679-2-zhiyong.yang@intel.com",
    "date": "2018-02-14T14:53:27",
    "name": "[dpdk-dev,1/4] vhost: move fdset functions from fd_man.c to fd_man.h",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "cca4e9a92ba1dece96e980ef2430af24f0dc4e3d",
    "submitter": {
        "id": 540,
        "url": "http://patches.dpdk.org/api/people/540/?format=api",
        "name": "Yang, Zhiyong",
        "email": "zhiyong.yang@intel.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20180214145330.4679-2-zhiyong.yang@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/35172/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/35172/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 9A97F1B335;\n\tWed, 14 Feb 2018 15:53:39 +0100 (CET)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 2982B1B308\n\tfor <dev@dpdk.org>; Wed, 14 Feb 2018 15:53:36 +0100 (CET)",
            "from fmsmga007.fm.intel.com ([10.253.24.52])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t14 Feb 2018 06:53:36 -0800",
            "from unknown (HELO dpdk5.bj.intel.com) ([172.16.182.198])\n\tby fmsmga007.fm.intel.com with ESMTP; 14 Feb 2018 06:53:34 -0800"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.46,512,1511856000\"; d=\"scan'208\";a=\"17661398\"",
        "From": "Zhiyong Yang <zhiyong.yang@intel.com>",
        "To": "dev@dpdk.org, yliu@fridaylinux.org, maxime.coquelin@redhat.com,\n\tjianfeng.tan@intel.com, tiwei.bie@intel.com, zhihong.wang@intel.com",
        "Cc": "dong1.wang@intel.com,\n\tZhiyong Yang <zhiyong.yang@intel.com>",
        "Date": "Wed, 14 Feb 2018 22:53:27 +0800",
        "Message-Id": "<20180214145330.4679-2-zhiyong.yang@intel.com>",
        "X-Mailer": "git-send-email 2.13.3",
        "In-Reply-To": "<20180214145330.4679-1-zhiyong.yang@intel.com>",
        "References": "<20180214145330.4679-1-zhiyong.yang@intel.com>",
        "Subject": "[dpdk-dev] [PATCH 1/4] vhost: move fdset functions from fd_man.c to\n\tfd_man.h",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "The patch moves fdset related funcitons from fd_man.c to fd_man.h in\norder to reuse these funcitons from the perspective of PMDs.\n\nSigned-off-by: Zhiyong Yang <zhiyong.yang@intel.com>\n---\n lib/librte_vhost/Makefile |   3 +-\n lib/librte_vhost/fd_man.c | 274 ----------------------------------------------\n lib/librte_vhost/fd_man.h | 258 +++++++++++++++++++++++++++++++++++++++++--\n 3 files changed, 253 insertions(+), 282 deletions(-)\n delete mode 100644 lib/librte_vhost/fd_man.c",
    "diff": "diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile\nindex 5d6c6abae..e201df79c 100644\n--- a/lib/librte_vhost/Makefile\n+++ b/lib/librte_vhost/Makefile\n@@ -21,10 +21,11 @@ endif\n LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev -lrte_net\n \n # all source are stored in SRCS-y\n-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \\\n+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := iotlb.c socket.c vhost.c \\\n \t\t\t\t\tvhost_user.c virtio_net.c\n \n # install includes\n SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h\n+SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += fd_man.h\n \n include $(RTE_SDK)/mk/rte.lib.mk\ndiff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c\ndeleted file mode 100644\nindex 181711c2a..000000000\n--- a/lib/librte_vhost/fd_man.c\n+++ /dev/null\n@@ -1,274 +0,0 @@\n-/* SPDX-License-Identifier: BSD-3-Clause\n- * Copyright(c) 2010-2014 Intel Corporation\n- */\n-\n-#include <stdint.h>\n-#include <stdio.h>\n-#include <stdlib.h>\n-#include <sys/socket.h>\n-#include <sys/time.h>\n-#include <sys/types.h>\n-#include <unistd.h>\n-#include <string.h>\n-\n-#include <rte_common.h>\n-#include <rte_log.h>\n-\n-#include \"fd_man.h\"\n-\n-#define FDPOLLERR (POLLERR | POLLHUP | POLLNVAL)\n-\n-static int\n-get_last_valid_idx(struct fdset *pfdset, int last_valid_idx)\n-{\n-\tint i;\n-\n-\tfor (i = last_valid_idx; i >= 0 && pfdset->fd[i].fd == -1; i--)\n-\t\t;\n-\n-\treturn i;\n-}\n-\n-static void\n-fdset_move(struct fdset *pfdset, int dst, int src)\n-{\n-\tpfdset->fd[dst]    = pfdset->fd[src];\n-\tpfdset->rwfds[dst] = pfdset->rwfds[src];\n-}\n-\n-static void\n-fdset_shrink_nolock(struct fdset *pfdset)\n-{\n-\tint i;\n-\tint last_valid_idx = get_last_valid_idx(pfdset, pfdset->num - 1);\n-\n-\tfor (i = 0; i < last_valid_idx; i++) {\n-\t\tif (pfdset->fd[i].fd != -1)\n-\t\t\tcontinue;\n-\n-\t\tfdset_move(pfdset, i, last_valid_idx);\n-\t\tlast_valid_idx = get_last_valid_idx(pfdset, last_valid_idx - 1);\n-\t}\n-\tpfdset->num = last_valid_idx + 1;\n-}\n-\n-/*\n- * Find deleted fd entries and remove them\n- */\n-static void\n-fdset_shrink(struct fdset *pfdset)\n-{\n-\tpthread_mutex_lock(&pfdset->fd_mutex);\n-\tfdset_shrink_nolock(pfdset);\n-\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-}\n-\n-/**\n- * Returns the index in the fdset for a given fd.\n- * @return\n- *   index for the fd, or -1 if fd isn't in the fdset.\n- */\n-static int\n-fdset_find_fd(struct fdset *pfdset, int fd)\n-{\n-\tint i;\n-\n-\tfor (i = 0; i < pfdset->num && pfdset->fd[i].fd != fd; i++)\n-\t\t;\n-\n-\treturn i == pfdset->num ? -1 : i;\n-}\n-\n-static void\n-fdset_add_fd(struct fdset *pfdset, int idx, int fd,\n-\tfd_cb rcb, fd_cb wcb, void *dat)\n-{\n-\tstruct fdentry *pfdentry = &pfdset->fd[idx];\n-\tstruct pollfd *pfd = &pfdset->rwfds[idx];\n-\n-\tpfdentry->fd  = fd;\n-\tpfdentry->rcb = rcb;\n-\tpfdentry->wcb = wcb;\n-\tpfdentry->dat = dat;\n-\n-\tpfd->fd = fd;\n-\tpfd->events  = rcb ? POLLIN : 0;\n-\tpfd->events |= wcb ? POLLOUT : 0;\n-\tpfd->revents = 0;\n-}\n-\n-void\n-fdset_init(struct fdset *pfdset)\n-{\n-\tint i;\n-\n-\tif (pfdset == NULL)\n-\t\treturn;\n-\n-\tfor (i = 0; i < MAX_FDS; i++) {\n-\t\tpfdset->fd[i].fd = -1;\n-\t\tpfdset->fd[i].dat = NULL;\n-\t}\n-\tpfdset->num = 0;\n-}\n-\n-/**\n- * Register the fd in the fdset with read/write handler and context.\n- */\n-int\n-fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat)\n-{\n-\tint i;\n-\n-\tif (pfdset == NULL || fd == -1)\n-\t\treturn -1;\n-\n-\tpthread_mutex_lock(&pfdset->fd_mutex);\n-\ti = pfdset->num < MAX_FDS ? pfdset->num++ : -1;\n-\tif (i == -1) {\n-\t\tfdset_shrink_nolock(pfdset);\n-\t\ti = pfdset->num < MAX_FDS ? pfdset->num++ : -1;\n-\t\tif (i == -1) {\n-\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-\t\t\treturn -2;\n-\t\t}\n-\t}\n-\n-\tfdset_add_fd(pfdset, i, fd, rcb, wcb, dat);\n-\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-\n-\treturn 0;\n-}\n-\n-/**\n- *  Unregister the fd from the fdset.\n- *  Returns context of a given fd or NULL.\n- */\n-void *\n-fdset_del(struct fdset *pfdset, int fd)\n-{\n-\tint i;\n-\tvoid *dat = NULL;\n-\n-\tif (pfdset == NULL || fd == -1)\n-\t\treturn NULL;\n-\n-\tdo {\n-\t\tpthread_mutex_lock(&pfdset->fd_mutex);\n-\n-\t\ti = fdset_find_fd(pfdset, fd);\n-\t\tif (i != -1 && pfdset->fd[i].busy == 0) {\n-\t\t\t/* busy indicates r/wcb is executing! */\n-\t\t\tdat = pfdset->fd[i].dat;\n-\t\t\tpfdset->fd[i].fd = -1;\n-\t\t\tpfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL;\n-\t\t\tpfdset->fd[i].dat = NULL;\n-\t\t\ti = -1;\n-\t\t}\n-\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-\t} while (i != -1);\n-\n-\treturn dat;\n-}\n-\n-\n-/**\n- * This functions runs in infinite blocking loop until there is no fd in\n- * pfdset. It calls corresponding r/w handler if there is event on the fd.\n- *\n- * Before the callback is called, we set the flag to busy status; If other\n- * thread(now rte_vhost_driver_unregister) calls fdset_del concurrently, it\n- * will wait until the flag is reset to zero(which indicates the callback is\n- * finished), then it could free the context after fdset_del.\n- */\n-void *\n-fdset_event_dispatch(void *arg)\n-{\n-\tint i;\n-\tstruct pollfd *pfd;\n-\tstruct fdentry *pfdentry;\n-\tfd_cb rcb, wcb;\n-\tvoid *dat;\n-\tint fd, numfds;\n-\tint remove1, remove2;\n-\tint need_shrink;\n-\tstruct fdset *pfdset = arg;\n-\tint val;\n-\n-\tif (pfdset == NULL)\n-\t\treturn NULL;\n-\n-\twhile (1) {\n-\n-\t\t/*\n-\t\t * When poll is blocked, other threads might unregister\n-\t\t * listenfds from and register new listenfds into fdset.\n-\t\t * When poll returns, the entries for listenfds in the fdset\n-\t\t * might have been updated. It is ok if there is unwanted call\n-\t\t * for new listenfds.\n-\t\t */\n-\t\tpthread_mutex_lock(&pfdset->fd_mutex);\n-\t\tnumfds = pfdset->num;\n-\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-\n-\t\tval = poll(pfdset->rwfds, numfds, 1000 /* millisecs */);\n-\t\tif (val < 0)\n-\t\t\tcontinue;\n-\n-\t\tneed_shrink = 0;\n-\t\tfor (i = 0; i < numfds; i++) {\n-\t\t\tpthread_mutex_lock(&pfdset->fd_mutex);\n-\n-\t\t\tpfdentry = &pfdset->fd[i];\n-\t\t\tfd = pfdentry->fd;\n-\t\t\tpfd = &pfdset->rwfds[i];\n-\n-\t\t\tif (fd < 0) {\n-\t\t\t\tneed_shrink = 1;\n-\t\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tif (!pfd->revents) {\n-\t\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tremove1 = remove2 = 0;\n-\n-\t\t\trcb = pfdentry->rcb;\n-\t\t\twcb = pfdentry->wcb;\n-\t\t\tdat = pfdentry->dat;\n-\t\t\tpfdentry->busy = 1;\n-\n-\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n-\n-\t\t\tif (rcb && pfd->revents & (POLLIN | FDPOLLERR))\n-\t\t\t\trcb(fd, dat, &remove1);\n-\t\t\tif (wcb && pfd->revents & (POLLOUT | FDPOLLERR))\n-\t\t\t\twcb(fd, dat, &remove2);\n-\t\t\tpfdentry->busy = 0;\n-\t\t\t/*\n-\t\t\t * fdset_del needs to check busy flag.\n-\t\t\t * We don't allow fdset_del to be called in callback\n-\t\t\t * directly.\n-\t\t\t */\n-\t\t\t/*\n-\t\t\t * When we are to clean up the fd from fdset,\n-\t\t\t * because the fd is closed in the cb,\n-\t\t\t * the old fd val could be reused by when creates new\n-\t\t\t * listen fd in another thread, we couldn't call\n-\t\t\t * fd_set_del.\n-\t\t\t */\n-\t\t\tif (remove1 || remove2) {\n-\t\t\t\tpfdentry->fd = -1;\n-\t\t\t\tneed_shrink = 1;\n-\t\t\t}\n-\t\t}\n-\n-\t\tif (need_shrink)\n-\t\t\tfdset_shrink(pfdset);\n-\t}\n-\n-\treturn NULL;\n-}\ndiff --git a/lib/librte_vhost/fd_man.h b/lib/librte_vhost/fd_man.h\nindex 3a9276c3c..b1c628251 100644\n--- a/lib/librte_vhost/fd_man.h\n+++ b/lib/librte_vhost/fd_man.h\n@@ -4,11 +4,11 @@\n \n #ifndef _FD_MAN_H_\n #define _FD_MAN_H_\n-#include <stdint.h>\n-#include <pthread.h>\n #include <poll.h>\n+#include <stdio.h>\n \n #define MAX_FDS 1024\n+#define FDPOLLERR (POLLERR | POLLHUP | POLLNVAL)\n \n typedef void (*fd_cb)(int fd, void *dat, int *remove);\n \n@@ -27,14 +27,258 @@ struct fdset {\n \tint num;\t/* current fd number of this fdset */\n };\n \n+static inline int\n+get_last_valid_idx(struct fdset *pfdset, int last_valid_idx)\n+{\n+\tint i;\n \n-void fdset_init(struct fdset *pfdset);\n+\tfor (i = last_valid_idx; i >= 0 && pfdset->fd[i].fd == -1; i--)\n+\t\t;\n \n-int fdset_add(struct fdset *pfdset, int fd,\n-\tfd_cb rcb, fd_cb wcb, void *dat);\n+\treturn i;\n+}\n \n-void *fdset_del(struct fdset *pfdset, int fd);\n+static inline void\n+fdset_move(struct fdset *pfdset, int dst, int src)\n+{\n+\tpfdset->fd[dst]    = pfdset->fd[src];\n+\tpfdset->rwfds[dst] = pfdset->rwfds[src];\n+}\n \n-void *fdset_event_dispatch(void *arg);\n+static inline void\n+fdset_shrink_nolock(struct fdset *pfdset)\n+{\n+\tint i;\n+\tint last_valid_idx = get_last_valid_idx(pfdset, pfdset->num - 1);\n+\n+\tfor (i = 0; i < last_valid_idx; i++) {\n+\t\tif (pfdset->fd[i].fd != -1)\n+\t\t\tcontinue;\n+\n+\t\tfdset_move(pfdset, i, last_valid_idx);\n+\t\tlast_valid_idx = get_last_valid_idx(pfdset, last_valid_idx - 1);\n+\t}\n+\tpfdset->num = last_valid_idx + 1;\n+}\n+\n+/*\n+ * Find deleted fd entries and remove them\n+ */\n+static inline void\n+fdset_shrink(struct fdset *pfdset)\n+{\n+\tpthread_mutex_lock(&pfdset->fd_mutex);\n+\tfdset_shrink_nolock(pfdset);\n+\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+}\n+\n+/**\n+ * Returns the index in the fdset for a given fd.\n+ * @return\n+ *   index for the fd, or -1 if fd isn't in the fdset.\n+ */\n+static inline int\n+fdset_find_fd(struct fdset *pfdset, int fd)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < pfdset->num && pfdset->fd[i].fd != fd; i++)\n+\t\t;\n+\n+\treturn i == pfdset->num ? -1 : i;\n+}\n+\n+static inline void\n+fdset_add_fd(struct fdset *pfdset, int idx, int fd,\n+\tfd_cb rcb, fd_cb wcb, void *dat)\n+{\n+\tstruct fdentry *pfdentry = &pfdset->fd[idx];\n+\tstruct pollfd *pfd = &pfdset->rwfds[idx];\n+\n+\tpfdentry->fd  = fd;\n+\tpfdentry->rcb = rcb;\n+\tpfdentry->wcb = wcb;\n+\tpfdentry->dat = dat;\n+\n+\tpfd->fd = fd;\n+\tpfd->events  = rcb ? POLLIN : 0;\n+\tpfd->events |= wcb ? POLLOUT : 0;\n+\tpfd->revents = 0;\n+}\n+\n+static inline void\n+fdset_init(struct fdset *pfdset)\n+{\n+\tint i;\n+\n+\tif (pfdset == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < MAX_FDS; i++) {\n+\t\tpfdset->fd[i].fd = -1;\n+\t\tpfdset->fd[i].dat = NULL;\n+\t}\n+\tpfdset->num = 0;\n+}\n+\n+/**\n+ * Register the fd in the fdset with read/write handler and context.\n+ */\n+static inline int\n+fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat)\n+{\n+\tint i;\n+\n+\tif (pfdset == NULL || fd == -1)\n+\t\treturn -1;\n+\n+\tpthread_mutex_lock(&pfdset->fd_mutex);\n+\ti = pfdset->num < MAX_FDS ? pfdset->num++ : -1;\n+\tif (i == -1) {\n+\t\tfdset_shrink_nolock(pfdset);\n+\t\ti = pfdset->num < MAX_FDS ? pfdset->num++ : -1;\n+\t\tif (i == -1) {\n+\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+\t\t\treturn -2;\n+\t\t}\n+\t}\n+\n+\tfdset_add_fd(pfdset, i, fd, rcb, wcb, dat);\n+\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ *  Unregister the fd from the fdset.\n+ *  Returns context of a given fd or NULL.\n+ */\n+static inline void *\n+fdset_del(struct fdset *pfdset, int fd)\n+{\n+\tint i;\n+\tvoid *dat = NULL;\n+\n+\tif (pfdset == NULL || fd == -1)\n+\t\treturn NULL;\n+\n+\tdo {\n+\t\tpthread_mutex_lock(&pfdset->fd_mutex);\n+\n+\t\ti = fdset_find_fd(pfdset, fd);\n+\t\tif (i != -1 && pfdset->fd[i].busy == 0) {\n+\t\t\t/* busy indicates r/wcb is executing! */\n+\t\t\tdat = pfdset->fd[i].dat;\n+\t\t\tpfdset->fd[i].fd = -1;\n+\t\t\tpfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL;\n+\t\t\tpfdset->fd[i].dat = NULL;\n+\t\t\ti = -1;\n+\t\t}\n+\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+\t} while (i != -1);\n+\n+\treturn dat;\n+}\n+\n+/**\n+ * This functions runs in infinite blocking loop until there is no fd in\n+ * pfdset. It calls corresponding r/w handler if there is event on the fd.\n+ *\n+ * Before the callback is called, we set the flag to busy status; If other\n+ * thread(now rte_vhost_driver_unregister) calls fdset_del concurrently, it\n+ * will wait until the flag is reset to zero(which indicates the callback is\n+ * finished), then it could free the context after fdset_del.\n+ */\n+static inline void *\n+fdset_event_dispatch(void *arg)\n+{\n+\tint i;\n+\tstruct pollfd *pfd;\n+\tstruct fdentry *pfdentry;\n+\tfd_cb rcb, wcb;\n+\tvoid *dat;\n+\tint fd, numfds;\n+\tint remove1, remove2;\n+\tint need_shrink;\n+\tstruct fdset *pfdset = arg;\n+\tint val;\n+\n+\tif (pfdset == NULL)\n+\t\treturn NULL;\n+\n+\twhile (1) {\n+\n+\t\t/*\n+\t\t * When poll is blocked, other threads might unregister\n+\t\t * listenfds from and register new listenfds into fdset.\n+\t\t * When poll returns, the entries for listenfds in the fdset\n+\t\t * might have been updated. It is ok if there is unwanted call\n+\t\t * for new listenfds.\n+\t\t */\n+\t\tpthread_mutex_lock(&pfdset->fd_mutex);\n+\t\tnumfds = pfdset->num;\n+\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+\n+\t\tval = poll(pfdset->rwfds, numfds, 1000 /* millisecs */);\n+\t\tif (val < 0)\n+\t\t\tcontinue;\n+\n+\t\tneed_shrink = 0;\n+\t\tfor (i = 0; i < numfds; i++) {\n+\t\t\tpthread_mutex_lock(&pfdset->fd_mutex);\n+\n+\t\t\tpfdentry = &pfdset->fd[i];\n+\t\t\tfd = pfdentry->fd;\n+\t\t\tpfd = &pfdset->rwfds[i];\n+\n+\t\t\tif (fd < 0) {\n+\t\t\t\tneed_shrink = 1;\n+\t\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tif (!pfd->revents) {\n+\t\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tremove1 = remove2 = 0;\n+\n+\t\t\trcb = pfdentry->rcb;\n+\t\t\twcb = pfdentry->wcb;\n+\t\t\tdat = pfdentry->dat;\n+\t\t\tpfdentry->busy = 1;\n+\n+\t\t\tpthread_mutex_unlock(&pfdset->fd_mutex);\n+\n+\t\t\tif (rcb && pfd->revents & (POLLIN | FDPOLLERR))\n+\t\t\t\trcb(fd, dat, &remove1);\n+\t\t\tif (wcb && pfd->revents & (POLLOUT | FDPOLLERR))\n+\t\t\t\twcb(fd, dat, &remove2);\n+\t\t\tpfdentry->busy = 0;\n+\t\t\t/*\n+\t\t\t * fdset_del needs to check busy flag.\n+\t\t\t * We don't allow fdset_del to be called in callback\n+\t\t\t * directly.\n+\t\t\t */\n+\t\t\t/*\n+\t\t\t * When we are to clean up the fd from fdset,\n+\t\t\t * because the fd is closed in the cb,\n+\t\t\t * the old fd val could be reused by when creates new\n+\t\t\t * listen fd in another thread, we couldn't call\n+\t\t\t * fd_set_del.\n+\t\t\t */\n+\t\t\tif (remove1 || remove2) {\n+\t\t\t\tpfdentry->fd = -1;\n+\t\t\t\tneed_shrink = 1;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (need_shrink)\n+\t\t\tfdset_shrink(pfdset);\n+\t}\n+\n+\treturn NULL;\n+}\n \n #endif\n",
    "prefixes": [
        "dpdk-dev",
        "1/4"
    ]
}