+libcaptive/ex/work.c
[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
27
28 static gboolean ExQueueWorkItem_idlefunc(WORK_QUEUE_ITEM *WorkItem /* data */)
29 {
30         g_return_val_if_fail(WorkItem!=NULL,FALSE);     /* false=>remove-me */
31         g_return_val_if_fail(WorkItem->Routine!=NULL,FALSE);    /* false=>remove-me */
32
33         /* typedef VOID STDCALL_FUNC (*PWORKER_THREAD_ROUTINE)(PVOID Parameter); */
34
35         (*WorkItem->Routine)(WorkItem->Context);
36         WorkItem->Routine=NULL; /* request is no longer pending */
37         return FALSE;   /* remove-me */
38 }
39
40 /**
41  * ExQueueWorkItem:
42  * @WorkItem: Initialized structure of #WORK_QUEUE_ITEM to be initialize.
43  * %NULL value is forbidden.
44  * @QueueType: Queue priority.
45  *
46  * Inserts a work item in a queue for one of the system worker threads to
47  * process. It will be processed through g_idle_add_full() with priority
48  * range %G_PRIORITY_DEFAULT+10 ... %G_PRIORITY_DEFAULT+30.
49  *
50  * FIXME: @WorkItem is required by libcaptive to remain valid until invocation.
51  * Is it legal?
52  */
53 VOID ExQueueWorkItem(PWORK_QUEUE_ITEM WorkItem,WORK_QUEUE_TYPE QueueType)
54 {
55 gint priority;
56
57         g_return_if_fail(WorkItem!=NULL);
58         g_return_if_fail(WorkItem->Routine!=NULL);
59
60         switch (QueueType) {
61                 case DelayedWorkQueue:
62                         priority=G_PRIORITY_DEFAULT+30; /* positive towards G_PRIORITY_HIGH_IDLE */
63                         break;
64                 case CriticalWorkQueue:
65                         priority=G_PRIORITY_DEFAULT+20; /* positive towards G_PRIORITY_HIGH_IDLE */
66                         break;
67                 case HyperCriticalWorkQueue:
68                         priority=G_PRIORITY_DEFAULT+10; /* positive towards G_PRIORITY_HIGH_IDLE */
69                         break;
70                 default:
71                         g_assert_not_reached();
72                         priority=G_PRIORITY_DEFAULT;
73                 }
74
75         g_idle_add_full(
76                         priority,       /* priority */
77                         (GSourceFunc)ExQueueWorkItem_idlefunc,  /* function */
78                         WorkItem,       /* data */
79                         NULL);  /* notify */
80 }