pollfd.c
来自「CS架构的多平台的GUI系统」· C语言 代码 · 共 107 行
C
107 行
/*************************************************************************** begin : Tue May 25 2004 copyright : (C) 2004 - 2005 by Alper Akcan email : distchx@yahoo.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation; either version 2.1 of the * * License, or (at your option) any later version. * * * ***************************************************************************/#include "xynth_.h"int s_pollfd_init (s_pollfd_t **pfd){ (*pfd) = (s_pollfd_t *) s_calloc(1, sizeof(s_pollfd_t)); (*pfd)->fd = -1; return 0;}int s_pollfd_uninit (s_pollfd_t *pfd){ s_free(pfd); return 0;}int s_pollfd_find_cmp_f (void *p1, void *p2){ s_pollfd_t *p1_ = (s_pollfd_t *) p1; s_pollfd_t *p2_ = (s_pollfd_t *) p2; if (p1_->fd == p2_->fd) { return 0; } return -1;}s_pollfd_t * s_pollfd_find (s_window_t *window, int fd){ s_pollfd_t pfd; s_pollfd_t *ret; pfd.fd = fd; s_thread_mutex_lock(window->pollfds->mut); ret = (s_pollfd_t *) s_list_find(window->pollfds->list, &pfd, s_pollfd_find_cmp_f); s_thread_mutex_unlock(window->pollfds->mut); return ret;}int s_pollfd_add (s_window_t *window, s_pollfd_t *pfd){ int ret = 0; s_thread_mutex_lock(window->pollfds->mut); if (s_list_get_pos(window->pollfds->list, pfd) < 0) { ret = s_list_add(window->pollfds->list, pfd, -1); } s_thread_mutex_unlock(window->pollfds->mut); s_client_wakeup(window); return ret;}int s_pollfd_del (s_window_t *window, s_pollfd_t *pfd){ int ret; s_thread_mutex_lock(window->pollfds->mut); ret = s_list_remove(window->pollfds->list, s_list_get_pos(window->pollfds->list, pfd)); s_thread_mutex_unlock(window->pollfds->mut); s_client_wakeup(window); return ret;}int s_pollfds_init (s_window_t *window){ window->pollfds = (s_pollfds_t *) s_calloc(1, sizeof(s_pollfds_t)); window->pollfds->list = (s_list_t *) s_calloc(1, sizeof(s_list_t)); if (s_thread_mutex_init(&(window->pollfds->mut))) { goto err0; } return s_list_init(window->pollfds->list);err0: s_free(window->pollfds->list); s_free(window->pollfds); return -1;}int s_pollfds_uninit (s_window_t *window){ s_pollfd_t *pfd; s_thread_mutex_lock(window->pollfds->mut); while (!s_list_eol(window->pollfds->list, 0)) { pfd = (s_pollfd_t *) s_list_get(window->pollfds->list, 0); s_list_remove(window->pollfds->list, 0); if (pfd->pf_close != NULL) { pfd->pf_close(window, pfd->fd); } s_pollfd_uninit(pfd); } s_thread_mutex_unlock(window->pollfds->mut); s_thread_mutex_destroy(window->pollfds->mut); s_free(window->pollfds->list); s_free(window->pollfds); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?