Initial pollset_set_posix implementation

pull/1888/head
Craig Tiller 10 years ago
parent b7cf08ff73
commit c38bc42d67
  1. 57
      src/core/iomgr/pollset_set_posix.c
  2. 4
      src/core/iomgr/pollset_set_posix.h

@ -36,31 +36,76 @@
#ifdef GPR_POSIX_SOCKET #ifdef GPR_POSIX_SOCKET
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/useful.h>
#include "src/core/iomgr/pollset_set.h" #include "src/core/iomgr/pollset_set.h"
void grpc_pollset_set_init(grpc_pollset_set *pollset_set) { void grpc_pollset_set_init(grpc_pollset_set *pollset_set) {
abort(); memset(pollset_set, 0, sizeof(*pollset_set));
gpr_mu_init(&pollset_set->mu);
} }
void grpc_pollset_set_destroy(grpc_pollset_set *pollset_set) { void grpc_pollset_set_destroy(grpc_pollset_set *pollset_set) {
abort(); gpr_mu_destroy(&pollset_set->mu);
gpr_free(pollset_set->pollsets);
gpr_free(pollset_set->fds);
} }
void grpc_pollset_set_add_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) { void grpc_pollset_set_add_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) {
abort(); size_t i;
gpr_mu_lock(&pollset_set->mu);
if (pollset_set->pollset_count == pollset_set->pollset_capacity) {
pollset_set->pollset_capacity = GPR_MAX(8, 2 * pollset_set->pollset_capacity);
pollset_set->pollsets = gpr_realloc(pollset_set->pollsets, pollset_set->pollset_capacity * sizeof(*pollset_set->pollsets));
}
pollset_set->pollsets[pollset_set->pollset_count++] = pollset;
for (i = 0; i < pollset_set->fd_count; i++) {
grpc_pollset_add_fd(pollset, pollset_set->fds[i]);
}
gpr_mu_unlock(&pollset_set->mu);
} }
void grpc_pollset_set_del_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) { void grpc_pollset_set_del_pollset(grpc_pollset_set *pollset_set, grpc_pollset *pollset) {
abort(); size_t i;
gpr_mu_lock(&pollset_set->mu);
for (i = 0; i < pollset_set->pollset_count; i++) {
if (pollset_set->pollsets[i] == pollset) {
pollset_set->pollset_count--;
GPR_SWAP(grpc_pollset *, pollset_set->pollsets[i], pollset_set->pollsets[pollset_set->pollset_count]);
break;
}
}
gpr_mu_unlock(&pollset_set->mu);
} }
void grpc_pollset_set_add_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) { void grpc_pollset_set_add_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) {
abort(); size_t i;
gpr_mu_lock(&pollset_set->mu);
if (pollset_set->fd_count == pollset_set->fd_capacity) {
pollset_set->fd_capacity = GPR_MAX(8, 2 * pollset_set->fd_capacity);
pollset_set->fds = gpr_realloc(pollset_set->fds, pollset_set->fd_capacity * sizeof(*pollset_set->fds));
}
pollset_set->fds[pollset_set->fd_count++] = fd;
for (i = 0; i < pollset_set->pollset_count; i++) {
grpc_pollset_add_fd(pollset_set->pollsets[i], fd);
}
gpr_mu_unlock(&pollset_set->mu);
} }
void grpc_pollset_set_del_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) { void grpc_pollset_set_del_fd(grpc_pollset_set *pollset_set, grpc_fd *fd) {
abort(); size_t i;
gpr_mu_lock(&pollset_set->mu);
for (i = 0; i < pollset_set->fd_count; i++) {
if (pollset_set->fds[i] == fd) {
pollset_set->fd_count--;
GPR_SWAP(grpc_fd *, pollset_set->fds[i], pollset_set->fds[pollset_set->pollset_count]);
break;
}
}
gpr_mu_unlock(&pollset_set->mu);
} }
#endif /* GPR_POSIX_SOCKET */ #endif /* GPR_POSIX_SOCKET */

@ -42,11 +42,11 @@ typedef struct grpc_pollset_set {
size_t pollset_count; size_t pollset_count;
size_t pollset_capacity; size_t pollset_capacity;
grpc_pollset *pollsets; grpc_pollset **pollsets;
size_t fd_count; size_t fd_count;
size_t fd_capacity; size_t fd_capacity;
grpc_fd *fd; grpc_fd **fds;
} grpc_pollset_set; } grpc_pollset_set;
void grpc_pollset_set_add_fd(grpc_pollset_set *pollset_set, grpc_fd *fd); void grpc_pollset_set_add_fd(grpc_pollset_set *pollset_set, grpc_fd *fd);

Loading…
Cancel
Save