1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "cr_mem.h"
|
---|
8 | #include "cr_spu.h"
|
---|
9 | #include "cr_glstate.h"
|
---|
10 | #include "packspu.h"
|
---|
11 | #include "cr_packfunctions.h"
|
---|
12 | #include <stdio.h>
|
---|
13 |
|
---|
14 | extern SPUNamedFunctionTable _cr_pack_table[];
|
---|
15 |
|
---|
16 | SPUFunctions pack_functions = {
|
---|
17 | NULL, /* CHILD COPY */
|
---|
18 | NULL, /* DATA */
|
---|
19 | _cr_pack_table /* THE ACTUAL FUNCTIONS */
|
---|
20 | };
|
---|
21 |
|
---|
22 | PackSPU pack_spu;
|
---|
23 |
|
---|
24 | #ifdef CHROMIUM_THREADSAFE
|
---|
25 | CRtsd _PackTSD;
|
---|
26 | CRmutex _PackMutex;
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | static SPUFunctions *
|
---|
30 | packSPUInit( int id, SPU *child, SPU *self,
|
---|
31 | unsigned int context_id,
|
---|
32 | unsigned int num_contexts )
|
---|
33 | {
|
---|
34 | ThreadInfo *thread;
|
---|
35 |
|
---|
36 | (void) context_id;
|
---|
37 | (void) num_contexts;
|
---|
38 | (void) child;
|
---|
39 | (void) self;
|
---|
40 |
|
---|
41 | #ifdef CHROMIUM_THREADSAFE
|
---|
42 | crInitMutex(&_PackMutex);
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | pack_spu.id = id;
|
---|
46 |
|
---|
47 | packspuSetVBoxConfiguration( child );
|
---|
48 |
|
---|
49 | /* This connects to the server, sets up the packer, etc. */
|
---|
50 | thread = packspuNewThread( crThreadID() );
|
---|
51 |
|
---|
52 | if (!thread) {
|
---|
53 | return NULL;
|
---|
54 | }
|
---|
55 | CRASSERT( thread == &(pack_spu.thread[0]) );
|
---|
56 |
|
---|
57 | packspuCreateFunctions();
|
---|
58 | crStateInit();
|
---|
59 |
|
---|
60 | return &pack_functions;
|
---|
61 | }
|
---|
62 |
|
---|
63 | static void
|
---|
64 | packSPUSelfDispatch(SPUDispatchTable *self)
|
---|
65 | {
|
---|
66 | (void)self;
|
---|
67 | }
|
---|
68 |
|
---|
69 | static int
|
---|
70 | packSPUCleanup(void)
|
---|
71 | {
|
---|
72 | int i;
|
---|
73 | #ifdef CHROMIUM_THREADSAFE
|
---|
74 | crLockMutex(&_PackMutex);
|
---|
75 | #endif
|
---|
76 | for (i=0; i<pack_spu.numThreads; ++i)
|
---|
77 | {
|
---|
78 | if (pack_spu.thread[i].packer)
|
---|
79 | {
|
---|
80 | crPackDeleteContext(pack_spu.thread[i].packer);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | crFreeTSD(&_PackerTSD);
|
---|
85 | crFreeTSD(&_PackTSD);
|
---|
86 |
|
---|
87 | #ifdef CHROMIUM_THREADSAFE
|
---|
88 | crUnlockMutex(&_PackMutex);
|
---|
89 | crFreeMutex(&_PackMutex);
|
---|
90 | #endif
|
---|
91 | return 1;
|
---|
92 | }
|
---|
93 |
|
---|
94 | extern SPUOptions packSPUOptions[];
|
---|
95 |
|
---|
96 | int SPULoad( char **name, char **super, SPUInitFuncPtr *init,
|
---|
97 | SPUSelfDispatchFuncPtr *self, SPUCleanupFuncPtr *cleanup,
|
---|
98 | SPUOptionsPtr *options, int *flags )
|
---|
99 | {
|
---|
100 | *name = "pack";
|
---|
101 | *super = NULL;
|
---|
102 | *init = packSPUInit;
|
---|
103 | *self = packSPUSelfDispatch;
|
---|
104 | *cleanup = packSPUCleanup;
|
---|
105 | *options = packSPUOptions;
|
---|
106 | *flags = (SPU_HAS_PACKER|SPU_IS_TERMINAL|SPU_MAX_SERVERS_ONE);
|
---|
107 |
|
---|
108 | return 1;
|
---|
109 | }
|
---|