Skip to content

Commit 8ca8328

Browse files
authored
c_stubs: use 'new' acquire and release runtime functions (#6341)
These functions have a more relevant name than the previous ones, especially with the advent of OCaml 5.0 the runtime lock becomes more important and programmers must be aware of it. These functions were introduced in OCaml 3.12.
2 parents f5cd21d + f2e6490 commit 8ca8328

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed

ocaml/auth/xa_auth_stubs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <caml/custom.h>
2626
#include <caml/fail.h>
2727
#include <caml/callback.h>
28-
#include <caml/signals.h>
28+
#include <caml/threads.h>
2929

3030
#include "xa_auth.h"
3131

@@ -39,11 +39,11 @@ CAMLprim value stub_XA_mh_authorize(value username, value password){
3939
const char *error = NULL;
4040
int rc;
4141

42-
caml_enter_blocking_section();
42+
caml_release_runtime_system();
4343
rc = XA_mh_authorize(c_username, c_password, &error);
4444
free(c_username);
4545
free(c_password);
46-
caml_leave_blocking_section();
46+
caml_acquire_runtime_system();
4747

4848
if (rc != XA_SUCCESS)
4949
caml_failwith(error ? error : "Unknown error");
@@ -60,11 +60,11 @@ CAMLprim value stub_XA_mh_chpasswd(value username, value new_password){
6060
const char *error = NULL;
6161
int rc;
6262

63-
caml_enter_blocking_section();
63+
caml_release_runtime_system();
6464
rc = XA_mh_chpasswd (c_username, c_new_password, &error);
6565
free(c_username);
6666
free(c_new_password);
67-
caml_leave_blocking_section();
67+
caml_acquire_runtime_system();
6868

6969
if (rc != XA_SUCCESS)
7070
caml_failwith(error ? error : "Unknown error");
@@ -102,10 +102,10 @@ CAMLprim value stub_XA_crypt_r(value key, value setting) {
102102

103103
struct crypt_data cd = {0};
104104

105-
caml_enter_blocking_section();
105+
caml_release_runtime_system();
106106
const char* const hashed =
107107
crypt_r(String_val(key), String_val(setting), &cd);
108-
caml_leave_blocking_section();
108+
caml_acquire_runtime_system();
109109

110110
if (!hashed || *hashed == '*')
111111
CAMLreturn(Val_none);

ocaml/libs/log/syslog_stubs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <caml/memory.h>
1919
#include <caml/alloc.h>
2020
#include <caml/custom.h>
21-
#include <caml/signals.h>
21+
#include <caml/threads.h>
2222

2323
static int syslog_level_table[] = {
2424
LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING,
@@ -57,10 +57,10 @@ value stub_syslog(value facility, value level, value msg)
5757
int c_facility = syslog_facility_table[Int_val(facility)]
5858
| syslog_level_table[Int_val(level)];
5959

60-
caml_enter_blocking_section();
60+
caml_release_runtime_system();
6161
syslog(c_facility, "%s", c_msg);
6262
free(c_msg);
63-
caml_leave_blocking_section();
63+
caml_acquire_runtime_system();
6464

6565
CAMLreturn(Val_unit);
6666
}

ocaml/libs/vhd/vhd_format_lwt/blkgetsize64_stubs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include <caml/alloc.h>
2727
#include <caml/memory.h>
28-
#include <caml/signals.h>
28+
#include <caml/threads.h>
2929
#include <caml/fail.h>
3030
#include <caml/callback.h>
3131
#include <caml/bigarray.h>
@@ -54,7 +54,7 @@ CAMLprim value stub_blkgetsize64(value filename){
5454
int rc = NOT_IMPLEMENTED;
5555
const char *filename_c = strdup(String_val(filename));
5656

57-
caml_enter_blocking_section();
57+
caml_release_runtime_system();
5858
fd = open(filename_c, O_RDONLY, 0);
5959
if (fd >= 0) {
6060
#if defined(BLKGETSIZE64)
@@ -71,7 +71,7 @@ CAMLprim value stub_blkgetsize64(value filename){
7171
close(fd);
7272
} else
7373
size_in_bytes = -1;
74-
caml_leave_blocking_section();
74+
caml_acquire_runtime_system();
7575
free((void*)filename_c);
7676

7777
if (fd == -1) uerror("open", filename);

ocaml/libs/vhd/vhd_format_lwt/lseek64_stubs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <caml/alloc.h>
2828
#include <caml/memory.h>
29-
#include <caml/signals.h>
29+
#include <caml/threads.h>
3030
#include <caml/fail.h>
3131
#include <caml/callback.h>
3232
#include <caml/bigarray.h>
@@ -43,7 +43,7 @@ CAMLprim value stub_lseek64_data(value fd, value ofs) {
4343
off_t c_ofs = Int64_val(ofs);
4444
off_t c_ret;
4545

46-
caml_enter_blocking_section();
46+
caml_release_runtime_system();
4747
#if defined(SEEK_DATA)
4848
c_ret = lseek(c_fd, c_ofs, SEEK_DATA);
4949
/* retry, if SEEK_DATA not supported on this file system */
@@ -53,7 +53,7 @@ CAMLprim value stub_lseek64_data(value fd, value ofs) {
5353
/* Set the file pointer to ofs; pretend there is data */
5454
c_ret = lseek(c_fd, c_ofs, SEEK_SET);
5555
#endif
56-
caml_leave_blocking_section();
56+
caml_acquire_runtime_system();
5757
if (c_ret == -1) uerror("lseek", Nothing);
5858

5959
result = caml_copy_int64(c_ret);
@@ -67,7 +67,7 @@ CAMLprim value stub_lseek64_hole(value fd, value ofs) {
6767
off_t c_ofs = Int64_val(ofs);
6868
off_t c_ret;
6969

70-
caml_enter_blocking_section();
70+
caml_release_runtime_system();
7171
#if defined(SEEK_HOLE)
7272
c_ret = lseek(c_fd, c_ofs, SEEK_HOLE);
7373
/* retry, if SEEK_HOLE not supported on this file system */
@@ -78,7 +78,7 @@ CAMLprim value stub_lseek64_hole(value fd, value ofs) {
7878
there is no hole */
7979
c_ret = lseek(c_fd, 0, SEEK_END);
8080
#endif
81-
caml_leave_blocking_section();
81+
caml_acquire_runtime_system();
8282
if (c_ret == -1) uerror("lseek", Nothing);
8383
result = caml_copy_int64(c_ret);
8484
CAMLreturn(result);

ocaml/libs/vhd/vhd_format_lwt/odirect_stubs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <caml/alloc.h>
2525
#include <caml/memory.h>
26-
#include <caml/signals.h>
26+
#include <caml/threads.h>
2727
#include <caml/fail.h>
2828
#include <caml/callback.h>
2929
#include <caml/bigarray.h>
@@ -36,7 +36,7 @@ CAMLprim value stub_openfile_direct(value filename, value rw, value perm){
3636

3737
const char *filename_c = strdup(String_val(filename));
3838

39-
caml_enter_blocking_section();
39+
caml_release_runtime_system();
4040
int flags = 0;
4141
#if defined(O_DIRECT)
4242
flags |= O_DIRECT;
@@ -47,7 +47,7 @@ CAMLprim value stub_openfile_direct(value filename, value rw, value perm){
4747
flags |= O_RDONLY;
4848
}
4949
fd = open(filename_c, flags, Int_val(perm));
50-
caml_leave_blocking_section();
50+
caml_acquire_runtime_system();
5151

5252
free((void*)filename_c);
5353

ocaml/vhd-tool/src/direct_copy_stubs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include <caml/alloc.h>
3030
#include <caml/memory.h>
31-
#include <caml/signals.h>
31+
#include <caml/threads.h>
3232
#include <caml/fail.h>
3333
#include <caml/callback.h>
3434
#include <caml/bigarray.h>
@@ -134,7 +134,7 @@ CAMLprim value stub_direct_copy(value handle, value len){
134134
* values may be accessed, until it is reacquired. Also this
135135
* means other OCaml threads may do things while this is going
136136
* on so the caller must be careful. */
137-
caml_enter_blocking_section();
137+
caml_release_runtime_system();
138138

139139
rc = TRIED_AND_FAILED;
140140
bytes = 0;
@@ -195,7 +195,7 @@ CAMLprim value stub_direct_copy(value handle, value len){
195195
rc = OK;
196196
fail:
197197

198-
caml_leave_blocking_section();
198+
caml_acquire_runtime_system();
199199
/* Now that the OCaml runtime lock is reacquired, it is safe to
200200
* raise OCaml exceptions */
201201

ocaml/xenopsd/c_stubs/xenctrlext_stubs.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <caml/alloc.h>
2929
#include <caml/custom.h>
3030
#include <caml/fail.h>
31-
#include <caml/signals.h>
31+
#include <caml/threads.h>
3232
#include <caml/callback.h>
3333
#include <caml/unixsupport.h>
3434
#include <caml/bigarray.h>
@@ -95,9 +95,9 @@ CAMLprim value stub_xenctrlext_interface_open(value unused)
9595
CAMLlocal1(result);
9696
xc_interface *xch;
9797

98-
caml_enter_blocking_section();
98+
caml_release_runtime_system();
9999
xch = xc_interface_open(NULL, NULL, 0);
100-
caml_leave_blocking_section();
100+
caml_acquire_runtime_system();
101101

102102
if ( !xch )
103103
failwith_xc(xch);
@@ -226,9 +226,9 @@ CAMLprim value stub_xenctrlext_get_max_nr_cpus(value xch_val)
226226
xc_interface *xch = xch_of_val(xch_val);
227227
int r;
228228

229-
caml_enter_blocking_section();
229+
caml_release_runtime_system();
230230
r = xc_physinfo(xch, &c_physinfo);
231-
caml_leave_blocking_section();
231+
caml_acquire_runtime_system();
232232

233233
if (r)
234234
failwith_xc(xch);
@@ -256,9 +256,9 @@ CAMLprim value stub_xenctrlext_physdev_map_pirq(value xch_val,
256256
CAMLparam3(xch_val, domid, irq);
257257
xc_interface *xch = xch_of_val(xch_val);
258258
int pirq = Int_val(irq);
259-
caml_enter_blocking_section();
259+
caml_release_runtime_system();
260260
int retval = xc_physdev_map_pirq(xch, Int_val(domid), pirq, &pirq);
261-
caml_leave_blocking_section();
261+
caml_acquire_runtime_system();
262262
if (retval)
263263
failwith_xc(xch);
264264
CAMLreturn(Val_int(pirq));
@@ -269,9 +269,9 @@ CAMLprim value stub_xenctrlext_assign_device(value xch_val, value domid,
269269
{
270270
CAMLparam4(xch_val, domid, machine_sbdf, flag);
271271
xc_interface *xch = xch_of_val(xch_val);
272-
caml_enter_blocking_section();
272+
caml_release_runtime_system();
273273
int retval = xc_assign_device(xch, Int_val(domid), Int_val(machine_sbdf), Int_val(flag));
274-
caml_leave_blocking_section();
274+
caml_acquire_runtime_system();
275275
if (retval)
276276
failwith_xc(xch);
277277
CAMLreturn(Val_unit);
@@ -281,9 +281,9 @@ CAMLprim value stub_xenctrlext_deassign_device(value xch_val, value domid, value
281281
{
282282
CAMLparam3(xch_val, domid, machine_sbdf);
283283
xc_interface *xc = xch_of_val(xch_val);
284-
caml_enter_blocking_section();
284+
caml_release_runtime_system();
285285
int retval = xc_deassign_device(xc, Int_val(domid), Int_val(machine_sbdf));
286-
caml_leave_blocking_section();
286+
caml_acquire_runtime_system();
287287
if (retval)
288288
failwith_xc(xc);
289289
CAMLreturn(Val_unit);
@@ -299,9 +299,9 @@ CAMLprim value stub_xenctrlext_domain_soft_reset(value xch_val, value domid)
299299
{
300300
CAMLparam2(xch_val, domid);
301301
xc_interface *xc = xch_of_val(xch_val);
302-
caml_enter_blocking_section();
302+
caml_release_runtime_system();
303303
int retval = xc_domain_soft_reset(xc, Int_val(domid));
304-
caml_leave_blocking_section();
304+
caml_acquire_runtime_system();
305305
if (retval)
306306
failwith_xc(xc);
307307
CAMLreturn(Val_unit);
@@ -312,11 +312,11 @@ CAMLprim value stub_xenctrlext_domain_update_channels(value xch_val, value domid
312312
{
313313
CAMLparam4(xch_val, domid, store_port, console_port);
314314
xc_interface *xc = xch_of_val(xch_val);
315-
caml_enter_blocking_section();
315+
caml_release_runtime_system();
316316
int retval = xc_set_hvm_param(xc, Int_val(domid), HVM_PARAM_STORE_EVTCHN, Int_val(store_port));
317317
if (!retval)
318318
retval = xc_set_hvm_param(xc, Int_val(domid), HVM_PARAM_CONSOLE_EVTCHN, Int_val(console_port));
319-
caml_leave_blocking_section();
319+
caml_acquire_runtime_system();
320320
if (retval)
321321
failwith_xc(xc);
322322
CAMLreturn(Val_unit);

0 commit comments

Comments
 (0)