aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-05-07 08:25:02 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-05-07 08:25:02 -0700
commitf666adef90b05c1c0878a0971c14d7f306eeb62e (patch)
treec39eee8f1fddbe7f8737c93421832cd8bdc83896 /src/core
parentf9e6adf998ed36479ccbb8eb3cdc58b02cc161dd (diff)
parent63733efd730316c0317a5df4f288aac242014d91 (diff)
Merge github.com:grpc/grpc into churn-churn-churn-the-api-gently-down-the-stream
Diffstat (limited to 'src/core')
-rw-r--r--src/core/profiling/basic_timers.c14
-rw-r--r--src/core/profiling/stap_probes.d1
-rw-r--r--src/core/profiling/stap_timers.c5
-rw-r--r--src/core/profiling/timers.h12
-rw-r--r--src/core/support/slice_buffer.c33
-rw-r--r--src/core/surface/call.c11
-rw-r--r--src/core/transport/chttp2_transport.c30
-rw-r--r--src/core/transport/stream_op.c31
8 files changed, 97 insertions, 40 deletions
diff --git a/src/core/profiling/basic_timers.c b/src/core/profiling/basic_timers.c
index 866833f225..124a8d6621 100644
--- a/src/core/profiling/basic_timers.c
+++ b/src/core/profiling/basic_timers.c
@@ -45,7 +45,12 @@
#include <grpc/support/thd.h>
#include <stdio.h>
-typedef enum { BEGIN = '{', END = '}', MARK = '.' } marker_type;
+typedef enum {
+ BEGIN = '{',
+ END = '}',
+ MARK = '.',
+ IMPORTANT = '!'
+} marker_type;
typedef struct grpc_timer_entry {
grpc_precise_clock tm;
@@ -101,6 +106,13 @@ void grpc_timer_add_mark(int tag, void* id, const char* file, int line) {
}
}
+void grpc_timer_add_important_mark(int tag, void* id, const char* file,
+ int line) {
+ if (tag < GRPC_PTAG_IGNORE_THRESHOLD) {
+ grpc_timers_log_add(tag, IMPORTANT, id, file, line);
+ }
+}
+
void grpc_timer_begin(int tag, void* id, const char* file, int line) {
if (tag < GRPC_PTAG_IGNORE_THRESHOLD) {
grpc_timers_log_add(tag, BEGIN, id, file, line);
diff --git a/src/core/profiling/stap_probes.d b/src/core/profiling/stap_probes.d
index 374eeedd6c..153de91752 100644
--- a/src/core/profiling/stap_probes.d
+++ b/src/core/profiling/stap_probes.d
@@ -1,5 +1,6 @@
provider _stap {
probe add_mark(int tag);
+ probe add_important_mark(int tag);
probe timing_ns_begin(int tag);
probe timing_ns_end(int tag);
};
diff --git a/src/core/profiling/stap_timers.c b/src/core/profiling/stap_timers.c
index 6e3a965dae..064c86e794 100644
--- a/src/core/profiling/stap_timers.c
+++ b/src/core/profiling/stap_timers.c
@@ -46,6 +46,11 @@ void grpc_timer_add_mark(int tag, void* id, const char* file, int line) {
_STAP_ADD_MARK(tag);
}
+void grpc_timer_add_important_mark(int tag, void* id, const char* file,
+ int line) {
+ _STAP_ADD_IMPORTANT_MARK(tag);
+}
+
void grpc_timer_begin(int tag, void* id, const char* file, int line) {
_STAP_TIMING_NS_BEGIN(tag);
}
diff --git a/src/core/profiling/timers.h b/src/core/profiling/timers.h
index 0b0f7152e7..4fb465c237 100644
--- a/src/core/profiling/timers.h
+++ b/src/core/profiling/timers.h
@@ -42,6 +42,8 @@ void grpc_timers_global_init(void);
void grpc_timers_global_destroy(void);
void grpc_timer_add_mark(int tag, void *id, const char *file, int line);
+void grpc_timer_add_important_mark(int tag, void *id, const char *file,
+ int line);
void grpc_timer_begin(int tag, void *id, const char *file, int line);
void grpc_timer_end(int tag, void *id, const char *file, int line);
@@ -82,6 +84,10 @@ enum grpc_profiling_tags {
do { \
} while (0)
+#define GRPC_TIMER_IMPORTANT_MARK(tag, id) \
+ do { \
+ } while (0)
+
#define GRPC_TIMER_BEGIN(tag, id) \
do { \
} while (0)
@@ -102,6 +108,12 @@ enum grpc_profiling_tags {
grpc_timer_add_mark(tag, ((void *)(gpr_intptr)(id)), __FILE__, __LINE__); \
}
+#define GRPC_TIMER_IMPORTANT_MARK(tag, id) \
+ if (tag < GRPC_PTAG_IGNORE_THRESHOLD) { \
+ grpc_timer_add_important_mark(tag, ((void *)(gpr_intptr)(id)), __FILE__, \
+ __LINE__); \
+ }
+
#define GRPC_TIMER_BEGIN(tag, id) \
if (tag < GRPC_PTAG_IGNORE_THRESHOLD) { \
grpc_timer_begin(tag, ((void *)(gpr_intptr)(id)), __FILE__, __LINE__); \
diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c
index 3b1daa07c5..91b5d8c98b 100644
--- a/src/core/support/slice_buffer.c
+++ b/src/core/support/slice_buffer.c
@@ -37,6 +37,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include <grpc/support/useful.h>
/* grow a buffer; requires GRPC_SLICE_BUFFER_INLINE_ELEMENTS > 1 */
#define GROW(x) (3 * (x) / 2)
@@ -162,14 +163,30 @@ void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb) {
}
void gpr_slice_buffer_swap(gpr_slice_buffer *a, gpr_slice_buffer *b) {
- gpr_slice_buffer temp = *a;
- *a = *b;
- *b = temp;
-
- if (a->slices == b->inlined) {
+ GPR_SWAP(size_t, a->count, b->count);
+ GPR_SWAP(size_t, a->capacity, b->capacity);
+ GPR_SWAP(size_t, a->length, b->length);
+
+ if (a->slices == a->inlined) {
+ if (b->slices == b->inlined) {
+ /* swap contents of inlined buffer */
+ gpr_slice temp[GRPC_SLICE_BUFFER_INLINE_ELEMENTS];
+ memcpy(temp, a->slices, b->count * sizeof(gpr_slice));
+ memcpy(a->slices, b->slices, a->count * sizeof(gpr_slice));
+ memcpy(b->slices, temp, b->count * sizeof(gpr_slice));
+ } else {
+ /* a is inlined, b is not - copy a inlined into b, fix pointers */
+ a->slices = b->slices;
+ b->slices = b->inlined;
+ memcpy(b->slices, a->inlined, b->count * sizeof(gpr_slice));
+ }
+ } else if (b->slices == b->inlined) {
+ /* b is inlined, a is not - copy b inlined int a, fix pointers */
+ b->slices = a->slices;
a->slices = a->inlined;
- }
- if (b->slices == a->inlined) {
- b->slices = b->inlined;
+ memcpy(a->slices, b->inlined, a->count * sizeof(gpr_slice));
+ } else {
+ /* no inlining: easy swap */
+ GPR_SWAP(gpr_slice *, a->slices, b->slices);
}
}
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index 0782a58fda..7ab9142947 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -235,13 +235,6 @@ struct grpc_call {
#define CALL_FROM_TOP_ELEM(top_elem) \
CALL_FROM_CALL_STACK(grpc_call_stack_from_top_element(top_elem))
-#define SWAP(type, x, y) \
- do { \
- type temp = x; \
- x = y; \
- y = temp; \
- } while (0)
-
static void do_nothing(void *ignored, grpc_op_error also_ignored) {}
static void set_deadline_alarm(grpc_call *call, gpr_timespec deadline);
static void call_on_done_recv(void *call, int success);
@@ -572,12 +565,12 @@ static void finish_live_ioreq_op(grpc_call *call, grpc_ioreq_op op,
call->request_data[GRPC_IOREQ_RECV_STATUS_DETAILS]);
break;
case GRPC_IOREQ_RECV_INITIAL_METADATA:
- SWAP(grpc_metadata_array, call->buffered_metadata[0],
+ GPR_SWAP(grpc_metadata_array, call->buffered_metadata[0],
*call->request_data[GRPC_IOREQ_RECV_INITIAL_METADATA]
.recv_metadata);
break;
case GRPC_IOREQ_RECV_TRAILING_METADATA:
- SWAP(grpc_metadata_array, call->buffered_metadata[1],
+ GPR_SWAP(grpc_metadata_array, call->buffered_metadata[1],
*call->request_data[GRPC_IOREQ_RECV_TRAILING_METADATA]
.recv_metadata);
break;
diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c
index dae1b1e1b7..885838ec5d 100644
--- a/src/core/transport/chttp2_transport.c
+++ b/src/core/transport/chttp2_transport.c
@@ -823,24 +823,26 @@ static void unlock(transport *t) {
finish_reads(t);
/* gather any callbacks that need to be made */
- if (!t->calling_back && cb) {
+ if (!t->calling_back) {
perform_callbacks = prepare_callbacks(t);
if (perform_callbacks) {
t->calling_back = 1;
}
- if (t->error_state == ERROR_STATE_SEEN && !t->writing) {
- call_closed = 1;
- t->calling_back = 1;
- t->cb = NULL; /* no more callbacks */
- t->error_state = ERROR_STATE_NOTIFIED;
- }
- if (t->num_pending_goaways) {
- goaways = t->pending_goaways;
- num_goaways = t->num_pending_goaways;
- t->pending_goaways = NULL;
- t->num_pending_goaways = 0;
- t->cap_pending_goaways = 0;
- t->calling_back = 1;
+ if (cb) {
+ if (t->error_state == ERROR_STATE_SEEN && !t->writing && !t->calling_back) {
+ call_closed = 1;
+ t->calling_back = 1;
+ t->cb = NULL; /* no more callbacks */
+ t->error_state = ERROR_STATE_NOTIFIED;
+ }
+ if (t->num_pending_goaways) {
+ goaways = t->pending_goaways;
+ num_goaways = t->num_pending_goaways;
+ t->pending_goaways = NULL;
+ t->num_pending_goaways = 0;
+ t->cap_pending_goaways = 0;
+ t->calling_back = 1;
+ }
}
}
diff --git a/src/core/transport/stream_op.c b/src/core/transport/stream_op.c
index e1a75adcb6..8996ecac35 100644
--- a/src/core/transport/stream_op.c
+++ b/src/core/transport/stream_op.c
@@ -59,15 +59,30 @@ void grpc_sopb_reset(grpc_stream_op_buffer *sopb) {
}
void grpc_sopb_swap(grpc_stream_op_buffer *a, grpc_stream_op_buffer *b) {
- grpc_stream_op_buffer temp = *a;
- *a = *b;
- *b = temp;
-
- if (a->ops == b->inlined_ops) {
+ GPR_SWAP(size_t, a->nops, b->nops);
+ GPR_SWAP(size_t, a->capacity, b->capacity);
+
+ if (a->ops == a->inlined_ops) {
+ if (b->ops == b->inlined_ops) {
+ /* swap contents of inlined buffer */
+ gpr_slice temp[GRPC_SOPB_INLINE_ELEMENTS];
+ memcpy(temp, a->ops, b->nops * sizeof(grpc_stream_op));
+ memcpy(a->ops, b->ops, a->nops * sizeof(grpc_stream_op));
+ memcpy(b->ops, temp, b->nops * sizeof(grpc_stream_op));
+ } else {
+ /* a is inlined, b is not - copy a inlined into b, fix pointers */
+ a->ops = b->ops;
+ b->ops = b->inlined_ops;
+ memcpy(b->ops, a->inlined_ops, b->nops * sizeof(grpc_stream_op));
+ }
+ } else if (b->ops == b->inlined_ops) {
+ /* b is inlined, a is not - copy b inlined int a, fix pointers */
+ b->ops = a->ops;
a->ops = a->inlined_ops;
- }
- if (b->ops == a->inlined_ops) {
- b->ops = b->inlined_ops;
+ memcpy(a->ops, b->inlined_ops, a->nops * sizeof(grpc_stream_op));
+ } else {
+ /* no inlining: easy swap */
+ GPR_SWAP(grpc_stream_op *, a->ops, b->ops);
}
}