Commit d0c11d20 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: declare addtimer/deltimer in runtime.h

In preparation for integrated network poller
(https://golang.org/cl/7326051),
this is required to handle deadlines.

R=golang-dev, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/7446047
parent db018bf7
...@@ -761,6 +761,8 @@ int64 runtime·cputicks(void); ...@@ -761,6 +761,8 @@ int64 runtime·cputicks(void);
int64 runtime·tickspersecond(void); int64 runtime·tickspersecond(void);
void runtime·blockevent(int64, int32); void runtime·blockevent(int64, int32);
extern int64 runtime·blockprofilerate; extern int64 runtime·blockprofilerate;
void runtime·addtimer(Timer*);
bool runtime·deltimer(Timer*);
#pragma varargck argpos runtime·printf 1 #pragma varargck argpos runtime·printf 1
#pragma varargck type "d" int32 #pragma varargck type "d" int32
......
...@@ -15,7 +15,6 @@ package time ...@@ -15,7 +15,6 @@ package time
static Timers timers; static Timers timers;
static void addtimer(Timer*); static void addtimer(Timer*);
static bool deltimer(Timer*);
// Package time APIs. // Package time APIs.
// Godoc uses the comments in package time, not these. // Godoc uses the comments in package time, not these.
...@@ -31,15 +30,13 @@ func Sleep(ns int64) { ...@@ -31,15 +30,13 @@ func Sleep(ns int64) {
func startTimer(t *Timer) { func startTimer(t *Timer) {
if(raceenabled) if(raceenabled)
runtime·racerelease(t); runtime·racerelease(t);
runtime·lock(&timers); runtime·addtimer(t);
addtimer(t);
runtime·unlock(&timers);
} }
// stopTimer removes t from the timer heap if it is there. // stopTimer removes t from the timer heap if it is there.
// It returns true if t was removed, false if t wasn't even there. // It returns true if t was removed, false if t wasn't even there.
func stopTimer(t *Timer) (stopped bool) { func stopTimer(t *Timer) (stopped bool) {
stopped = deltimer(t); stopped = runtime·deltimer(t);
} }
// C runtime. // C runtime.
...@@ -79,6 +76,14 @@ runtime·tsleep(int64 ns, int8 *reason) ...@@ -79,6 +76,14 @@ runtime·tsleep(int64 ns, int8 *reason)
static FuncVal timerprocv = {timerproc}; static FuncVal timerprocv = {timerproc};
void
runtime·addtimer(Timer *t)
{
runtime·lock(&timers);
addtimer(t);
runtime·unlock(&timers);
}
// Add a timer to the heap and start or kick the timer proc // Add a timer to the heap and start or kick the timer proc
// if the new timer is earlier than any of the others. // if the new timer is earlier than any of the others.
static void static void
...@@ -121,8 +126,8 @@ addtimer(Timer *t) ...@@ -121,8 +126,8 @@ addtimer(Timer *t)
// Delete timer t from the heap. // Delete timer t from the heap.
// Do not need to update the timerproc: // Do not need to update the timerproc:
// if it wakes up early, no big deal. // if it wakes up early, no big deal.
static bool bool
deltimer(Timer *t) runtime·deltimer(Timer *t)
{ {
int32 i; int32 i;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment