comparison TaskManager/Cell/SpeThreads.cc @ 65:519d24aa7ac8

*** empty log message ***
author gongo
date Sun, 17 Feb 2008 18:06:53 +0900
parents
children 1034077dd217
comparison
equal deleted inserted replaced
64:eb2cb212881c 65:519d24aa7ac8
1 #include "SpeThreads.h"
2
3 SpeThreads::SpeThreads(int num) : spe_num(num) {}
4
5 void*
6 SpeThreads::spe_thread_run(void *arg)
7 {
8 unsigned int entry = SPE_DEFAULT_ENTRY;
9 spe_context_ptr_t ctx = (spe_context_ptr_t)arg;
10
11 spe_context_run(ctx, &entry, 0, NULL, NULL, NULL);
12
13 pthread_exit(NULL);
14 }
15
16 void*
17 SpeThreads::frontend_thread_run(void *arg)
18 {
19 pthread_t thread;
20 thread_arg_t *arg_t = (thread_arg_t *)arg;
21
22 pthread_create(&thread, NULL, &spe_thread_run, (void*)arg_t->ctx);
23
24 pthread_exit(NULL);
25 }
26
27 void
28 SpeThreads::init(void)
29 {
30 int i;
31
32 spe_handle = spe_image_open(SPE_ELF);
33
34 spe_ctx = new spe_context_ptr_t[spe_num];
35 threads = new pthread_t[spe_num];
36 args = new thread_arg_t[spe_num];
37
38 for (i = 0; i < spe_num; i++) {
39 args[i].speid = i;
40 spe_ctx[i] = spe_context_create(0, NULL);
41 spe_program_load(spe_ctx[i], spe_handle);
42 args[i].ctx = spe_ctx[i];
43 }
44
45 for (i = 0; i < spe_num; i++) {
46 pthread_create(&threads[i], NULL,
47 &frontend_thread_run, (void*)&args[i]);
48 }
49 }
50
51 int
52 SpeThreads::get_mail(int speid)
53 {
54 unsigned int ret;
55
56 if (spe_out_mbox_read(spe_ctx[speid], &ret, 1) > 0) {
57 return (int)ret;
58 } else {
59 return -1;
60 }
61 }