bzr branch
http://darksoft.org/webbzr/ani/mrses
1
by Suren A. Chilingaryan
Initial import |
1 |
#ifndef _HW_SCHED_H
|
2 |
#define _HW_SCHED_H
|
|
3 |
||
4 |
typedef struct HWSchedT *HWSched; |
|
5 |
||
6 |
#include "hw_thread.h" |
|
7 |
||
8 |
enum HWSchedModeT { |
|
9 |
HW_SCHED_MODE_PREALLOCATED = 0, |
|
10 |
HW_SCHED_MODE_SEQUENTIAL
|
|
11 |
};
|
|
12 |
typedef enum HWSchedModeT HWSchedMode; |
|
13 |
||
14 |
||
15 |
#define HW_MAX_THREADS 128
|
|
16 |
||
17 |
#ifndef HW_HIDE_DETAILS
|
|
18 |
#include <pthread.h> |
|
19 |
struct HWSchedT { |
|
20 |
int status; |
|
21 |
int started; |
|
22 |
||
23 |
int n_threads; |
|
24 |
HWThread thread[HW_MAX_THREADS]; |
|
25 |
||
26 |
int sync_init; |
|
27 |
pthread_cond_t job_cond, compl_cond; |
|
28 |
pthread_mutex_t job_cond_mutex, compl_cond_mutex, data_mutex; |
|
29 |
||
30 |
HWSchedMode mode; |
|
31 |
int *n_blocks; |
|
32 |
int *cur_block; |
|
33 |
||
34 |
int entry; |
|
35 |
void *ctx; |
|
36 |
};
|
|
37 |
typedef struct HWSchedT HWSchedS; |
|
38 |
#endif /* HW_HIDE_DETAILS */ |
|
39 |
||
40 |
HWSched hw_sched_create(); |
|
41 |
void hw_sched_destroy(HWSched ctx); |
|
42 |
int hw_sched_set_sequential_mode(HWSched ctx, int *n_blocks, int *cur_block); |
|
43 |
int hw_sched_get_chunk(HWSched ctx, int thread_id); |
|
44 |
int hw_sched_schedule_task(HWSched ctx, void *appctx, int entry); |
|
45 |
int hw_sched_wait_task(HWSched ctx); |
|
46 |
||
47 |
#define hw_sched_lock(ctx, type) pthread_mutex_lock(&ctx->type##_mutex)
|
|
48 |
#define hw_sched_unlock(ctx, type) pthread_mutex_unlock(&ctx->type##_mutex)
|
|
49 |
#define hw_sched_broadcast(ctx, type) pthread_cond_broadcast(&ctx->type##_cond)
|
|
50 |
#define hw_sched_signal(ctx, type) pthread_cond_signal(&ctx->type##_cond)
|
|
51 |
#define hw_sched_wait(ctx, type) pthread_cond_wait(&ctx->type##_cond, &ctx->type##_cond_mutex)
|
|
52 |
||
53 |
#endif /* _HW_SCHED_H */ |
|
54 |