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 | #if defined(CHROMIUM_THREADSAFE) && !defined(WINDOWS)
|
---|
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 | pack_spu.idxThreadInUse = 0;
|
---|
57 |
|
---|
58 | packspuCreateFunctions();
|
---|
59 | crStateInit();
|
---|
60 |
|
---|
61 | return &pack_functions;
|
---|
62 | }
|
---|
63 |
|
---|
64 | static void
|
---|
65 | packSPUSelfDispatch(SPUDispatchTable *self)
|
---|
66 | {
|
---|
67 | (void)self;
|
---|
68 | }
|
---|
69 |
|
---|
70 | static int
|
---|
71 | packSPUCleanup(void)
|
---|
72 | {
|
---|
73 | int i;
|
---|
74 | #ifdef CHROMIUM_THREADSAFE
|
---|
75 | crLockMutex(&_PackMutex);
|
---|
76 | #endif
|
---|
77 | for (i=0; i<MAX_THREADS; ++i)
|
---|
78 | {
|
---|
79 | if (pack_spu.thread[i].inUse && pack_spu.thread[i].packer)
|
---|
80 | {
|
---|
81 | crPackDeleteContext(pack_spu.thread[i].packer);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | crFreeTSD(&_PackerTSD);
|
---|
86 | crFreeTSD(&_PackTSD);
|
---|
87 |
|
---|
88 | #ifdef CHROMIUM_THREADSAFE
|
---|
89 | crUnlockMutex(&_PackMutex);
|
---|
90 | # ifndef WINDOWS
|
---|
91 | crFreeMutex(&_PackMutex);
|
---|
92 | # endif
|
---|
93 | #endif
|
---|
94 | return 1;
|
---|
95 | }
|
---|
96 |
|
---|
97 | extern SPUOptions packSPUOptions[];
|
---|
98 |
|
---|
99 | int SPULoad( char **name, char **super, SPUInitFuncPtr *init,
|
---|
100 | SPUSelfDispatchFuncPtr *self, SPUCleanupFuncPtr *cleanup,
|
---|
101 | SPUOptionsPtr *options, int *flags )
|
---|
102 | {
|
---|
103 | *name = "pack";
|
---|
104 | *super = NULL;
|
---|
105 | *init = packSPUInit;
|
---|
106 | *self = packSPUSelfDispatch;
|
---|
107 | *cleanup = packSPUCleanup;
|
---|
108 | *options = packSPUOptions;
|
---|
109 | *flags = (SPU_HAS_PACKER|SPU_IS_TERMINAL|SPU_MAX_SERVERS_ONE);
|
---|
110 |
|
---|
111 | return 1;
|
---|
112 | }
|
---|