1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 
13 #ifndef CHTHREADSWIN32_H
14 #define CHTHREADSWIN32_H
15 
16 #include <string>
17 
18 #include "chrono/core/ChApiCE.h"
19 #include "chrono/parallel/ChThreadsFunct.h"
20 #include "chrono/collision/bullet/LinearMath/btAlignedObjectArray.h"
21 
22 namespace chrono {
23 
24 typedef unsigned int uint32_t;
25 
26 // typedef void (*Win32ThreadFunc)(void* userPtr,void* lsMemory);
27 // typedef void* (*Win32lsMemorySetupFunc)();
28 
29 struct ChThreadStateWIN32 {
30     uint32_t m_taskId;
31 
32     uint32_t m_commandId;
33     uint32_t m_status;
34 
35     ChThreadFunc m_userThreadFunc;  // user function
36     void* m_userPtr;                // user data
37     void* m_lsMemory;               // initialized using Win32LocalStoreMemorySetupFunc
38 
39     void* m_threadHandle;
40 
41     void* m_eventStartHandle;
42     char m_eventStartHandleName[32];
43 
44     void* m_eventCompletetHandle;
45     char m_eventCompletetHandleName[32];
46 };
47 
48 class ChApi ChThreadsWIN32  // : public ChThreads
49     {
50     btAlignedObjectArray<ChThreadStateWIN32> m_activeSpuStatus;
51     btAlignedObjectArray<void*> m_completeHandles;
52 
53     std::string uniqueName;
54 
55   public:
56     /// Constructor: create and initialize N threads.
57     ChThreadsWIN32(ChThreadConstructionInfo& threadConstructionInfo);
58 
59     /// Destructor: cleanup/shutdown
60     virtual ~ChThreadsWIN32();
61 
62     void makeThreads(ChThreadConstructionInfo& threadInfo);
63 
64     virtual void sendRequest(uint32_t uiCommand, void* uiUserPtr, unsigned int threadId);
65 
66     virtual void waitForResponse(unsigned int* puiArgument0, unsigned int* puiArgument1);
67 
68     virtual void startSPU();
69 
70     virtual void stopSPU();
71 
72     virtual void flush();
73 
getNumberOfThreads()74     virtual int getNumberOfThreads() { return m_activeSpuStatus.size(); }
75 
getUniqueName()76     virtual std::string getUniqueName() { return uniqueName; }
77 };
78 
79 typedef ChThreadsWIN32 ChThreadsPlatformImplementation;
80 
81 }  // end namespace chrono
82 
83 #endif
84