Sha256: bf69830f13352d066bd4aa157c346ddfa0b578a3f973779a72640e66d25b4a40

Contents?: true

Size: 1.71 KB

Versions: 49

Compression:

Stored size: 1.71 KB

Contents

#include "wdm.h"

#include "memory.h"
#include "entry.h"
#include "queue.h"

#include "monitor.h"

WDM_PMonitor
wdm_monitor_new()
{
    WDM_PMonitor monitor;

    monitor = WDM_ALLOC(WDM_Monitor);

    monitor->running = FALSE;

    monitor->head = NULL;
    monitor->monitoring_thread = INVALID_HANDLE_VALUE;

    monitor->changes = wdm_queue_new();

    monitor->process_event = CreateEvent(NULL, TRUE, FALSE, NULL);
    monitor->stop_event = CreateEvent(NULL, TRUE, FALSE, NULL);

    if ( ! InitializeCriticalSectionAndSpinCount(&monitor->lock,
            0x00000400) ) // TODO: look into the best value for spinning.
    {
        rb_raise(eWDM_Error, "Can't create a lock for the monitor");
    }

    return monitor;
}

void
wdm_monitor_free(WDM_PMonitor monitor)
{
    if ( monitor->monitoring_thread != INVALID_HANDLE_VALUE ) CloseHandle(monitor->monitoring_thread);

    wdm_entry_list_free(monitor->head);
    wdm_queue_free(monitor->changes);
    DeleteCriticalSection(&monitor->lock);
    CloseHandle(monitor->process_event); // TODO: Look into why this crashes the app when exiting!
    CloseHandle(monitor->stop_event);

    free(monitor);
}

void
wdm_monitor_update_head(WDM_PMonitor monitor, WDM_PEntry new_head)
{
    EnterCriticalSection(&monitor->lock);
        new_head->next = monitor->head;
        monitor->head = new_head;
    LeaveCriticalSection(&monitor->lock);
}

WDM_PMonitorCallbackParam
wdm_monitor_callback_param_new(WDM_PMonitor monitor, WDM_PEntry entry)
{
    WDM_PMonitorCallbackParam param;

    param = WDM_ALLOC(WDM_MonitorCallbackParam);

    param->monitor = monitor;
    param->entry = entry;

    return param;
}

void
wdm_monitor_callback_param_free(WDM_PMonitorCallbackParam param)
{
    free(param);
}

Version data entries

49 entries across 41 versions & 5 rubygems

Version Path
wdm-0.2.0 ext/wdm/monitor.c
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/wdm-0.1.1/ext/wdm/monitor.c