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

Fix mutex change of ownership (OpenBSD) #264

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Do not use vendored libraries when building the lsp package (#260)

- Fix: correctly use mutexes on OpenBSD (#264)

# 1.1.0 (10/14/2020)

## Features
Expand Down
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ We recommend to install the server via a project such as
To install the lsp server in a particular opam switch:

```
$ opam pin add ocaml-lsp-server https://github.com/ocaml/ocaml-lsp.git
$ opam install ocaml-lsp-server
```

Expand All @@ -24,13 +23,10 @@ you'd like to use it.

### Esy

To add the lsp server to an esy project, add the following lines to your
project's `package.json`:
To add the lsp server to an esy project:

```
"devDependencies": {
"@opam/ocaml-lsp-server": "ocaml/ocaml-lsp:ocaml-lsp-server.opam"
}
$ esy add @opam/ocaml-lsp-server
```

### Source
Expand All @@ -47,10 +43,12 @@ $ make build

## Usage

Once `ocaml-lsp-server` is installed, the executable is called `ocamllsp`.
For now, the server can only be used through the standard file descriptors `stdin` and `stdout`.
Once `ocaml-lsp-server` is installed, the executable is called `ocamllsp`. For
now, the server can only be used through the standard file descriptors `stdin`
and `stdout`.

For an example of usage of the server in a VSCode extension, see [here](https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/src/Extension.ml).
For an example of usage of the server in a VSCode extension, see
[here](https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/src/vscode_ocaml_platform.ml).

## Features

Expand Down Expand Up @@ -90,7 +88,7 @@ git clone --recursive [email protected]:ocaml/ocaml-lsp.git
git submodule update --init --recursive

# create local switch (or use global one) and install dependencies
opam switch create . ocaml-base-compiler.4.09.1 --with-test
opam switch create . ocaml-base-compiler.4.11.1 --with-test

# don't forget to set your environment to use the local switch
eval ($opam env)
Expand All @@ -110,10 +108,8 @@ To run tests execute:
$ make test
```

Note that tests require [Node.js][] and [Yarn][] installed.

[node.js]: https://nodejs.org/en/
[yarn]: https://yarnpkg.com/lang/en/
Note that tests require [Node.js](https://nodejs.org/en/) and
[Yarn][https://yarnpkg.com/lang/en/] installed.

## Relationship to Other Tools

Expand All @@ -124,8 +120,8 @@ and merlin independently.

## History

The implementation of the lsp protocol itself was taken from [facebook's
hack](https://github.com/facebook/hhvm/blob/master/hphp/hack/src/utils/lsp/lsp.mli)
The implementation of the lsp protocol itself was taken from
[facebook's hack](https://github.com/facebook/hhvm/blob/master/hphp/hack/src/utils/lsp/lsp.mli)

Previously, this lsp server was a part of merlin, until it was realized that the
lsp protocol covers a wider scope than merlin.
Expand Down
3 changes: 1 addition & 2 deletions lsp.opam
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ depends: [
]
dev-repo: "git+https://github.com/ocaml/ocaml-lsp.git"
build: [
["dune" "subst"] {pinned}
["ocaml" "unix.cma" "unvendor.ml"]
# broken by unvendor
# ["dune" "subst"] {pinned}
[
"dune"
"build"
Expand Down
3 changes: 1 addition & 2 deletions lsp.opam.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
build: [
["dune" "subst"] {pinned}
["ocaml" "unix.cma" "unvendor.ml"]
# broken by unvendor
# ["dune" "subst"] {pinned}
[
"dune"
"build"
Expand Down
16 changes: 8 additions & 8 deletions lsp/src/scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ end = struct
| Finished -> assert false
| Running _ -> loop ()
in
loop ()
with_mutex t.mutex ~f:loop

let create ~do_ =
let t =
Expand All @@ -103,10 +103,8 @@ end = struct
; work_available = Condition.create ()
}
in
Mutex.lock t.mutex;
t.state <- Running (Thread.create run (do_, t));
Mutex.lock t.mutex;
Mutex.unlock t.mutex;
with_mutex t.mutex ~f:(fun () ->
t.state <- Running (Thread.create run (do_, t)));
t

let add_work (type a) (t : a t) (w : a) =
Expand Down Expand Up @@ -226,7 +224,8 @@ let time_loop t =
add_events t !to_run;
loop ()
in
loop ()
Condition.signal t.timers_available;
with_mutex t.time_mutex ~f:loop

let wake_loop t =
let rec loop () =
Expand Down Expand Up @@ -254,8 +253,9 @@ let create () =
; detached = Queue.create ()
}
in
Mutex.lock t.time_mutex;
t.time <- Thread.create time_loop t;
with_mutex t.time_mutex ~f:(fun () ->
t.time <- Thread.create time_loop t;
Condition.wait t.timers_available t.time_mutex);
t.waker <- Thread.create wake_loop t;
t

Expand Down
2 changes: 1 addition & 1 deletion lsp/test/fiber_thread_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let worker = Scheduler.create_thread s
let fb () =
Scheduler.async worker (fun () ->
Thread.delay 1.0;
print_endline "pre epmtive thread finished")
print_endline "preemptive thread finished")
|> Scheduler.await_no_cancel

let _ =
Expand Down