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
|
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "libspe2.h"
struct thread_args {
struct spe_context * ctx;
void * argp;
void * envp;
};
void * spe_thread(void * arg);
__attribute__((noreturn)) void * spe_thread(void * arg)
{
int flags = 0;
unsigned int entry = SPE_DEFAULT_ENTRY;
int rc;
spe_program_handle_t * program;
struct thread_args * arg_ptr;
arg_ptr = (struct thread_args *) arg;
program = spe_image_open("hello");
if (!program) {
perror("spe_image_open");
pthread_exit(NULL);
}
if (spe_program_load(arg_ptr->ctx, program)) {
perror("spe_program_load");
pthread_exit(NULL);
}
rc = spe_context_run(arg_ptr->ctx, &entry, flags, arg_ptr->argp, arg_ptr->envp, NULL);
if (rc < 0)
perror("spe_context_run");
pthread_exit(NULL);
}
int main() {
int thread_id;
pthread_t pts;
spe_context_ptr_t ctx;
struct thread_args t_args;
int value = 1;
int flags = 0;
if (!(ctx = spe_context_create(flags, NULL))) {
perror("spe_create_context");
return -2;
}
t_args.ctx = ctx;
t_args.argp = &value;
thread_id = pthread_create( &pts, NULL, &spe_thread, &t_args);
pthread_join (pts, NULL);
spe_context_destroy (ctx);
return 0;
}
|