/ani/mrses

To get this branch, use:
bzr branch http://suren.me/webbzr/ani/mrses
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
#ifndef _HW_SCHED_H
#define _HW_SCHED_H

typedef struct HWSchedT *HWSched;

#include "hw_thread.h"

enum HWSchedModeT {
    HW_SCHED_MODE_PREALLOCATED = 0,
    HW_SCHED_MODE_SEQUENTIAL
};
typedef enum HWSchedModeT HWSchedMode;


#define HW_MAX_THREADS 128

#ifndef HW_HIDE_DETAILS
#include <pthread.h>
struct HWSchedT {
    int status;
    int started;
    
    int n_threads;
    HWThread thread[HW_MAX_THREADS];
    
    int sync_init;
    pthread_cond_t job_cond, compl_cond;
    pthread_mutex_t job_cond_mutex, compl_cond_mutex, data_mutex;
    
    HWSchedMode mode;
    int *n_blocks;
    int *cur_block;

    int entry;
    void *ctx;
};
typedef struct HWSchedT HWSchedS;
#endif /* HW_HIDE_DETAILS */

HWSched hw_sched_create();
void hw_sched_destroy(HWSched ctx);
int hw_sched_set_sequential_mode(HWSched ctx, int *n_blocks, int *cur_block);
int hw_sched_get_chunk(HWSched ctx, int thread_id);
int hw_sched_schedule_task(HWSched ctx, void *appctx, int entry);
int hw_sched_wait_task(HWSched ctx);

#define hw_sched_lock(ctx, type) pthread_mutex_lock(&ctx->type##_mutex)
#define hw_sched_unlock(ctx, type) pthread_mutex_unlock(&ctx->type##_mutex)
#define hw_sched_broadcast(ctx, type) pthread_cond_broadcast(&ctx->type##_cond)
#define hw_sched_signal(ctx, type) pthread_cond_signal(&ctx->type##_cond)
#define hw_sched_wait(ctx, type) pthread_cond_wait(&ctx->type##_cond, &ctx->type##_cond_mutex)

#endif /* _HW_SCHED_H */