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

Leave blocking section on callback while polling #142

Merged
merged 1 commit into from
Dec 3, 2021
Merged
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
4 changes: 4 additions & 0 deletions src/ml_glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,15 @@ ML_1 (g_source_remove, Int_val, Unit)

static GPollFunc poll_func = NULL;

int polling = 0;

static gint ml_poll (GPollFD *ufds, guint nfsd, gint timeout)
{
gint res;
caml_enter_blocking_section();
polling = 1;
res = poll_func(ufds, nfsd, timeout);
polling = 0;
caml_leave_blocking_section();
return res;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ml_glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ CAMLexport GSList *GSList_val (value list, value_out);

CAMLexport void ml_register_exn_map (GQuark domain, char *caml_name);
CAMLexport void ml_raise_gerror(GError *) Noreturn;

extern int polling;
17 changes: 16 additions & 1 deletion src/ml_gobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <caml/memory.h>
#include <caml/callback.h>
#include <caml/fail.h>
#include <caml/threads.h>

#include "wrappers.h"
#include "ml_glib.h"
Expand Down Expand Up @@ -178,7 +179,7 @@ static void notify_destroy(gpointer unit, GClosure *c)
remove_global_root((value*)&c->data);
}

static void marshal (GClosure *closure, GValue *ret,
static void marshal_core (GClosure *closure, GValue *ret,
guint nargs, const GValue *args,
gpointer hint, gpointer marshall_data)
{
Expand All @@ -194,6 +195,20 @@ static void marshal (GClosure *closure, GValue *ret,
CAMLreturn0;
}

static void marshal (GClosure *closure, GValue *ret,
guint nargs, const GValue *args,
gpointer hint, gpointer marshall_data)
{
if (polling) { // https://github.com/garrigue/lablgtk/issues/141
caml_leave_blocking_section();
polling = 0;
marshal_core(closure, ret, nargs, args, hint, marshall_data);
polling = 1;
caml_enter_blocking_section();
} else
marshal_core(closure, ret, nargs, args, hint, marshall_data);
}

CAMLprim value ml_g_closure_new (value clos)
{
GClosure* closure = g_closure_new_simple(sizeof(GClosure), (gpointer)clos);
Expand Down