Skip to content

Commit

Permalink
all: use golang.design/x/mainthread
Browse files Browse the repository at this point in the history
  • Loading branch information
changkun committed Feb 20, 2021
1 parent 833ce97 commit 3e50a24
Show file tree
Hide file tree
Showing 201 changed files with 20,759 additions and 100,279 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/spf13/cobra v1.1.1
golang.design/x/clipboard v0.4.2
golang.org/x/sys v0.0.0-20200116001909-b77594299b42
golang.design/x/mainthread v0.2.0
golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.design/x/clipboard v0.4.2 h1:IqRHnFb48m1mQlF7pj8hP/4ecRBl84VONG+s0w4kE6Q=
golang.design/x/clipboard v0.4.2/go.mod h1:QetBbCbWomvi8bX+buWaqILoiT4osRNU6T1Bsn4qbEY=
golang.design/x/mainthread v0.2.0 h1:/U8kAEB2uNzpJbCIiGJrZTcdYZI2Fvb0m8DWn/ycZNM=
golang.design/x/mainthread v0.2.0/go.mod h1:vYX7cF2b3pTJMGM/hc13NmN6kblKnf4/IyvHeu259L0=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -302,8 +304,9 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd h1:WgqgiQvkiZWz7XLhphjt2GI2GcGCTIZs9jqXMWmH+oc=
golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down
2 changes: 1 addition & 1 deletion internal/hotkey/hotkey_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sync"
"unsafe"

"changkun.de/x/midgard/internal/mainthread"
"golang.design/x/mainthread"
)

// This hkCallback tries to avoid a runtime panic error when directly
Expand Down
2 changes: 1 addition & 1 deletion internal/hotkey/hotkey_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int register_hotkey(void* go_hotkey_handler) {

// The following three lines of code must run on the main thread.
// Don't ask why. This is really bad. Go must handle this using the
// pkg/mainthread.
// golang.design/x/mainthread.
//
// inspired from here: https://github.com/cehoffman/dotfiles/blob/4be8e893517e970d40746a9bdc67fe5832dd1c33/os/mac/iTerm2HotKey.m
void run_shared_application() {
Expand Down
37 changes: 0 additions & 37 deletions internal/mainthread/bench_test.go

This file was deleted.

49 changes: 0 additions & 49 deletions internal/mainthread/mainthread.go

This file was deleted.

66 changes: 0 additions & 66 deletions internal/mainthread/mainthread_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion midgard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

import (
"changkun.de/x/midgard/cmd"
"changkun.de/x/midgard/internal/mainthread"
"golang.design/x/mainthread"
)

func main() {
Expand Down
15 changes: 15 additions & 0 deletions vendor/golang.design/x/mainthread/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
21 changes: 21 additions & 0 deletions vendor/golang.design/x/mainthread/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Changkun Ou <contact@changkun.de>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 62 additions & 0 deletions vendor/golang.design/x/mainthread/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# mainthread [![PkgGoDev](https://pkg.go.dev/badge/golang.design/x/mainthread)](https://pkg.go.dev/golang.design/x/mainthread) ![mainthread](https://github.com/golang-design/mainthread/workflows/mainthread/badge.svg?branch=main) ![](https://changkun.de/urlstat?mode=github&repo=golang-design/mainthread)

schedules function to run on the main thread

```go
import "golang.design/x/mainthread"
```

## Features

- Main thread scheduling
- Schedule functions without memory allocation

## API Usage

Package mainthread offers facilities to schedule functions on the
maint hread. To use this package properly, one must call
mainthread.Init from the main package. For example:

```go
package main

import "golang.design/x/mainthread"

func main() { mainthread.Init(fn) }

// fn is the actual main function
func fn() {
// mainthread.Call returns when f1 returns. Note that if f1 blocks
// it will also block the execution of any subsequent calls on the
// main thread.
mainthread.Call(f1)

// ... do whatever you want to do ...

// mainthread.Go returns immediately and f2 is scheduled to be executed
// in the future.
mainthread.Go(f2)

// ... do whatever you want to do ...
}

func f1() { ... }
func f2() { ... }
```

## When do you need this package?

Read this to learn more about the design purpose of this package:
https://golang.design/research/zero-alloc-call-sched/

## Who is using this package?

The initial purpose of building this package is to support writing
graphical applications in Go. To know projects that are using this
package, check our [wiki](https://github.com/golang-design/mainthread/wiki)
page.


## License

MIT | &copy; 2021 The golang.design Initiative Authors, written by [Changkun Ou](https://changkun.de).
5 changes: 5 additions & 0 deletions vendor/golang.design/x/mainthread/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module golang.design/x/mainthread

go 1.16

require golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd
2 changes: 2 additions & 0 deletions vendor/golang.design/x/mainthread/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd h1:WgqgiQvkiZWz7XLhphjt2GI2GcGCTIZs9jqXMWmH+oc=
golang.org/x/sys v0.0.0-20201022201747-fb209a7c41cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Loading

0 comments on commit 3e50a24

Please sign in to comment.