1 /**************************************************************************/
2 /*                                                                        */
3 /*                                 OCaml                                  */
4 /*                                                                        */
5 /*   Contributed by Sylvain Le Gall for Lexifi                            */
6 /*                                                                        */
7 /*   Copyright 2008 Institut National de Recherche en Informatique et     */
8 /*     en Automatique.                                                    */
9 /*                                                                        */
10 /*   All rights reserved.  This file is distributed under the terms of    */
11 /*   the GNU Lesser General Public License version 2.1, with the          */
12 /*   special exception on linking described in the file LICENSE.          */
13 /*                                                                        */
14 /**************************************************************************/
15 
16 #ifndef _WINWORKER_H
17 #define _WINWORKER_H
18 
19 #undef _WIN32_WINNT
20 #define _WIN32_WINNT 0x0400
21 #include "unixsupport.h"
22 #include <windows.h>
23 
24 /* Pool of worker threads.
25  *
26  * These functions help to manage a pool of worker thread and submit task to
27  * the pool. It helps to reduce the number of thread creation.
28  *
29  * Each worker are started in alertable wait state and jobs are submitted as
30  * APC (asynchronous procedure call).
31  */
32 
33 /* Data associated with submitted job */
34 typedef struct _WORKER WORKER;
35 typedef WORKER *LPWORKER;
36 
37 /* Function type of submitted job:
38  * void worker_call (HANDLE hStop, void *data)
39  *
40  * This function will be called using the data following:
41  * - hStop must be watched for change, since it represents an external command
42  *   to stop the call. This event is shared through the WORKER structure, which
43  *   can be access throuhg worker_job_event_done.
44  * - data is user provided data for the function.
45  */
46 typedef void (*WORKERFUNC) (HANDLE, void *);
47 
48 /* Initialize global data structure for worker
49  */
50 void worker_init (void);
51 
52 /* Free global data structure for worker
53  */
54 void worker_cleanup (void);
55 
56 /* Submit a job to worker. Use returned data to synchronize with the procedure
57  * submitted.
58  */
59 LPWORKER worker_job_submit (WORKERFUNC f, void *data);
60 
61 /* Get event to know when a job is done.
62  */
63 HANDLE worker_job_event_done (LPWORKER);
64 
65 /* Ask a job to stop processing.
66  */
67 void worker_job_stop (LPWORKER);
68 
69 /* End a job submitted to worker.
70  */
71 void worker_job_finish (LPWORKER);
72 
73 #endif /* _WINWORKER_H */
74