The Wayback Machine - https://web.archive.org/web/20201223151810/https://github.com/tinygo-org/tinygo/pull/1172
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: add cheap atomic condition variable #1172

Merged
merged 1 commit into from Oct 14, 2020
Merged

Conversation

@niaow
Copy link
Member

@niaow niaow commented Jun 15, 2020

Earlier on slack @aykevl suggested that something like this would be needed.

Usage example with systick:

package main

import (
	"device/arm"
	"machine"
	"runtime"
)

var cond runtime.Cond

func main() {
	machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})

	// timer fires 10 times per second
	arm.SetupSystemTimer(machine.CPUFrequency() / 10)

	for {
		machine.LED.Low()
		cond.Wait()
		machine.LED.High()
		cond.Wait()
	}
}

//export SysTick_Handler
func timer_isr() {
	cond.Notify()
}

Current issues making this WIP/not ready:

  1. #1142 needs to be merged
  2. Where should this go? It was originally in runtime/interrupt, but that caused an import cycle.
  3. The no-scheduler implementation is still suboptimal (it should wait instead of using a polling loop).
@niaow niaow added this to the v0.15 milestone Jun 27, 2020
@niaow niaow force-pushed the niaow:icond branch from f48ccce to 7c9452e Jul 12, 2020
@niaow
Copy link
Member Author

@niaow niaow commented Jul 12, 2020

The no-scheduler implementation is still suboptimal (it should wait instead of using a polling loop).

This part has now been resolved.

@niaow
Copy link
Member Author

@niaow niaow commented Jul 12, 2020

Where should this go?

@aykevl any opinion?

@deadprogram
Copy link
Member

@deadprogram deadprogram commented Sep 12, 2020

Reminder to @aykevl and @niaow about this PR. 😺

@niaow niaow force-pushed the niaow:icond branch from 7c9452e to e0297b5 Sep 12, 2020
@niaow niaow marked this pull request as ready for review Sep 12, 2020
@niaow
Copy link
Member Author

@niaow niaow commented Sep 12, 2020

This should work decently now. However, my computer isn't recognizing my ARM boards right now so I have not been able to test on hardware.

@deadprogram
Copy link
Member

@deadprogram deadprogram commented Sep 12, 2020

Tested with the provided example on ATSAMD21 board (Circuit Playground Express) and then also on nrf52840 (Circuit Playground Bluefruit) and both worked exactly as expected.

@aykevl any feedback before this gets merged?

@deadprogram
Copy link
Member

@deadprogram deadprogram commented Oct 14, 2020

We really need this for something specific. Code looks good, and works as promised, so now merging. Thanks @niaow for this feature!

@deadprogram deadprogram merged commit ed9b97c into tinygo-org:dev Oct 14, 2020
9 checks passed
9 checks passed
ci/circleci: assert-test-linux Your tests passed on CircleCI!
Details
ci/circleci: build-linux Your tests passed on CircleCI!
Details
ci/circleci: build-macos Your tests passed on CircleCI!
Details
ci/circleci: test-llvm10-go112 Your tests passed on CircleCI!
Details
ci/circleci: test-llvm10-go113 Your tests passed on CircleCI!
Details
ci/circleci: test-llvm10-go114 Your tests passed on CircleCI!
Details
ci/circleci: test-llvm10-go115 Your tests passed on CircleCI!
Details
ci/circleci: test-llvm9-go111 Your tests passed on CircleCI!
Details
tinygo-CI #20200912.3 succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.