1 
2 #ifndef __SCHRO_ASYNC_H__
3 #define __SCHRO_ASYNC_H__
4 
5 #include <schroedinger/schroutils.h>
6 #include <schroedinger/schrodomain.h>
7 
8 SCHRO_BEGIN_DECLS
9 
10 typedef int SchroExecDomain;
11 
12 typedef struct _SchroAsync SchroAsync;
13 typedef struct _SchroThread SchroThread;
14 typedef struct _SchroAsyncTask SchroAsyncTask;
15 typedef struct _SchroAsyncStage SchroAsyncStage;
16 typedef struct _SchroMutex SchroMutex;
17 
18 #ifdef SCHRO_ENABLE_UNSTABLE_API
19 
20 typedef int (*SchroAsyncScheduleFunc)(void *, SchroExecDomain exec_domain);
21 typedef void (*SchroAsyncCompleteFunc)(void *);
22 typedef void (*SchroAsyncTaskFunc) (void *);
23 
24 struct _SchroAsyncTask {
25   SchroAsyncTaskFunc task_func;
26   void *priv;
27 };
28 
29 struct _SchroAsyncStage {
30   SchroAsyncTaskFunc task_func;
31   void *priv;
32 
33   schro_bool is_ready;
34   schro_bool is_needed; /* FIXME remove eventually */
35   schro_bool is_done;
36   int priority;
37   int n_tasks_started;
38   int n_tasks_completed;
39 
40   int n_tasks;
41   SchroAsyncTaskFunc tasks[10];
42 };
43 
44 void schro_async_init (void);
45 SchroAsync * schro_async_new(int n_threads,
46     SchroAsyncScheduleFunc schedule,
47     SchroAsyncCompleteFunc complete,
48     void *closure);
49 void schro_async_free (SchroAsync *async);
50 
51 /**
52  * schro_async_stop:
53  *
54  * wait for all worker threads belonging to @async to finish their
55  * current task.  no further tasks will be executed until
56  * schro_async_start is called
57  */
58 void schro_async_stop (SchroAsync *async);
59 
60 /**
61  * schro_async_sart:
62  *
63  * Resume execution of scheduler for @async after schro_async_stop
64  * has been called.
65  */
66 void schro_async_start (SchroAsync *async);
67 
68 void schro_async_run_stage_locked (SchroAsync *async, SchroAsyncStage *stage);
69 int schro_async_wait_locked (SchroAsync *async);
70 void schro_async_signal_scheduler (SchroAsync *async);
71 void schro_async_lock (SchroAsync *async);
72 void schro_async_unlock (SchroAsync *async);
73 SchroExecDomain schro_async_get_exec_domain (void);
74 
75 void schro_async_add_exec_domain (SchroAsync *async,
76     SchroExecDomain exec_domain);
77 
78 SchroMutex *schro_mutex_new (void);
79 #if 0
80 SchroMutex *schro_mutex_new_recursive (void);
81 #endif
82 void schro_mutex_lock (SchroMutex *mutex);
83 void schro_mutex_unlock (SchroMutex *mutex);
84 void schro_mutex_free (SchroMutex *mutex);
85 
86 #endif
87 
88 SCHRO_END_DECLS
89 
90 #endif
91 
92