ocaml: Use generational global roots.

These are considerably more efficient than ordinary global roots, but
with the caveat that the program is not allowed to modify them without
calling a special function.  We don't modify them, so this change is
safe.

This requires OCaml >= 3.11, but we have that on RHEL 6
(since we dropped support for RHEL 5).

See also:
http://caml.inria.fr/pub/ml-archives/caml-list/2008/03/c3bf86990088236ceeb9a0f0f4c35390.en.html
This commit is contained in:
Richard W.M. Jones
2015-10-06 15:00:00 +01:00
parent 0944acf90c
commit 3858db9d58
2 changed files with 6 additions and 12 deletions

2
README
View File

@@ -84,7 +84,7 @@ The full requirements are described below.
+--------------+-------------+---+-----------------------------------------+
| Pod::Simple | | R | Part of Perl core. |
+--------------+-------------+---+-----------------------------------------+
| OCaml | |R/O| Required if compiling from git. |
| OCaml | 3.11 |R/O| Required if compiling from git. |
| | | | Optional if compiling from tarball. |
| | | | To build generated files and OCaml bindings.
+--------------+-------------+---+-----------------------------------------+

View File

@@ -88,12 +88,12 @@ guestfs_finalize (value gv)
/* Now unregister the global roots. */
for (i = 0; i < len; ++i) {
caml_remove_global_root (roots[i]);
caml_remove_generational_global_root (roots[i]);
free (roots[i]);
}
free (roots);
caml_remove_global_root (v);
caml_remove_generational_global_root (v);
free (v);
}
}
@@ -179,10 +179,7 @@ ocaml_guestfs_create (value environmentv, value close_on_exitv, value unitv)
*/
v = guestfs_int_safe_malloc (g, sizeof *v);
*v = gv;
/* XXX This global root is generational, but we cannot rely on every
* user having the OCaml 3.11 version which supports this.
*/
caml_register_global_root (v);
caml_register_generational_global_root (v);
guestfs_set_private (g, "_ocaml_g", v);
CAMLreturn (gv);
@@ -255,10 +252,7 @@ ocaml_guestfs_set_event_callback (value gv, value closure, value events)
ocaml_guestfs_raise_error (g, "set_event_callback");
}
/* XXX This global root is generational, but we cannot rely on every
* user having the OCaml 3.11 version which supports this.
*/
caml_register_global_root (root);
caml_register_generational_global_root (root);
snprintf (key, sizeof key, "_ocaml_event_%d", eh);
guestfs_set_private (g, key, root);
@@ -280,7 +274,7 @@ ocaml_guestfs_delete_event_callback (value gv, value ehv)
value *root = guestfs_get_private (g, key);
if (root) {
caml_remove_global_root (root);
caml_remove_generational_global_root (root);
free (root);
guestfs_set_private (g, key, NULL);
guestfs_delete_event_callback (g, eh);