Skip to content

Commit

Permalink
Remove lua.Lock
Browse files Browse the repository at this point in the history
Exposing locking primitives to lua plugins is tricky and may lead to
deadlocks. Instead, if possible, it's better to ensure all the needed
synchonization in micro itself, without leaving this burden to lua code.

Since we've added micro.After() timer API and removed exposing Go timers
directly to lua, now we (probably?) have no cases of lua code possibly
running asynchronously without micro controlling when it is running. So
now we can remove lua.Lock.

This means breaking compatibility, but, until recently lua.Lock wasn't
workable at all (see zyedidia#2945), which suggests that it has never been
really used by anyone. So it should be safe to remove it.
  • Loading branch information
dmaluka committed Mar 14, 2024
1 parent 4ffc220 commit 1d1b363
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 10 deletions.
1 change: 0 additions & 1 deletion cmd/micro/initlua.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func luaImportMicro() *lua.LTable {
ulua.L.SetField(pkg, "Tabs", luar.New(ulua.L, func() *action.TabList {
return action.Tabs
}))
ulua.L.SetField(pkg, "Lock", luar.New(ulua.L, &ulua.Lock))
ulua.L.SetField(pkg, "After", luar.New(ulua.L, func(t time.Duration, f func()) {
time.AfterFunc(t, func() {
timerChan <- f
Expand Down
7 changes: 0 additions & 7 deletions cmd/micro/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/clipboard"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
"github.com/zyedidia/micro/v2/internal/shell"
"github.com/zyedidia/micro/v2/internal/util"
Expand Down Expand Up @@ -418,15 +417,11 @@ func DoEvent() {
select {
case f := <-shell.Jobs:
// If a new job has finished while running in the background we should execute the callback
ulua.Lock.Lock()
f.Function(f.Output, f.Args)
ulua.Lock.Unlock()
case <-config.Autosave:
ulua.Lock.Lock()
for _, b := range buffer.OpenBuffers {
b.Save()
}
ulua.Lock.Unlock()
case <-shell.CloseTerms:
case event = <-screen.Events:
case <-screen.DrawChan():
Expand Down Expand Up @@ -478,12 +473,10 @@ func DoEvent() {
return
}

ulua.Lock.Lock()
_, resize := event.(*tcell.EventResize)
if action.InfoBar.HasPrompt && !resize {
action.InfoBar.HandleEvent(event)
} else {
action.Tabs.HandleEvent(event)
}
ulua.Lock.Unlock()
}
2 changes: 0 additions & 2 deletions internal/lua/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"regexp"
"runtime"
"strings"
"sync"
"time"
"unicode/utf8"

Expand All @@ -27,7 +26,6 @@ import (
)

var L *lua.LState
var Lock sync.Mutex

// LoadFile loads a lua file
func LoadFile(module string, file string, data []byte) error {
Expand Down

0 comments on commit 1d1b363

Please sign in to comment.