| Index: third_party/grpc/src/core/iomgr/socket_utils_posix.c
|
| diff --git a/third_party/tcmalloc/vendor/src/base/synchronization_profiling.h b/third_party/grpc/src/core/iomgr/socket_utils_posix.c
|
| similarity index 63%
|
| copy from third_party/tcmalloc/vendor/src/base/synchronization_profiling.h
|
| copy to third_party/grpc/src/core/iomgr/socket_utils_posix.c
|
| index cf02c218a111806189f71f7b528a83b5ceb164a4..3c56b4674431fbcc898bc9fb7d265ef1f1cc3678 100644
|
| --- a/third_party/tcmalloc/vendor/src/base/synchronization_profiling.h
|
| +++ b/third_party/grpc/src/core/iomgr/socket_utils_posix.c
|
| @@ -1,4 +1,6 @@
|
| -/* Copyright (c) 2010, Google Inc.
|
| +/*
|
| + *
|
| + * Copyright 2015, Google Inc.
|
| * All rights reserved.
|
| *
|
| * Redistribution and use in source and binary forms, with or without
|
| @@ -27,24 +29,42 @@
|
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| *
|
| - * ---
|
| - * Author: Chris Ruemmler
|
| */
|
|
|
| -#ifndef BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
|
| -#define BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
|
| +#include <grpc/support/port_platform.h>
|
| +
|
| +#ifdef GPR_POSIX_SOCKETUTILS
|
| +
|
| +#include "src/core/iomgr/socket_utils_posix.h"
|
|
|
| -#include "base/basictypes.h"
|
| +#include <fcntl.h>
|
| +#include <sys/socket.h>
|
| +#include <unistd.h>
|
|
|
| -namespace base {
|
| +#include <grpc/support/log.h>
|
|
|
| -// We can do contention-profiling of SpinLocks, but the code is in
|
| -// mutex.cc, which is not always linked in with spinlock. Hence we
|
| -// provide a weak definition, which are used if mutex.cc isn't linked in.
|
| +int grpc_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen,
|
| + int nonblock, int cloexec) {
|
| + int fd, flags;
|
|
|
| -// Submit the number of cycles the spinlock spent contending.
|
| -ATTRIBUTE_WEAK extern void SubmitSpinLockProfileData(const void *, int64);
|
| -extern void SubmitSpinLockProfileData(const void *contendedlock,
|
| - int64 wait_cycles) {}
|
| + fd = accept(sockfd, addr, addrlen);
|
| + if (fd >= 0) {
|
| + if (nonblock) {
|
| + flags = fcntl(fd, F_GETFL, 0);
|
| + if (flags < 0) goto close_and_error;
|
| + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) != 0) goto close_and_error;
|
| + }
|
| + if (cloexec) {
|
| + flags = fcntl(fd, F_GETFD, 0);
|
| + if (flags < 0) goto close_and_error;
|
| + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) != 0) goto close_and_error;
|
| + }
|
| + }
|
| + return fd;
|
| +
|
| +close_and_error:
|
| + close(fd);
|
| + return -1;
|
| }
|
| -#endif // BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
|
| +
|
| +#endif /* GPR_POSIX_SOCKETUTILS */
|
|
|