Module: Contrast::Components::Scope

Defined in:
lib/contrast/components/scope.rb,
ext/cs__scope/cs__scope.c

Overview

Constants defined in C:

MONITOR = Mutex.new This was replaced from Monitor to Mutex. EXECUTION_CONTEXT = {} Hash containing all of the current ecs as keys pointing to their scope instances. EC_KEYS = [] set while we get the current ec, and used for sweeping the dead fibers in C.

Methods defined in C:

class Interface

initializes the scope for the current fiber context.
def initialize end;

  This returns the scope governing the current execution context. Use this sparingly, preferring the instance
 & class methods to access and query scope, rather than interacting with the scope object directly.
def scope_for_current_ec end;

end

module Scope

Singleton method for cleaning the dead fibers and unused scope instances, scope GC.
def self.sweep_dead_ecs end;

end

Defined Under Namespace

Modules: InstanceMethods Classes: Interface

Constant Summary collapse

ClassMethods =
InstanceMethods

Class Method Summary collapse

Class Method Details

.cs__with_app_scope?Boolean

If the value set is not valid the Contrast Scope with start with 0. If the value is validated, then the Contrast Scope will be set to 1. If the value is nil the Contrast Scope will be set as default => 0.

To be valid app scope must be one of the truthy_arr: [“true”, “True”, “TRUE”, “1”]

Returns:

  • (Boolean)


149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'ext/cs__scope/cs__scope.c', line 149

VALUE contrast_scope_application_update() {
    /**
     * ENV variables are null-terminated strings.
     *
     * getenv() returns a pointer to a string within the environment list.
     * The caller must take care not to modify this string,
     * since that would change the environment of the process.
     *
     * [ Do not touch, do not free. We don't control it! ]
     */
    char *eVar = getenv(c_const_ctr_agent_app_scope);
    /* check to see if the ENV variable is set */
    return INT2FIX(env_var_set(eVar));
}

.sweep_dead_ecs(args) ⇒ Object

TODO: RUBY-534, #sweep_dead_ecs compensates for a lack of weak tables. when we can use WeakRef, we should investigate removing this call and instead use the WeakRef for the Execution Context’s Keys or using our Finalizers Hash for Fibers

Parameters:

  • self

    VALUE

  • args

    VALUE

Returns:

  • VALUE



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
# File 'ext/cs__scope/cs__scope.c', line 859

VALUE scope_mod_sweep_dead_ecs(VALUE self, VALUE args) {
    VALUE mutex, ec, ec_keys, key, test;

    mutex = rb_const_get(scope_mod, rb_intern(rb_const_mon));
    ec = rb_const_get(scope_mod, rb_intern(rb_const_ec));
    ec_keys = rb_const_get(scope_mod, rb_intern(rb_const_ec_keys));

    /* Check if the key is dead (terminated fiber) and delete if true. */
    int i = 0;
    int size = rb_hash_size(ec_keys);

    for (i = 0; i < size; ++i) {
        key = rb_ary_entry(ec_keys, i);
        test = key;
        if (!RB_TYPE_P(key, T_NIL)) {
            if (!rb_fiber_alive_p(key)) {
                rb_hash_delete(ec, key);
            }
        }
    }

    return ec;
}