Class: NewRelic::Starter::Latch
- Inherits:
-
Object
- Object
- NewRelic::Starter::Latch
- Defined in:
- ext/new_relic_starter/new_relic_starter.c,
ext/new_relic_starter/new_relic_starter.c
Overview
NewRelic::Starter::Latch indicates whether the New Relic agent should be started.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Object
constructor
Returns a new Latch object.
-
#open ⇒ nil
Opens the latch.
-
#opened? ⇒ Boolean
Returns true if the latch is opened.
Constructor Details
#NewRelic::Starter::Latch.new ⇒ Object #NewRelic::Starter::Latch.new(path) ⇒ Object
Returns a new NewRelic::Starter::Latch object.
The state of the latch is stored in memory mapped by mmap(2) and shared with a forked process.
If path
is specified, the memory mapping is backed by the file and the state of the latch is shared with other latches backed by the same file.
NewRelic::Starter::Latch.new #=> #<NewRelic::Starter::Latch:0x00007fbecb04f038>
NewRelic::Starter::Latch.new("/path/to/latch") #=> #<NewRelic::Starter::Latch:0x00007fbec9808010>
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'ext/new_relic_starter/new_relic_starter.c', line 90
static VALUE
latch_initialize(int argc, VALUE *argv, VALUE self)
{
int fd = -1;
void *addr;
char *path = rb_check_arity(argc, 0, 1) ? RSTRING_PTR(argv[0]) : NULL;
if (path != NULL) {
fd = open_latch_file(path);
}
addr = mmap(NULL, 1, PROT_READ|PROT_WRITE, (fd == -1 ? MAP_ANONYMOUS|MAP_SHARED : MAP_SHARED), fd, 0);
if (addr == MAP_FAILED) {
int e = errno;
close(fd);
rb_raise(eError, "failed to create mapping for latch: %s", strerror(e));
}
close(fd);
DATA_PTR(self) = addr;
return self;
}
|
Instance Method Details
#open ⇒ nil
131 132 133 134 135 136 137 |
# File 'ext/new_relic_starter/new_relic_starter.c', line 131
static VALUE
latch_open(VALUE self)
{
uint8_t *l = check_latch(self);
*l = 1;
return Qnil;
}
|
#opened? ⇒ Boolean
150 151 152 153 154 |
# File 'ext/new_relic_starter/new_relic_starter.c', line 150
static VALUE
latch_opened(VALUE self)
{
return *check_latch(self) == 1 ? Qtrue : Qfalse;
}
|