update for ReactOS HEAD-2003091401
[captive.git] / src / libcaptive / ex / work.c
1 /* $Id$
2  * reactos WORK_QUEUE_ITEM handling by libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "reactos/ddk/exfuncs.h"        /* self */
23 #include <glib/gmessages.h>
24 #include "reactos/ddk/extypes.h"        /* for WORK_QUEUE_ITEM */
25 #include <glib/gmain.h>
26 #include "captive/macros.h"
27
28
29 static gboolean ExQueueWorkItem_idlefunc(WORK_QUEUE_ITEM *WorkItem_copy /* data */)
30 {
31         g_return_val_if_fail(WorkItem_copy!=NULL,FALSE);        /* false=>remove-me */
32         g_return_val_if_fail(WorkItem_copy->WorkerRoutine!=NULL,FALSE); /* false=>remove-me */
33
34         /* typedef VOID STDCALL_FUNC (*PWORKER_THREAD_ROUTINE)(PVOID Parameter); */
35
36         (*WorkItem_copy->WorkerRoutine)(WorkItem_copy->Parameter);
37         g_free(WorkItem_copy);
38
39         return FALSE;   /* remove-me */
40 }
41
42 /**
43  * ExQueueWorkItem:
44  * @WorkItem: Initialized structure of #WORK_QUEUE_ITEM to enqueue.
45  * %NULL value is forbidden.
46  * @QueueType: Queue priority.
47  *
48  * Inserts a work item in a queue for one of the system worker threads to
49  * process. It will be processed through g_idle_add_full() with priority
50  * range %G_PRIORITY_DEFAULT+10 ... %G_PRIORITY_DEFAULT+30.
51  *
52  * @WorkItem memory address space can be freed even before its function invocation
53  * (required by ntfs.sys).
54  */
55 VOID ExQueueWorkItem(PWORK_QUEUE_ITEM WorkItem,WORK_QUEUE_TYPE QueueType)
56 {
57 gint priority;
58 WORK_QUEUE_ITEM *WorkItem_copy;
59
60         g_return_if_fail(WorkItem!=NULL);
61         g_return_if_fail(WorkItem->WorkerRoutine!=NULL);
62
63         switch (QueueType) {
64                 case DelayedWorkQueue:
65                         priority=G_PRIORITY_DEFAULT+30; /* positive towards G_PRIORITY_HIGH_IDLE */
66                         break;
67                 case CriticalWorkQueue:
68                         priority=G_PRIORITY_DEFAULT+20; /* positive towards G_PRIORITY_HIGH_IDLE */
69                         break;
70                 case HyperCriticalWorkQueue:
71                         priority=G_PRIORITY_DEFAULT+10; /* positive towards G_PRIORITY_HIGH_IDLE */
72                         break;
73                 default:
74                         g_assert_not_reached();
75                         priority=G_PRIORITY_DEFAULT;
76                 }
77
78         captive_memdup(WorkItem_copy,WorkItem);
79         g_idle_add_full(
80                         priority,       /* priority */
81                         (GSourceFunc)ExQueueWorkItem_idlefunc,  /* function */
82                         WorkItem_copy,  /* data */
83                         NULL);  /* notify */
84 }