aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/support
diff options
context:
space:
mode:
authorGravatar David Klempner <klempner@imsanet.org>2015-02-04 13:14:13 -0800
committerGravatar David Klempner <klempner@imsanet.org>2015-02-04 13:14:13 -0800
commit01a0fb05a9b4733eca30f5c2c035974892d832e9 (patch)
tree8077e2a7afc0c68bbcbc4f9f28cf27552f4f12cb /src/core/support
parent9b60fa3acd9b48441f8f0a2062cfd2df7ebeeb8b (diff)
parent5de37830adb84cf6445cc27744f256ffb5fb64d8 (diff)
Merge branch 'master' into timespec
Diffstat (limited to 'src/core/support')
-rw-r--r--src/core/support/thd_posix.c8
-rw-r--r--src/core/support/thd_win32.c8
-rw-r--r--src/core/support/time.c16
3 files changed, 14 insertions, 18 deletions
diff --git a/src/core/support/thd_posix.c b/src/core/support/thd_posix.c
index bac1d9c220..74ca9424bb 100644
--- a/src/core/support/thd_posix.c
+++ b/src/core/support/thd_posix.c
@@ -62,17 +62,19 @@ int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg,
const gpr_thd_options *options) {
int thread_started;
pthread_attr_t attr;
+ pthread_t p;
struct thd_arg *a = gpr_malloc(sizeof(*a));
a->body = thd_body;
a->arg = arg;
GPR_ASSERT(pthread_attr_init(&attr) == 0);
GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0);
- thread_started = (pthread_create(t, &attr, &thread_body, a) == 0);
+ thread_started = (pthread_create(&p, &attr, &thread_body, a) == 0);
GPR_ASSERT(pthread_attr_destroy(&attr) == 0);
if (!thread_started) {
gpr_free(a);
}
+ *t = (gpr_thd_id)p;
return thread_started;
}
@@ -82,4 +84,8 @@ gpr_thd_options gpr_thd_options_default(void) {
return options;
}
+gpr_thd_id gpr_thd_currentid(void) {
+ return (gpr_thd_id)pthread_self();
+}
+
#endif /* GPR_POSIX_SYNC */
diff --git a/src/core/support/thd_win32.c b/src/core/support/thd_win32.c
index 1762f87f3c..2ee1417048 100644
--- a/src/core/support/thd_win32.c
+++ b/src/core/support/thd_win32.c
@@ -58,16 +58,18 @@ static DWORD WINAPI thread_body(void *v) {
int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg,
const gpr_thd_options *options) {
HANDLE handle;
+ DWORD thread_id;
struct thd_arg *a = gpr_malloc(sizeof(*a));
a->body = thd_body;
a->arg = arg;
*t = 0;
- handle = CreateThread(NULL, 64 * 1024, thread_body, a, 0, NULL);
+ handle = CreateThread(NULL, 64 * 1024, thread_body, a, 0, &thread_id);
if (handle == NULL) {
gpr_free(a);
} else {
CloseHandle(handle); /* threads are "detached" */
}
+ *t = (gpr_thd_id)thread_id;
return handle != NULL;
}
@@ -77,4 +79,8 @@ gpr_thd_options gpr_thd_options_default(void) {
return options;
}
+gpr_thd_id gpr_thd_currentid(void) {
+ return (gpr_thd_id)GetCurrentThreadId();
+}
+
#endif /* GPR_WIN32 */
diff --git a/src/core/support/time.c b/src/core/support/time.c
index 97243318fd..268a43c677 100644
--- a/src/core/support/time.c
+++ b/src/core/support/time.c
@@ -234,22 +234,6 @@ int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold) {
}
}
-struct timeval gpr_timeval_from_timespec(gpr_timespec t) {
- /* TODO(klempner): Consider whether this should round up, since it is likely
- to be used for delays */
- struct timeval tv;
- tv.tv_sec = t.tv_sec;
- tv.tv_usec = t.tv_nsec / 1000;
- return tv;
-}
-
-gpr_timespec gpr_timespec_from_timeval(struct timeval t) {
- gpr_timespec ts;
- ts.tv_sec = t.tv_sec;
- ts.tv_nsec = t.tv_usec * 1000;
- return ts;
-}
-
gpr_int32 gpr_time_to_millis(gpr_timespec t) {
if (t.tv_sec >= 2147483) {
if (t.tv_sec == 2147483 && t.tv_nsec < 648 * GPR_NS_PER_MS) {