File: atomic_boolean.c

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; ansic: 288; makefile: 9; sh: 6
file content (47 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (2)
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
#include <ruby.h>

#include "atomic_boolean.h"
#include "atomic_reference.h"
#include "ruby_193_compatible.h"

void atomic_boolean_mark(void *value) {
  rb_gc_mark_maybe((VALUE) value);
}

VALUE atomic_boolean_allocate(VALUE klass) {
  return rb_data_object_alloc(klass, (void *) Qfalse, atomic_boolean_mark, NULL);
}

VALUE method_atomic_boolean_initialize(int argc, VALUE* argv, VALUE self) {
  VALUE value = Qfalse;
  rb_check_arity(argc, 0, 1);
  if (argc == 1) value = TRUTHY(argv[0]);
  DATA_PTR(self) = (void *) value;
  return(self);
}

VALUE method_atomic_boolean_value(VALUE self) {
  return(ir_get(self));
}

VALUE method_atomic_boolean_value_set(VALUE self, VALUE value) {
  VALUE new_value = TRUTHY(value);
  return(ir_set(self, new_value));
}

VALUE method_atomic_boolean_true_question(VALUE self) {
  return(method_atomic_boolean_value(self));
}

VALUE method_atomic_boolean_false_question(VALUE self) {
  VALUE current = method_atomic_boolean_value(self);
  return(current == Qfalse ? Qtrue : Qfalse);
}

VALUE method_atomic_boolean_make_true(VALUE self) {
  return(ir_compare_and_set(self, Qfalse, Qtrue));
}

VALUE method_atomic_boolean_make_false(VALUE self) {
  return(ir_compare_and_set(self, Qtrue, Qfalse));
}