Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Kernel Services Thread |
| 3 | * |
| 4 | * Copyright 1999 Ulrich Weigand |
| 5 | */ |
| 6 | |
| 7 | #include <sys/time.h> |
| 8 | #include <unistd.h> |
| 9 | |
| 10 | #include "services.h" |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 11 | #include "process.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 12 | #include "debugtools.h" |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 13 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 14 | DEFAULT_DEBUG_CHANNEL(timer) |
| 15 | |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 16 | typedef struct _SERVICE |
| 17 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 18 | struct _SERVICE *next; |
| 19 | HANDLE self; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 20 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 21 | PAPCFUNC callback; |
| 22 | ULONG_PTR callback_arg; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 24 | BOOL disabled; |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 25 | HANDLE object; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 26 | } SERVICE; |
| 27 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 28 | typedef struct _SERVICETABLE |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 29 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 30 | HANDLE thread; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 31 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 32 | SERVICE *first; |
| 33 | DWORD counter; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 34 | |
| 35 | } SERVICETABLE; |
| 36 | |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 37 | /*********************************************************************** |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 38 | * SERVICE_Loop |
| 39 | */ |
| 40 | static DWORD CALLBACK SERVICE_Loop( SERVICETABLE *service ) |
| 41 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 42 | HANDLE handles[MAXIMUM_WAIT_OBJECTS]; |
| 43 | int count = 0; |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 44 | DWORD retval = WAIT_FAILED; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 45 | |
| 46 | while ( TRUE ) |
| 47 | { |
| 48 | PAPCFUNC callback; |
| 49 | ULONG_PTR callback_arg; |
| 50 | SERVICE *s; |
| 51 | |
| 52 | /* Check whether some condition is fulfilled */ |
| 53 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 54 | HeapLock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 55 | |
| 56 | callback = NULL; |
| 57 | callback_arg = 0L; |
| 58 | for ( s = service->first; s; s = s->next ) |
| 59 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 60 | if (s->disabled) continue; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 61 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 62 | if ( retval >= WAIT_OBJECT_0 && retval < WAIT_OBJECT_0 + count ) |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 63 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 64 | if ( handles[retval - WAIT_OBJECT_0] == s->object ) |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 65 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 66 | retval = WAIT_TIMEOUT; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 67 | callback = s->callback; |
| 68 | callback_arg = s->callback_arg; |
| 69 | break; |
| 70 | } |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 71 | } |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 74 | HeapUnlock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 75 | |
| 76 | /* If found, call callback routine */ |
| 77 | |
| 78 | if ( callback ) |
| 79 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 80 | callback( callback_arg ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 81 | continue; |
| 82 | } |
| 83 | |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 84 | /* If not found, determine wait condition */ |
| 85 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 86 | HeapLock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 87 | |
| 88 | count = 0; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 89 | for ( s = service->first; s; s = s->next ) |
| 90 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 91 | if (s->disabled) continue; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 92 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 93 | if ( count < MAXIMUM_WAIT_OBJECTS ) |
| 94 | handles[count++] = s->object; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 97 | HeapUnlock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 98 | |
| 99 | |
| 100 | /* Wait until some condition satisfied */ |
| 101 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 102 | TRACE("Waiting for %d objects\n", count ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 103 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 104 | retval = WaitForMultipleObjectsEx( count, handles, FALSE, INFINITE, TRUE ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 105 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 106 | TRACE("Wait returned: %ld\n", retval ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | return 0L; |
| 110 | } |
| 111 | |
| 112 | /*********************************************************************** |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 113 | * SERVICE_CreateServiceTable |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 114 | */ |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 115 | static BOOL SERVICE_CreateServiceTable( void ) |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 116 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 117 | HANDLE thread; |
| 118 | SERVICETABLE *service_table; |
| 119 | PDB *pdb = PROCESS_Current(); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 120 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 121 | service_table = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SERVICETABLE) ); |
| 122 | if ( !service_table ) |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 123 | { |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 124 | return FALSE; |
| 125 | } |
| 126 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 127 | /* service_table field in PDB must be set *BEFORE* calling CreateThread |
| 128 | * otherwise the thread cleanup service will cause an infinite recursion |
| 129 | * when installed |
| 130 | */ |
| 131 | pdb->service_table = service_table; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 132 | |
| 133 | thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)SERVICE_Loop, |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 134 | service_table, 0, NULL ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 135 | if ( thread == INVALID_HANDLE_VALUE ) |
| 136 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 137 | pdb->service_table = 0; |
| 138 | HeapFree( GetProcessHeap(), 0, service_table ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 139 | return FALSE; |
| 140 | } |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 141 | |
| 142 | service_table->thread = thread; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 143 | |
| 144 | return TRUE; |
| 145 | } |
| 146 | |
| 147 | /*********************************************************************** |
| 148 | * SERVICE_AddObject |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 149 | * |
| 150 | * Warning: the object supplied by the caller must not be closed. It'll |
| 151 | * be destroyed when the service is deleted. It's up to the caller |
| 152 | * to ensure that object will not be destroyed in between. |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 153 | */ |
| 154 | HANDLE SERVICE_AddObject( HANDLE object, |
| 155 | PAPCFUNC callback, ULONG_PTR callback_arg ) |
| 156 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 157 | SERVICE *s; |
| 158 | SERVICETABLE *service_table; |
| 159 | HANDLE handle; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 160 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 161 | if ( object == INVALID_HANDLE_VALUE || !callback ) |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 162 | return INVALID_HANDLE_VALUE; |
| 163 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 164 | if (PROCESS_Current()->service_table == 0 && !SERVICE_CreateServiceTable()) |
| 165 | return INVALID_HANDLE_VALUE; |
| 166 | service_table = PROCESS_Current()->service_table; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 167 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 168 | s = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SERVICE) ); |
| 169 | if ( !s ) return INVALID_HANDLE_VALUE; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 170 | |
| 171 | s->callback = callback; |
| 172 | s->callback_arg = callback_arg; |
| 173 | s->object = object; |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 174 | s->disabled = FALSE; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 175 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 176 | HeapLock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 177 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 178 | s->self = handle = (HANDLE)++service_table->counter; |
| 179 | s->next = service_table->first; |
| 180 | service_table->first = s; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 181 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 182 | HeapUnlock( GetProcessHeap() ); |
| 183 | |
| 184 | QueueUserAPC( NULL, service_table->thread, 0L ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 185 | |
| 186 | return handle; |
| 187 | } |
| 188 | |
| 189 | /*********************************************************************** |
| 190 | * SERVICE_AddTimer |
| 191 | */ |
| 192 | HANDLE SERVICE_AddTimer( LONG rate, |
| 193 | PAPCFUNC callback, ULONG_PTR callback_arg ) |
| 194 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 195 | HANDLE handle, ret; |
| 196 | LARGE_INTEGER when; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 197 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 198 | if ( !rate || !callback ) |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 199 | return INVALID_HANDLE_VALUE; |
| 200 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 201 | handle = CreateWaitableTimerA( NULL, FALSE, NULL ); |
| 202 | if (!handle) return INVALID_HANDLE_VALUE; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 203 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 204 | rate = (rate + 500) / 1000; /* us -> ms */ |
| 205 | if (!rate) rate = 1; |
| 206 | when.s.LowPart = when.s.HighPart = 0; |
| 207 | if (!SetWaitableTimer( handle, &when, rate, NULL, NULL, FALSE )) |
| 208 | { |
| 209 | CloseHandle( handle ); |
| 210 | return INVALID_HANDLE_VALUE; |
| 211 | } |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 212 | |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 213 | if ((ret = SERVICE_AddObject( handle, callback, callback_arg )) == INVALID_HANDLE_VALUE) |
| 214 | { |
| 215 | CloseHandle( handle ); |
| 216 | return INVALID_HANDLE_VALUE; |
| 217 | } |
| 218 | return ret; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /*********************************************************************** |
| 222 | * SERVICE_Delete |
| 223 | */ |
| 224 | BOOL SERVICE_Delete( HANDLE service ) |
| 225 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 226 | HANDLE handle = INVALID_HANDLE_VALUE; |
| 227 | BOOL retv = FALSE; |
| 228 | SERVICE **s, *next; |
| 229 | SERVICETABLE *service_table; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 230 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 231 | /* service table must have been created on previous SERVICE_Add??? call */ |
| 232 | if ((service_table = PROCESS_Current()->service_table) == 0) |
| 233 | return retv; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 234 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 235 | HeapLock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 236 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 237 | for ( s = &service_table->first; *s; s = &(*s)->next ) |
| 238 | { |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 239 | if ( (*s)->self == service ) |
| 240 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 241 | handle = (*s)->object; |
Ulrich Weigand | 70b2e38 | 1999-05-04 16:43:38 +0000 | [diff] [blame] | 242 | next = (*s)->next; |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 243 | HeapFree( GetProcessHeap(), 0, *s ); |
Ulrich Weigand | 70b2e38 | 1999-05-04 16:43:38 +0000 | [diff] [blame] | 244 | *s = next; |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 245 | retv = TRUE; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 246 | break; |
| 247 | } |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 248 | } |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 249 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 250 | HeapUnlock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 251 | |
Ulrich Weigand | 70b2e38 | 1999-05-04 16:43:38 +0000 | [diff] [blame] | 252 | if ( handle != INVALID_HANDLE_VALUE ) |
| 253 | CloseHandle( handle ); |
| 254 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 255 | QueueUserAPC( NULL, service_table->thread, 0L ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 256 | |
| 257 | return retv; |
| 258 | } |
| 259 | |
| 260 | /*********************************************************************** |
| 261 | * SERVICE_Enable |
| 262 | */ |
| 263 | BOOL SERVICE_Enable( HANDLE service ) |
| 264 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 265 | BOOL retv = FALSE; |
| 266 | SERVICE *s; |
| 267 | SERVICETABLE *service_table; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 268 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 269 | /* service table must have been created on previous SERVICE_Add??? call */ |
| 270 | if ((service_table = PROCESS_Current()->service_table) == 0) |
| 271 | return retv; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 272 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 273 | HeapLock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 274 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 275 | for ( s = service_table->first; s; s = s->next ) |
| 276 | { |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 277 | if ( s->self == service ) |
| 278 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 279 | s->disabled = FALSE; |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 280 | retv = TRUE; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 281 | break; |
| 282 | } |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 283 | } |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 284 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 285 | HeapUnlock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 286 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 287 | QueueUserAPC( NULL, service_table->thread, 0L ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 288 | |
| 289 | return retv; |
| 290 | } |
| 291 | |
| 292 | /*********************************************************************** |
| 293 | * SERVICE_Disable |
| 294 | */ |
| 295 | BOOL SERVICE_Disable( HANDLE service ) |
| 296 | { |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 297 | BOOL retv = TRUE; |
| 298 | SERVICE *s; |
| 299 | SERVICETABLE *service_table; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 300 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 301 | /* service table must have been created on previous SERVICE_Add??? call */ |
| 302 | if ((service_table = PROCESS_Current()->service_table) == 0) |
| 303 | return retv; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 304 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 305 | HeapLock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 306 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 307 | for ( s = service_table->first; s; s = s->next ) |
| 308 | { |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 309 | if ( s->self == service ) |
| 310 | { |
Alexandre Julliard | 000c980 | 1999-12-13 01:42:03 +0000 | [diff] [blame^] | 311 | s->disabled = TRUE; |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 312 | retv = TRUE; |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 313 | break; |
| 314 | } |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 315 | } |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 316 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 317 | HeapUnlock( GetProcessHeap() ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 318 | |
Eric Pouech | 63c7cdf | 1999-06-12 08:24:23 +0000 | [diff] [blame] | 319 | QueueUserAPC( NULL, service_table->thread, 0L ); |
Ulrich Weigand | 7761cbe | 1999-04-11 15:01:20 +0000 | [diff] [blame] | 320 | |
| 321 | return retv; |
| 322 | } |
| 323 | |
| 324 | |