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

Indented most of the source code #409

Merged
merged 12 commits into from
Jun 15, 2017
52 changes: 26 additions & 26 deletions src/preemptive/lwt_preemptive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ struct
let get t =
let rec await_value t =
match t.cell with
| None ->
Condition.wait t.cv t.m;
await_value t
| Some v ->
t.cell <- None;
Mutex.unlock t.m;
v
| None ->
Condition.wait t.cv t.m;
await_value t
| Some v ->
t.cell <- None;
Mutex.unlock t.m;
v
in
Mutex.lock t.m;
await_value t
Mutex.lock t.m;
await_value t

let set t v =
Mutex.lock t.m;
Expand Down Expand Up @@ -136,10 +136,10 @@ let make_worker () =
(* Add a worker to the pool: *)
let add_worker worker =
match Lwt_sequence.take_opt_l waiters with
| None ->
Queue.add worker workers
| Some w ->
Lwt.wakeup w worker
| None ->
Queue.add worker workers
| Some w ->
Lwt.wakeup w worker

(* Wait for worker to be available, then return it: *)
let get_worker () =
Expand Down Expand Up @@ -207,20 +207,20 @@ let detach f args =
in
Lwt.finalize
(fun () ->
(* Send the id and the task to the worker: *)
(* Send the id and the task to the worker: *)
CELL.set worker.task_cell (id, task);
waiter)
(fun () ->
if worker.reuse then
(* Put back the worker to the pool: *)
add_worker worker
else begin
decr threads_count;
(* Or wait for the thread to terminates, to free its associated
resources: *)
Thread.join worker.thread
end;
Lwt.return_unit)
if worker.reuse then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO ocp-indent gets this kind of thing wrong. It shouldn't cause an extra space if you have to add a ( to a function (or any other expression). Is it easy to fix in the ocp-indent settings? If not, it's fine – no need to go through all these files. The PR does much more good than harm, even with this nit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess it does this to align everything two spaces after the fun keyword, which is one column after the beginning of the line. I agree it looks kinda wrong. I'll see what I can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Available configuration doesn't seem to provide an option for this behavior.

Is it worth opening an issue on their side?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, they might be able to answer it, fix it, or teach me/us why the ocp-indent way is the right way :) Also cc @vasilisp for any experience with this.

I don't think this blocks the PR though, unless you want to wait for it.

(* Put back the worker to the pool: *)
add_worker worker
else begin
decr threads_count;
(* Or wait for the thread to terminates, to free its associated
resources: *)
Thread.join worker.thread
end;
Lwt.return_unit)

(* +-----------------------------------------------------------------+
| Running Lwt threads in the main thread |
Expand Down Expand Up @@ -267,5 +267,5 @@ let run_in_main f =
Lwt_unix.send_notification job_notification;
(* Wait for the result. *)
match CELL.get cell with
| Result.Ok ret -> ret
| Result.Error exn -> raise exn
| Result.Ok ret -> ret
| Result.Error exn -> raise exn