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
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/wdm-0.1.1/ext/wdm/monitor.c
vagrant-cloudstack-1.2.0 vendor/bundle/gems/wdm-0.1.1/ext/wdm/monitor.c
wdm-0.1.1 ext/wdm/monitor.c