summaryrefslogtreecommitdiff
path: root/otherlibs/unix/winworker.h
blob: cfaf81fa728b9d4263979f222a71762e986dd01d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**************************************************************************/
/*                                                                        */
/*                                 OCaml                                  */
/*                                                                        */
/*   Contributed by Sylvain Le Gall for Lexifi                            */
/*                                                                        */
/*   Copyright 2008 Institut National de Recherche en Informatique et     */
/*     en Automatique.                                                    */
/*                                                                        */
/*   All rights reserved.  This file is distributed under the terms of    */
/*   the GNU Lesser General Public License version 2.1, with the          */
/*   special exception on linking described in the file LICENSE.          */
/*                                                                        */
/**************************************************************************/

#ifndef _WINWORKER_H
#define _WINWORKER_H

#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#include "unixsupport.h"
#include <windows.h>

/* Pool of worker threads.
 *
 * These functions help to manage a pool of worker threads and submit task to
 * the pool. It helps to reduce the number of thread creation.
 *
 * Each worker are started in alertable wait state and jobs are submitted as
 * APC (asynchronous procedure call).
 */

/* Data associated with submitted job */
typedef struct _WORKER WORKER;
typedef WORKER *LPWORKER;

/* Function type of submitted job:
 * void worker_call (HANDLE hStop, void *data)
 *
 * This function will be called using the data following:
 * - hStop must be watched for change, since it represents an external command
 *   to stop the call. This event is shared through the WORKER structure, which
 *   can be accessed through caml_win32_worker_job_event_done.
 * - data is user provided data for the function.
 */
typedef void (*WORKERFUNC) (HANDLE, void *);

/* Initialize global data structure for worker
 */
void caml_win32_worker_init (void);

/* Free global data structure for worker
 */
void caml_win32_worker_cleanup (void);

/* Submit a job to worker. Use returned data to synchronize with the procedure
 * submitted.
 */
LPWORKER caml_win32_worker_job_submit (WORKERFUNC f, void *data);

/* Get event to know when a job is done.
 */
HANDLE caml_win32_worker_job_event_done (LPWORKER);

/* Ask a job to stop processing.
 */
void caml_win32_worker_job_stop (LPWORKER);

/* End a job submitted to worker.
 */
void caml_win32_worker_job_finish (LPWORKER);

#endif /* _WINWORKER_H */