wdm 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -21
- data/README.md +206 -206
- data/ext/wdm/entry.c +71 -71
- data/ext/wdm/entry.h +46 -46
- data/ext/wdm/extconf.rb +28 -27
- data/ext/wdm/memory.c +26 -26
- data/ext/wdm/memory.h +29 -29
- data/ext/wdm/monitor.c +74 -74
- data/ext/wdm/monitor.h +49 -49
- data/ext/wdm/queue.c +195 -195
- data/ext/wdm/queue.h +72 -72
- data/ext/wdm/rb_change.c +198 -198
- data/ext/wdm/rb_change.h +27 -27
- data/ext/wdm/rb_monitor.c +574 -570
- data/ext/wdm/rb_monitor.h +39 -39
- data/ext/wdm/utils.c +76 -76
- data/ext/wdm/utils.h +25 -25
- data/ext/wdm/wdm.c +46 -46
- data/ext/wdm/wdm.h +81 -71
- data/ext/wdm/wdm.sln +20 -20
- data/ext/wdm/wdm.vcxproj +105 -105
- data/ext/wdm/wdm.vcxproj.filters +73 -73
- data/lib/wdm.rb +9 -9
- metadata +20 -64
data/ext/wdm/monitor.h
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
-
#include <Windows.h>
|
2
|
-
|
3
|
-
#include "entry.h"
|
4
|
-
#include "queue.h"
|
5
|
-
|
6
|
-
#ifndef WDM_MONITOR_H
|
7
|
-
#define WDM_MONITOR_H
|
8
|
-
|
9
|
-
#ifdef __cplusplus
|
10
|
-
extern "C" {
|
11
|
-
#endif // __cplusplus
|
12
|
-
|
13
|
-
// ---------------------------------------------------------
|
14
|
-
// Types
|
15
|
-
// ---------------------------------------------------------
|
16
|
-
|
17
|
-
typedef struct {
|
18
|
-
BOOL running;
|
19
|
-
WDM_PEntry head;
|
20
|
-
WDM_PQueue changes;
|
21
|
-
CRITICAL_SECTION lock;
|
22
|
-
HANDLE monitoring_thread;
|
23
|
-
HANDLE process_event;
|
24
|
-
HANDLE stop_event;
|
25
|
-
} WDM_Monitor, *WDM_PMonitor;
|
26
|
-
|
27
|
-
typedef struct {
|
28
|
-
WDM_PEntry entry;
|
29
|
-
WDM_PMonitor monitor;
|
30
|
-
} WDM_MonitorCallbackParam, *WDM_PMonitorCallbackParam;
|
31
|
-
|
32
|
-
// ---------------------------------------------------------
|
33
|
-
// Prototypes
|
34
|
-
// ---------------------------------------------------------
|
35
|
-
|
36
|
-
WDM_PMonitor wdm_monitor_new();
|
37
|
-
void wdm_monitor_free(WDM_PMonitor);
|
38
|
-
|
39
|
-
void wdm_monitor_update_head(WDM_PMonitor, WDM_PEntry);
|
40
|
-
|
41
|
-
WDM_PMonitorCallbackParam wdm_monitor_callback_param_new(WDM_PMonitor, WDM_PEntry);
|
42
|
-
void wdm_monitor_callback_param_free(WDM_PMonitorCallbackParam);
|
43
|
-
|
44
|
-
// ---------------------------------------------------------
|
45
|
-
|
46
|
-
#ifdef __cplusplus
|
47
|
-
}
|
48
|
-
#endif // __cplusplus
|
49
|
-
|
1
|
+
#include <Windows.h>
|
2
|
+
|
3
|
+
#include "entry.h"
|
4
|
+
#include "queue.h"
|
5
|
+
|
6
|
+
#ifndef WDM_MONITOR_H
|
7
|
+
#define WDM_MONITOR_H
|
8
|
+
|
9
|
+
#ifdef __cplusplus
|
10
|
+
extern "C" {
|
11
|
+
#endif // __cplusplus
|
12
|
+
|
13
|
+
// ---------------------------------------------------------
|
14
|
+
// Types
|
15
|
+
// ---------------------------------------------------------
|
16
|
+
|
17
|
+
typedef struct {
|
18
|
+
BOOL running;
|
19
|
+
WDM_PEntry head;
|
20
|
+
WDM_PQueue changes;
|
21
|
+
CRITICAL_SECTION lock;
|
22
|
+
HANDLE monitoring_thread;
|
23
|
+
HANDLE process_event;
|
24
|
+
HANDLE stop_event;
|
25
|
+
} WDM_Monitor, *WDM_PMonitor;
|
26
|
+
|
27
|
+
typedef struct {
|
28
|
+
WDM_PEntry entry;
|
29
|
+
WDM_PMonitor monitor;
|
30
|
+
} WDM_MonitorCallbackParam, *WDM_PMonitorCallbackParam;
|
31
|
+
|
32
|
+
// ---------------------------------------------------------
|
33
|
+
// Prototypes
|
34
|
+
// ---------------------------------------------------------
|
35
|
+
|
36
|
+
WDM_PMonitor wdm_monitor_new();
|
37
|
+
void wdm_monitor_free(WDM_PMonitor);
|
38
|
+
|
39
|
+
void wdm_monitor_update_head(WDM_PMonitor, WDM_PEntry);
|
40
|
+
|
41
|
+
WDM_PMonitorCallbackParam wdm_monitor_callback_param_new(WDM_PMonitor, WDM_PEntry);
|
42
|
+
void wdm_monitor_callback_param_free(WDM_PMonitorCallbackParam);
|
43
|
+
|
44
|
+
// ---------------------------------------------------------
|
45
|
+
|
46
|
+
#ifdef __cplusplus
|
47
|
+
}
|
48
|
+
#endif // __cplusplus
|
49
|
+
|
50
50
|
#endif // WDM_MONITOR_H
|
data/ext/wdm/queue.c
CHANGED
@@ -1,196 +1,196 @@
|
|
1
|
-
#include <stdarg.h>
|
2
|
-
|
3
|
-
#include "wdm.h"
|
4
|
-
|
5
|
-
#include "memory.h"
|
6
|
-
#include "queue.h"
|
7
|
-
|
8
|
-
// ---------------------------------------------------------
|
9
|
-
// Prototypes of static functions
|
10
|
-
// ---------------------------------------------------------
|
11
|
-
|
12
|
-
static WDM_PQueueItem do_queue_dequeue(WDM_PQueue queue);
|
13
|
-
|
14
|
-
// ---------------------------------------------------------
|
15
|
-
// Queue item functions
|
16
|
-
// ---------------------------------------------------------
|
17
|
-
|
18
|
-
WDM_PQueueItemError
|
19
|
-
wdm_queue_item_error_new(VALUE exception, LPCSTR format, ...)
|
20
|
-
{
|
21
|
-
WDM_PQueueItemError error;
|
22
|
-
va_list ap;
|
23
|
-
int length;
|
24
|
-
|
25
|
-
error = WDM_ALLOC(WDM_QueueItemError);
|
26
|
-
|
27
|
-
va_start(ap, format);
|
28
|
-
length = _vscprintf(format, ap);
|
29
|
-
error->message = WDM_ALLOC_N(CHAR, length + 1);
|
30
|
-
vsprintf(error->message, format, ap);
|
31
|
-
va_end(ap);
|
32
|
-
|
33
|
-
error->exception_klass = exception;
|
34
|
-
|
35
|
-
return error;
|
36
|
-
}
|
37
|
-
|
38
|
-
void
|
39
|
-
wdm_queue_item_error_free(WDM_PQueueItemError error)
|
40
|
-
{
|
41
|
-
if ( error->message != NULL ) free(error->message);
|
42
|
-
free(error);
|
43
|
-
}
|
44
|
-
|
45
|
-
WDM_PQueueItemData
|
46
|
-
wdm_queue_item_data_new()
|
47
|
-
{
|
48
|
-
WDM_PQueueItemData data;
|
49
|
-
|
50
|
-
data = WDM_ALLOC(WDM_QueueItemData);
|
51
|
-
data->user_data = NULL;
|
52
|
-
|
53
|
-
ZeroMemory(&data->buffer, WDM_BUFFER_SIZE);
|
54
|
-
|
55
|
-
return data;
|
56
|
-
}
|
57
|
-
|
58
|
-
void
|
59
|
-
wdm_queue_item_data_free(WDM_PQueueItemData data)
|
60
|
-
{
|
61
|
-
free(data);
|
62
|
-
}
|
63
|
-
|
64
|
-
WDM_PQueueItem
|
65
|
-
wdm_queue_item_new(WDM_QueueItemType type)
|
66
|
-
{
|
67
|
-
WDM_PQueueItem item;
|
68
|
-
|
69
|
-
item = WDM_ALLOC(WDM_QueueItem);
|
70
|
-
item->type = type;
|
71
|
-
|
72
|
-
if ( type == WDM_QUEUE_ITEM_TYPE_ERROR ) {
|
73
|
-
item->error = NULL;
|
74
|
-
}
|
75
|
-
else {
|
76
|
-
item->data = NULL;
|
77
|
-
}
|
78
|
-
|
79
|
-
item->next = NULL;
|
80
|
-
|
81
|
-
return item;
|
82
|
-
}
|
83
|
-
|
84
|
-
void
|
85
|
-
wdm_queue_item_free(WDM_PQueueItem item)
|
86
|
-
{
|
87
|
-
if ( item->type == WDM_QUEUE_ITEM_TYPE_ERROR ) {
|
88
|
-
if ( item->error != NULL ) wdm_queue_item_error_free(item->error);
|
89
|
-
}
|
90
|
-
else {
|
91
|
-
if ( item->data != NULL ) wdm_queue_item_data_free(item->data);
|
92
|
-
}
|
93
|
-
|
94
|
-
// We can't really do anything to the next pointer because
|
95
|
-
// we might break any linking the user has established.
|
96
|
-
free(item);
|
97
|
-
}
|
98
|
-
|
99
|
-
// ---------------------------------------------------------
|
100
|
-
// Queue functions
|
101
|
-
// ---------------------------------------------------------
|
102
|
-
|
103
|
-
WDM_PQueue
|
104
|
-
wdm_queue_new()
|
105
|
-
{
|
106
|
-
WDM_PQueue queue;
|
107
|
-
|
108
|
-
queue = WDM_ALLOC(WDM_Queue);
|
109
|
-
queue->front = NULL;
|
110
|
-
queue->rear = NULL;
|
111
|
-
|
112
|
-
if ( ! InitializeCriticalSectionAndSpinCount(&queue->lock,
|
113
|
-
0x00000400) ) // TODO: look into the best value for spinning.
|
114
|
-
{
|
115
|
-
rb_raise(eWDM_Error, "Can't create a lock for the queue");
|
116
|
-
}
|
117
|
-
|
118
|
-
return queue;
|
119
|
-
}
|
120
|
-
|
121
|
-
void
|
122
|
-
wdm_queue_free(WDM_PQueue queue)
|
123
|
-
{
|
124
|
-
wdm_queue_empty(queue);
|
125
|
-
free(queue);
|
126
|
-
}
|
127
|
-
|
128
|
-
void
|
129
|
-
wdm_queue_enqueue(WDM_PQueue queue, WDM_PQueueItem item)
|
130
|
-
{
|
131
|
-
EnterCriticalSection(&queue->lock);
|
132
|
-
|
133
|
-
if ( wdm_queue_is_empty(queue) ) {
|
134
|
-
queue->front = queue->rear = item;
|
135
|
-
}
|
136
|
-
else {
|
137
|
-
queue->rear->next = item;
|
138
|
-
queue->rear = item;
|
139
|
-
}
|
140
|
-
|
141
|
-
LeaveCriticalSection(&queue->lock);
|
142
|
-
}
|
143
|
-
|
144
|
-
WDM_PQueueItem
|
145
|
-
do_queue_dequeue(WDM_PQueue queue)
|
146
|
-
{
|
147
|
-
WDM_PQueueItem item;
|
148
|
-
|
149
|
-
if ( wdm_queue_is_empty(queue) ) {
|
150
|
-
item = NULL;
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
item = queue->front;
|
154
|
-
queue->front = queue->front->next;
|
155
|
-
|
156
|
-
// Reset the rear when the queue is empty
|
157
|
-
if ( queue->front == NULL ) queue->rear = NULL;
|
158
|
-
|
159
|
-
// Don't allow the user to mess with the queue
|
160
|
-
item->next = NULL;
|
161
|
-
}
|
162
|
-
|
163
|
-
return item;
|
164
|
-
}
|
165
|
-
|
166
|
-
WDM_PQueueItem
|
167
|
-
wdm_queue_dequeue(WDM_PQueue queue)
|
168
|
-
{
|
169
|
-
WDM_PQueueItem item;
|
170
|
-
|
171
|
-
EnterCriticalSection(&queue->lock);
|
172
|
-
|
173
|
-
item = do_queue_dequeue(queue);
|
174
|
-
|
175
|
-
LeaveCriticalSection(&queue->lock);
|
176
|
-
|
177
|
-
return item;
|
178
|
-
}
|
179
|
-
|
180
|
-
void
|
181
|
-
wdm_queue_empty(WDM_PQueue queue)
|
182
|
-
{
|
183
|
-
EnterCriticalSection(&queue->lock);
|
184
|
-
|
185
|
-
while( ! wdm_queue_is_empty(queue) ) {
|
186
|
-
wdm_queue_item_free( do_queue_dequeue(queue) );
|
187
|
-
}
|
188
|
-
|
189
|
-
LeaveCriticalSection(&queue->lock);
|
190
|
-
}
|
191
|
-
|
192
|
-
inline BOOL
|
193
|
-
wdm_queue_is_empty(WDM_PQueue queue)
|
194
|
-
{
|
195
|
-
return queue->front == NULL && queue->rear == NULL;
|
1
|
+
#include <stdarg.h>
|
2
|
+
|
3
|
+
#include "wdm.h"
|
4
|
+
|
5
|
+
#include "memory.h"
|
6
|
+
#include "queue.h"
|
7
|
+
|
8
|
+
// ---------------------------------------------------------
|
9
|
+
// Prototypes of static functions
|
10
|
+
// ---------------------------------------------------------
|
11
|
+
|
12
|
+
static WDM_PQueueItem do_queue_dequeue(WDM_PQueue queue);
|
13
|
+
|
14
|
+
// ---------------------------------------------------------
|
15
|
+
// Queue item functions
|
16
|
+
// ---------------------------------------------------------
|
17
|
+
|
18
|
+
WDM_PQueueItemError
|
19
|
+
wdm_queue_item_error_new(VALUE exception, LPCSTR format, ...)
|
20
|
+
{
|
21
|
+
WDM_PQueueItemError error;
|
22
|
+
va_list ap;
|
23
|
+
int length;
|
24
|
+
|
25
|
+
error = WDM_ALLOC(WDM_QueueItemError);
|
26
|
+
|
27
|
+
va_start(ap, format);
|
28
|
+
length = _vscprintf(format, ap);
|
29
|
+
error->message = WDM_ALLOC_N(CHAR, length + 1);
|
30
|
+
vsprintf(error->message, format, ap);
|
31
|
+
va_end(ap);
|
32
|
+
|
33
|
+
error->exception_klass = exception;
|
34
|
+
|
35
|
+
return error;
|
36
|
+
}
|
37
|
+
|
38
|
+
void
|
39
|
+
wdm_queue_item_error_free(WDM_PQueueItemError error)
|
40
|
+
{
|
41
|
+
if ( error->message != NULL ) free(error->message);
|
42
|
+
free(error);
|
43
|
+
}
|
44
|
+
|
45
|
+
WDM_PQueueItemData
|
46
|
+
wdm_queue_item_data_new()
|
47
|
+
{
|
48
|
+
WDM_PQueueItemData data;
|
49
|
+
|
50
|
+
data = WDM_ALLOC(WDM_QueueItemData);
|
51
|
+
data->user_data = NULL;
|
52
|
+
|
53
|
+
ZeroMemory(&data->buffer, WDM_BUFFER_SIZE);
|
54
|
+
|
55
|
+
return data;
|
56
|
+
}
|
57
|
+
|
58
|
+
void
|
59
|
+
wdm_queue_item_data_free(WDM_PQueueItemData data)
|
60
|
+
{
|
61
|
+
free(data);
|
62
|
+
}
|
63
|
+
|
64
|
+
WDM_PQueueItem
|
65
|
+
wdm_queue_item_new(WDM_QueueItemType type)
|
66
|
+
{
|
67
|
+
WDM_PQueueItem item;
|
68
|
+
|
69
|
+
item = WDM_ALLOC(WDM_QueueItem);
|
70
|
+
item->type = type;
|
71
|
+
|
72
|
+
if ( type == WDM_QUEUE_ITEM_TYPE_ERROR ) {
|
73
|
+
item->error = NULL;
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
item->data = NULL;
|
77
|
+
}
|
78
|
+
|
79
|
+
item->next = NULL;
|
80
|
+
|
81
|
+
return item;
|
82
|
+
}
|
83
|
+
|
84
|
+
void
|
85
|
+
wdm_queue_item_free(WDM_PQueueItem item)
|
86
|
+
{
|
87
|
+
if ( item->type == WDM_QUEUE_ITEM_TYPE_ERROR ) {
|
88
|
+
if ( item->error != NULL ) wdm_queue_item_error_free(item->error);
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
if ( item->data != NULL ) wdm_queue_item_data_free(item->data);
|
92
|
+
}
|
93
|
+
|
94
|
+
// We can't really do anything to the next pointer because
|
95
|
+
// we might break any linking the user has established.
|
96
|
+
free(item);
|
97
|
+
}
|
98
|
+
|
99
|
+
// ---------------------------------------------------------
|
100
|
+
// Queue functions
|
101
|
+
// ---------------------------------------------------------
|
102
|
+
|
103
|
+
WDM_PQueue
|
104
|
+
wdm_queue_new()
|
105
|
+
{
|
106
|
+
WDM_PQueue queue;
|
107
|
+
|
108
|
+
queue = WDM_ALLOC(WDM_Queue);
|
109
|
+
queue->front = NULL;
|
110
|
+
queue->rear = NULL;
|
111
|
+
|
112
|
+
if ( ! InitializeCriticalSectionAndSpinCount(&queue->lock,
|
113
|
+
0x00000400) ) // TODO: look into the best value for spinning.
|
114
|
+
{
|
115
|
+
rb_raise(eWDM_Error, "Can't create a lock for the queue");
|
116
|
+
}
|
117
|
+
|
118
|
+
return queue;
|
119
|
+
}
|
120
|
+
|
121
|
+
void
|
122
|
+
wdm_queue_free(WDM_PQueue queue)
|
123
|
+
{
|
124
|
+
wdm_queue_empty(queue);
|
125
|
+
free(queue);
|
126
|
+
}
|
127
|
+
|
128
|
+
void
|
129
|
+
wdm_queue_enqueue(WDM_PQueue queue, WDM_PQueueItem item)
|
130
|
+
{
|
131
|
+
EnterCriticalSection(&queue->lock);
|
132
|
+
|
133
|
+
if ( wdm_queue_is_empty(queue) ) {
|
134
|
+
queue->front = queue->rear = item;
|
135
|
+
}
|
136
|
+
else {
|
137
|
+
queue->rear->next = item;
|
138
|
+
queue->rear = item;
|
139
|
+
}
|
140
|
+
|
141
|
+
LeaveCriticalSection(&queue->lock);
|
142
|
+
}
|
143
|
+
|
144
|
+
WDM_PQueueItem
|
145
|
+
do_queue_dequeue(WDM_PQueue queue)
|
146
|
+
{
|
147
|
+
WDM_PQueueItem item;
|
148
|
+
|
149
|
+
if ( wdm_queue_is_empty(queue) ) {
|
150
|
+
item = NULL;
|
151
|
+
}
|
152
|
+
else {
|
153
|
+
item = queue->front;
|
154
|
+
queue->front = queue->front->next;
|
155
|
+
|
156
|
+
// Reset the rear when the queue is empty
|
157
|
+
if ( queue->front == NULL ) queue->rear = NULL;
|
158
|
+
|
159
|
+
// Don't allow the user to mess with the queue
|
160
|
+
item->next = NULL;
|
161
|
+
}
|
162
|
+
|
163
|
+
return item;
|
164
|
+
}
|
165
|
+
|
166
|
+
WDM_PQueueItem
|
167
|
+
wdm_queue_dequeue(WDM_PQueue queue)
|
168
|
+
{
|
169
|
+
WDM_PQueueItem item;
|
170
|
+
|
171
|
+
EnterCriticalSection(&queue->lock);
|
172
|
+
|
173
|
+
item = do_queue_dequeue(queue);
|
174
|
+
|
175
|
+
LeaveCriticalSection(&queue->lock);
|
176
|
+
|
177
|
+
return item;
|
178
|
+
}
|
179
|
+
|
180
|
+
void
|
181
|
+
wdm_queue_empty(WDM_PQueue queue)
|
182
|
+
{
|
183
|
+
EnterCriticalSection(&queue->lock);
|
184
|
+
|
185
|
+
while( ! wdm_queue_is_empty(queue) ) {
|
186
|
+
wdm_queue_item_free( do_queue_dequeue(queue) );
|
187
|
+
}
|
188
|
+
|
189
|
+
LeaveCriticalSection(&queue->lock);
|
190
|
+
}
|
191
|
+
|
192
|
+
inline BOOL
|
193
|
+
wdm_queue_is_empty(WDM_PQueue queue)
|
194
|
+
{
|
195
|
+
return queue->front == NULL && queue->rear == NULL;
|
196
196
|
}
|