1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
//! Raw C ABI types and constants mirroring `erl_nif.h` and `erl_drv_nif.h`.
//!
//! Direct `#[repr(C)]` transcriptions — no logic, no safety wrappers. Prefixes
//! are dropped per the crate naming convention; names that would shadow a Rust
//! keyword or a `std` prelude item take a trailing underscore (`Option_`).
//!
//! Each item ends with a `[`ErlNif…`](…) — NIF x.y — OTP z` line naming the C
//! entity and the release that introduced it; struct fields and enum variants
//! added in a later release carry their own inline note. The crate floor is
//! NIF 2.15 (OTP 22); anything newer is gated behind its rung.
use ;
use ;
use BitOr;
// `SysIOVec` is platform-divergent; its definition lives in the active platform
// module. Re-export it here so it sits with the rest of the type mirror and
// reaches the crate root through `lib.rs`'s `pub use types::*`.
pub use crateSysIOVec;
pub use crateSysIOVec;
// ---------------------------------------------------------------------------
// Library version
// ---------------------------------------------------------------------------
/// The major NIF API version this build targets.
///
/// Always 2; the major number has not changed since the modern NIF API. Written
/// into the library [`Entry`] reported to the BEAM at load.
///
/// [`ERL_NIF_MAJOR_VERSION`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_MAJOR_VERSION) — NIF 0.1 — OTP R13B03
pub const MAJOR_VERSION: c_int = 2;
/// The highest NIF minor version this build targets.
///
/// Set from the enabled feature rung (15, 16, 17, or 18) and written into the
/// library [`Entry`]. The BEAM refuses to load the library if its own NIF
/// version is lower than this.
///
/// [`ERL_NIF_MINOR_VERSION`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_MINOR_VERSION) — NIF 0.1 — OTP R13B03
pub const MINOR_VERSION: c_int = 15;
pub const MINOR_VERSION: c_int = 16;
pub const MINOR_VERSION: c_int = 17;
pub const MINOR_VERSION: c_int = 18;
/// The minimum ERTS version the library requires.
///
/// An `erts-X.Y` string tracking the enabled feature rung, written into the
/// [`Entry`]. The BEAM refuses to load the library on an older runtime.
///
/// [`ERL_NIF_MIN_ERTS_VERSION`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_MIN_ERTS_VERSION) — NIF 2.14 — OTP 21
pub const MIN_ERTS_VERSION: &CStr = c"erts-10.4";
pub const MIN_ERTS_VERSION: &CStr = c"erts-12.0";
pub const MIN_ERTS_VERSION: &CStr = c"erts-14.0";
/// The VM variant the library is built for.
///
/// Always `"beam.vanilla"`. Written into the [`Entry`]; the BEAM checks it
/// against the running emulator at load.
///
/// [`ERL_NIF_VM_VARIANT`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_VM_VARIANT) — NIF 2.1 — OTP R14B02
pub const VM_VARIANT: &CStr = c"beam.vanilla";
// ---------------------------------------------------------------------------
// Core term type
// ---------------------------------------------------------------------------
/// Any Erlang term, as an opaque tagged word.
///
/// A pointer-sized tagged machine word whose bit layout is private to the
/// runtime. A NIF must only ever inspect or build terms through the `enif_*`
/// functions, never by interpreting the integer directly.
///
/// [`ERL_NIF_TERM`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_TERM) — NIF 0.1 — OTP R13B03
pub type Term = usize;
// ---------------------------------------------------------------------------
// Opaque environment
// ---------------------------------------------------------------------------
/// A NIF environment that owns terms.
///
/// Always handled as `*mut Env` and never constructed by a NIF. A call
/// environment is passed into each NIF and lives for the duration of the call; a
/// process-independent one from [`alloc_env`](crate::alloc_env) lives until [`free_env`](crate::free_env). Every
/// term is bound to some environment.
///
/// [`ErlNifEnv`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifEnv) — NIF 0.1 — OTP R13B03
// ---------------------------------------------------------------------------
// Function and entry descriptors
// ---------------------------------------------------------------------------
/// The descriptor for a single exported NIF.
///
/// Pairs an Erlang function `name` and `arity` with the C function pointer
/// `fptr`. `flags` is `0` for a regular NIF, or [`DIRTY_JOB_CPU_BOUND`] /
/// [`DIRTY_JOB_IO_BOUND`] (cast to `c_uint`) for a dirty NIF; the `flags` field
/// itself was added in NIF 2.7 (OTP 17.3).
///
/// [`ErlNifFunc`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifFunc) — NIF 0.1 — OTP R13B03
/// The library descriptor the BEAM reads at load.
///
/// Built and returned by `nif_init`, it lists the module's functions and the
/// load/upgrade/unload callbacks, plus version and metadata fields. All tail
/// fields through `min_erts` are always present; an older BEAM simply reads
/// fewer of them.
///
/// [`ErlNifEntry`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifEntry) — NIF 0.1 — OTP R13B03
// ---------------------------------------------------------------------------
// Binary
// ---------------------------------------------------------------------------
/// A binary's bytes, as a size and data pointer.
///
/// `size` and `data` describe the bytes; the `ref_bin`/`_spare` fields are
/// BEAM-internal bookkeeping and must be left untouched. Filled by
/// [`inspect_binary`](crate::inspect_binary) for borrowing, or [`alloc_binary`](crate::alloc_binary) for an owned, mutable
/// binary.
///
/// [`ErlNifBinary`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifBinary) — NIF 0.1 — OTP R13B03
// ---------------------------------------------------------------------------
// Pid and Port
// ---------------------------------------------------------------------------
/// A local process identifier.
///
/// Wraps the pid term in `pid`. Obtained from [`self_`](crate::self_), [`get_local_pid`](crate::get_local_pid), or
/// [`whereis_pid`](crate::whereis_pid), turned back into a term with [`make_pid`](crate::make_pid), and may be flagged
/// undefined with [`set_pid_undefined`](crate::set_pid_undefined).
///
/// [`ErlNifPid`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifPid) — NIF 2.0 — OTP R14A
/// A port identifier.
///
/// Wraps the port term in `port_id`. Obtained from [`get_local_port`](crate::get_local_port) or
/// [`whereis_port`](crate::whereis_port).
///
/// [`ErlNifPort`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifPort) — NIF 2.11 — OTP 19
// ---------------------------------------------------------------------------
// Monitor
// ---------------------------------------------------------------------------
/// A process-monitor handle.
///
/// A 32-byte opaque value — the C type is also `ErlDrvMonitor` — always passed by
/// pointer and never interpreted. Produced by [`monitor_process`](crate::monitor_process), ordered with
/// [`compare_monitors`](crate::compare_monitors), and turned into a term with [`make_monitor_term`](crate::make_monitor_term).
///
/// [`ErlNifMonitor`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifMonitor) — NIF 2.12 — OTP 20
;
// ---------------------------------------------------------------------------
// Resource type
// ---------------------------------------------------------------------------
/// A handle to a registered resource type.
///
/// An opaque value returned by [`open_resource_type`](crate::open_resource_type),
/// [`open_resource_type_x`](crate::open_resource_type_x), or `init_resource_type`
/// and passed to [`alloc_resource`](crate::alloc_resource) and
/// [`get_resource`](crate::get_resource). Always handled as `*mut ResourceType`.
///
/// [`ErlNifResourceType`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifResourceType) — NIF 1.0 — OTP R13B04
/// Callback table for resource type registration.
///
/// `members` must equal the number of callback fields provided, counting from
/// the start: 1 = dtor, 2 = +stop, 3 = +down, 4 = +dyncall; `dyncall` was added
/// in NIF 2.16 (OTP 24). The field is always present — set `members` to bound
/// what the target BEAM understands.
///
/// [`ErlNifResourceTypeInit`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifResourceTypeInit) — NIF 2.12 — OTP 20
/// Create-or-take-over flags for registering a resource type.
///
/// Combine with `|`, e.g. `ResourceFlags::CREATE | ResourceFlags::TAKEOVER`.
/// Passed to [`open_resource_type`](crate::open_resource_type) and friends, which report through their
/// `tried` out-parameter which operation actually occurred.
///
/// [`ErlNifResourceFlags`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifResourceFlags) — NIF 1.0 — OTP R13B04
;
// ---------------------------------------------------------------------------
// OS event handle (for enif_select)
// ---------------------------------------------------------------------------
/// An OS event handle for use with [`select`](crate::select).
///
/// A file descriptor on Unix (`c_int`) or a `HANDLE` on Windows (`*mut c_void`).
/// Registered for readiness notifications through [`select`](crate::select), with a resource
/// owning its lifetime.
///
/// [`ErlNifEvent`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifEvent) — NIF 2.12 — OTP 20
pub type Event = c_int;
pub type Event = *mut c_void;
// ---------------------------------------------------------------------------
// Map iterator
// ---------------------------------------------------------------------------
/// Starting position for a map iterator.
///
/// [`ErlNifMapIteratorEntry`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifMapIteratorEntry) — NIF 2.6 — OTP 17
union MapIteratorUnion
/// A cursor for iterating a map's entries.
///
/// Only `map` is public; the remaining fields are BEAM-internal. Initialized by
/// [`map_iterator_create`](crate::map_iterator_create) and released by [`map_iterator_destroy`](crate::map_iterator_destroy), it must not
/// be moved after initialization. Iteration order is unspecified.
///
/// [`ErlNifMapIterator`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifMapIterator) — NIF 2.6 — OTP 17
// ---------------------------------------------------------------------------
// Term type tag
// ---------------------------------------------------------------------------
/// The canonical term types returned by `term_type`.
///
/// The C header reserves a `-1` sentinel and may add new types, so an
/// unrecognized code must never be transmuted into this enum.
///
/// [`ErlNifTermType`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifTermType) — NIF 2.15 — OTP 22
// ---------------------------------------------------------------------------
// Character encoding
// ---------------------------------------------------------------------------
/// Encoding for reading and writing atom and string bytes.
///
/// Selects how the byte buffer in functions like [`make_atom`](crate::make_atom), [`get_string`](crate::get_string),
/// and [`make_string`](crate::make_string) is interpreted. `Latin1` is one byte per character;
/// `Utf8` (NIF 2.17) is variable-width.
///
/// [`ErlNifCharEncoding`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifCharEncoding) — NIF 1.0 — OTP R13B04
// ---------------------------------------------------------------------------
// Time
// ---------------------------------------------------------------------------
/// A time value in BEAM time units.
///
/// A signed 64-bit count whose unit is given by an accompanying [`TimeUnit`].
/// Monotonic times are frequently negative; see [`monotonic_time`](crate::monotonic_time).
///
/// [`ErlNifTime`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifTime) — NIF 2.10 — OTP 18.3
pub type Time = i64;
/// Sentinel returned by the time functions on error.
///
/// Equal to `i64::MIN`. Returned when a time value cannot be represented in the
/// requested [`TimeUnit`].
///
/// [`ERL_NIF_TIME_ERROR`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_TIME_ERROR) — NIF 2.10 — OTP 18.3
pub const TIME_ERROR: Time = i64MIN;
/// The unit of a [`Time`] value.
///
/// Selects the unit passed to or returned by [`monotonic_time`](crate::monotonic_time), [`time_offset`](crate::time_offset),
/// and [`convert_time_unit`](crate::convert_time_unit).
///
/// [`ErlNifTimeUnit`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifTimeUnit) — NIF 2.10 — OTP 18.3
// ---------------------------------------------------------------------------
// Unique integer flags
// ---------------------------------------------------------------------------
/// Flags shaping the result of [`make_unique_integer`](crate::make_unique_integer). Combine with `|`.
///
/// The same options as `erlang:unique_integer/1`. With no flags the integer is
/// merely unique and may be negative; the flags constrain it to be positive
/// and/or strictly monotonic.
///
/// [`ErlNifUniqueInteger`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifUniqueInteger) — NIF 2.11 — OTP 19
;
// ---------------------------------------------------------------------------
// Hash
// ---------------------------------------------------------------------------
/// The hash algorithm selector for [`hash`](crate::hash).
///
/// Chooses between a fast non-portable internal hash and the portable `phash2`
/// that matches `erlang:phash2/1`.
///
/// [`ErlNifHash`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifHash) — NIF 2.12 — OTP 20
// ---------------------------------------------------------------------------
// Select (I/O event multiplexing)
// ---------------------------------------------------------------------------
/// Mode flags for [`select`](crate::select). Combine with `|`.
///
/// For example `SelectFlags::READ | SelectFlags::CUSTOM_MSG`. Defined in
/// `erl_drv_nif.h`; each flag carries its own introduction version, as the
/// cancel, custom-message, and error modes were added after the base ones.
///
/// [`ErlNifSelectFlags`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifSelectFlags) — NIF 2.12 — OTP 20
;
/// `select`'s stop callback ran on the calling thread.
///
/// A success bit in the value returned by [`select`](crate::select) /
/// [`select_x`](crate::select_x): the resource's stop callback was invoked
/// directly, so the event is fully retired on return. Test it with bitwise AND.
///
/// [`ERL_NIF_SELECT_STOP_CALLED`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_STOP_CALLED) — NIF 2.12 — OTP 20
pub const SELECT_STOP_CALLED: c_int = 1 << 0;
/// `select`'s stop callback was scheduled to run later.
///
/// A success bit: the stop callback could not run synchronously and was scheduled
/// to run later, on this or another thread, so the event is not yet retired when
/// [`select`](crate::select) returns.
///
/// [`ERL_NIF_SELECT_STOP_SCHEDULED`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_STOP_SCHEDULED) — NIF 2.12 — OTP 20
pub const SELECT_STOP_SCHEDULED: c_int = 1 << 1;
/// `select` was given an invalid event object.
///
/// A failure bit — the [`select`](crate::select) return value is negative —
/// meaning `event` was not a valid OS event object.
///
/// [`ERL_NIF_SELECT_INVALID_EVENT`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_INVALID_EVENT) — NIF 2.12 — OTP 20
pub const SELECT_INVALID_EVENT: c_int = 1 << 2;
/// `select` failed to add the event to the poll set.
///
/// A failure bit (negative return): the underlying system call could not add the
/// event object to the poll set.
///
/// [`ERL_NIF_SELECT_FAILED`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_FAILED) — NIF 2.12 — OTP 20
pub const SELECT_FAILED: c_int = 1 << 3;
/// A pending read `select` was cancelled.
///
/// A success bit: a read selection was removed by [`SelectFlags::CANCEL`] or
/// [`SelectFlags::STOP`] and is guaranteed not to produce a further `ready_input`
/// message.
///
/// [`ERL_NIF_SELECT_READ_CANCELLED`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_READ_CANCELLED) — NIF 2.15 — OTP 22
pub const SELECT_READ_CANCELLED: c_int = 1 << 4;
/// A pending write `select` was cancelled.
///
/// A success bit: a write selection was removed by [`SelectFlags::CANCEL`] or
/// [`SelectFlags::STOP`] and is guaranteed not to produce a further
/// `ready_output` message.
///
/// [`ERL_NIF_SELECT_WRITE_CANCELLED`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_WRITE_CANCELLED) — NIF 2.15 — OTP 22
pub const SELECT_WRITE_CANCELLED: c_int = 1 << 5;
/// A pending error `select` was cancelled.
///
/// A success bit: an error selection (see [`SelectFlags::ERROR`]) was removed by
/// [`SelectFlags::CANCEL`] or [`SelectFlags::STOP`].
///
/// [`ERL_NIF_SELECT_ERROR_CANCELLED`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_ERROR_CANCELLED) — NIF 2.16 — OTP 24
pub const SELECT_ERROR_CANCELLED: c_int = 1 << 6;
/// The requested `select` mode is not supported for the event object.
///
/// A failure bit (negative return): the requested mode — typically
/// [`SelectFlags::ERROR`] — is not supported for this event object on this
/// platform.
///
/// [`ERL_NIF_SELECT_NOTSUP`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_SELECT_NOTSUP) — NIF 2.16 — OTP 24
pub const SELECT_NOTSUP: c_int = 1 << 7;
// ---------------------------------------------------------------------------
// binary_to_term options
// ---------------------------------------------------------------------------
/// Safe decoding for `binary_to_term`: reject encoded atoms that don't already
/// exist.
///
/// [`ERL_NIF_BIN2TERM_SAFE`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_BIN2TERM_SAFE) — NIF 2.11 — OTP 19
pub const BIN2TERM_SAFE: c_uint = 0x2000_0000;
// ---------------------------------------------------------------------------
// System info
// ---------------------------------------------------------------------------
/// A snapshot of BEAM runtime information.
///
/// Filled by [`system_info`](crate::system_info) (the C type is also `ErlDrvSysInfo`): ERTS and OTP
/// version strings, the NIF and driver version numbers, scheduler counts, and the
/// SMP, thread, and dirty-scheduler support flags.
///
/// [`ErlNifSysInfo`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifSysInfo) — NIF 1.0 — OTP R13B04
// ---------------------------------------------------------------------------
// NIF options (enif_set_option) — NIF 2.17 (OTP 26.0)
// ---------------------------------------------------------------------------
/// The key selecting which runtime option `set_option` sets.
///
/// Used by the [`set_option_delay_halt`](crate::set_option_delay_halt), [`set_option_on_halt`](crate::set_option_on_halt), and
/// [`set_option_on_unload_thread`](crate::set_option_on_unload_thread) wrappers. The trailing underscore avoids
/// shadowing the `std` prelude `Option`.
///
/// [`ErlNifOption`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifOption) — NIF 2.17 — OTP 26
// ---------------------------------------------------------------------------
// Thread type (return values from enif_thread_type)
// ---------------------------------------------------------------------------
/// Not a scheduler thread.
///
/// [`ERL_NIF_THR_UNDEFINED`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_THR_UNDEFINED) — NIF 2.11 — OTP 19
pub const THR_UNDEFINED: c_int = 0;
/// Normal BEAM scheduler thread.
///
/// [`ERL_NIF_THR_NORMAL_SCHEDULER`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_THR_NORMAL_SCHEDULER) — NIF 2.11 — OTP 19
pub const THR_NORMAL_SCHEDULER: c_int = 1;
/// Dirty CPU scheduler thread.
///
/// [`ERL_NIF_THR_DIRTY_CPU_SCHEDULER`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_THR_DIRTY_CPU_SCHEDULER) — NIF 2.11 — OTP 19
pub const THR_DIRTY_CPU_SCHEDULER: c_int = 2;
/// Dirty I/O scheduler thread.
///
/// [`ERL_NIF_THR_DIRTY_IO_SCHEDULER`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_THR_DIRTY_IO_SCHEDULER) — NIF 2.11 — OTP 19
pub const THR_DIRTY_IO_SCHEDULER: c_int = 3;
// ---------------------------------------------------------------------------
// Dirty scheduler flags
// ---------------------------------------------------------------------------
// The two `ERL_NIF_DIRTY_JOB_*` constants. They apply to both the
// `enif_schedule_nif` `flags` argument and the [`Func::flags`] field (the
// latter is `c_uint`, so cast there); a regular NIF is just `0`.
/// Run on a dirty CPU scheduler.
///
/// [`ERL_NIF_DIRTY_JOB_CPU_BOUND`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_DIRTY_JOB_CPU_BOUND) — NIF 2.6 — OTP 17
pub const DIRTY_JOB_CPU_BOUND: c_int = 1;
/// Run on a dirty I/O scheduler.
///
/// [`ERL_NIF_DIRTY_JOB_IO_BOUND`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_DIRTY_JOB_IO_BOUND) — NIF 2.6 — OTP 17
pub const DIRTY_JOB_IO_BOUND: c_int = 2;
// ---------------------------------------------------------------------------
// I/O queue and iovec
// ---------------------------------------------------------------------------
/// An opaque I/O queue handle.
///
/// A FIFO of binary data used to stage output without copying. Created with
/// [`ioq_create`](crate::ioq_create) and destroyed with [`ioq_destroy`](crate::ioq_destroy); always handled as
/// `*mut IOQueue`.
///
/// [`ErlNifIOQueue`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifIOQueue) — NIF 2.12 — OTP 20.1
/// Creation mode for an I/O queue.
///
/// The `opts` argument to [`ioq_create`](crate::ioq_create); the only defined value is
/// [`IOQ_NORMAL`].
///
/// [`ErlNifIOQueueOpts`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifIOQueueOpts) — NIF 2.12 — OTP 20.1
pub type IOQueueOpts = c_int;
/// Normal I/O queue mode.
///
/// [`ERL_NIF_IOQ_NORMAL`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ERL_NIF_IOQ_NORMAL) — NIF 2.12 — OTP 20.1
pub const IOQ_NORMAL: IOQueueOpts = 1;
/// A scatter/gather I/O vector.
///
/// `iovcnt` [`SysIOVec`] segments at `iov` spanning `size` total bytes; the
/// remaining fields are BEAM-internal. Produced from an iolist by
/// [`inspect_iovec`](crate::inspect_iovec) and consumed by [`ioq_enqv`](crate::ioq_enqv).
///
/// [`ErlNifIOVec`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifIOVec) — NIF 2.12 — OTP 20.1
// ---------------------------------------------------------------------------
// Opaque thread-primitive handles
// ---------------------------------------------------------------------------
/// An opaque mutex handle.
///
/// Created with [`mutex_create`](crate::mutex_create) and destroyed with [`mutex_destroy`](crate::mutex_destroy); always
/// handled as `*mut Mutex`.
///
/// [`ErlNifMutex`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifMutex) — NIF 1.0 — OTP R13B04
/// An opaque condition variable handle.
///
/// Created with [`cond_create`](crate::cond_create) and destroyed with [`cond_destroy`](crate::cond_destroy); waited on
/// with [`cond_wait`](crate::cond_wait). Always handled as `*mut Cond`.
///
/// [`ErlNifCond`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifCond) — NIF 1.0 — OTP R13B04
/// An opaque read/write lock handle.
///
/// Created with [`rwlock_create`](crate::rwlock_create) and destroyed with [`rwlock_destroy`](crate::rwlock_destroy); always
/// handled as `*mut RWLock`.
///
/// [`ErlNifRWLock`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifRWLock) — NIF 1.0 — OTP R13B04
/// A thread identifier.
///
/// Returned by [`thread_self`](crate::thread_self), written by [`thread_create`](crate::thread_create), and compared with
/// [`equal_tids`](crate::equal_tids). An opaque pointer (in C, `struct ErlDrvTid_ *`).
///
/// [`ErlNifTid`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifTid) — NIF 1.0 — OTP R13B04
pub type Tid = *mut c_void;
/// A thread-specific data key.
///
/// Created with [`tsd_key_create`](crate::tsd_key_create); each thread stores and reads its own pointer
/// for the key with [`tsd_set`](crate::tsd_set) and [`tsd_get`](crate::tsd_get).
///
/// [`ErlNifTSDKey`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifTSDKey) — NIF 1.0 — OTP R13B04
pub type TSDKey = c_int;
/// Options for creating a thread.
///
/// Allocated with [`thread_opts_create`](crate::thread_opts_create) and passed to [`thread_create`](crate::thread_create). The
/// single field `suggested_stack_size` is a stack-size suggestion in kilowords;
/// a value below zero requests the default size.
///
/// [`ErlNifThreadOpts`](https://www.erlang.org/doc/apps/erts/erl_nif.html#ErlNifThreadOpts) — NIF 1.0 — OTP R13B04