Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / xfa / src / fwl / src / core / fwl_threadimp.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #include "include/fwl_targetimp.h"\r
9 #include "include/fwl_noteimp.h"\r
10 #include "include/fwl_threadimp.h"\r
11 #include "include/fwl_appimp.h"\r
12 CFWL_ControlThread::~CFWL_ControlThread()\r
13 {\r
14 }\r
15 FWL_ERR CFWL_ControlThread::Run(FWL_HTHREAD hThread)\r
16 {\r
17     static int count = 0;\r
18     while (TRUE) {\r
19     }\r
20     return FWL_ERR_Succeeded;\r
21 }\r
22 IFWL_Thread * IFWL_Thread::Create()\r
23 {\r
24     return (IFWL_Thread *) FX_NEW CFWL_Thread;\r
25 }\r
26 CFWL_Thread::CFWL_Thread()\r
27 {\r
28 }\r
29 CFWL_Thread::~CFWL_Thread()\r
30 {\r
31 }\r
32 FWL_ERR CFWL_Thread::Run(FWL_HTHREAD hThread)\r
33 {\r
34     return FWL_ERR_Succeeded;\r
35 }\r
36 CFWL_ControlThread *    CFWL_NoteThread::_assistantThreadHandler        = NULL;\r
37 FWL_HTHREAD                             CFWL_NoteThread::_assistantThread                       = NULL;\r
38 int32_t                         CFWL_NoteThread::_refCount                                      = 0;\r
39 IFWL_NoteThread* IFWL_NoteThread::Create()\r
40 {\r
41     return (IFWL_NoteThread*) FX_NEW CFWL_NoteThread;\r
42 }\r
43 CFWL_NoteThread::CFWL_NoteThread()\r
44     : m_hThread(NULL)\r
45 {\r
46     m_pNoteDriver = FX_NEW CFWL_NoteDriver;\r
47 }\r
48 CFWL_NoteThread::~CFWL_NoteThread()\r
49 {\r
50     if (m_hThread) {\r
51         FWL_StopThread(m_hThread, 0);\r
52     }\r
53     if (m_pNoteDriver) {\r
54         delete m_pNoteDriver;\r
55         m_pNoteDriver = NULL;\r
56     }\r
57 }\r
58 FWL_ERR CFWL_NoteThread::Run(FWL_HTHREAD hThread)\r
59 {\r
60     _FWL_RETURN_VALUE_IF_FAIL(m_pNoteDriver, FWL_ERR_Indefinite);\r
61     FWL_ERR result = m_pNoteDriver->Run();\r
62     return result;\r
63 }\r
64 IFWL_NoteDriver* CFWL_NoteThread::GetNoteDriver()\r
65 {\r
66     return (IFWL_NoteDriver*)m_pNoteDriver;\r
67 }\r
68 extern IFWL_AdapterNative* FWL_GetAdapterNative();\r
69 FWL_HTHREAD FWL_StartThread(IFWL_Thread *pThread, FX_BOOL bSuspended )\r
70 {\r
71     IFWL_AdapterNative *pNative = FWL_GetAdapterNative();\r
72     _FWL_RETURN_VALUE_IF_FAIL(pNative, NULL);\r
73     IFWL_AdapterThreadMgr *pThreadMgr = pNative->GetThreadMgr();\r
74     _FWL_RETURN_VALUE_IF_FAIL(pThreadMgr, NULL);\r
75     FWL_HTHREAD hThread = NULL;\r
76     pThreadMgr->Start(pThread, hThread, bSuspended);\r
77     return hThread;\r
78 }\r
79 FWL_ERR FWL_ResumeThread(FWL_HTHREAD hThread)\r
80 {\r
81     IFWL_AdapterNative * Native = FWL_GetAdapterNative();\r
82     _FWL_RETURN_VALUE_IF_FAIL(Native, FWL_ERR_Indefinite);\r
83     IFWL_AdapterThreadMgr * ThreadMgr = Native->GetThreadMgr();\r
84     _FWL_RETURN_VALUE_IF_FAIL(ThreadMgr, FWL_ERR_Indefinite);\r
85     return ThreadMgr->Resume(hThread);\r
86 }\r
87 FWL_ERR FWL_SuspendThread(FWL_HTHREAD hThread)\r
88 {\r
89     IFWL_AdapterNative * Native = FWL_GetAdapterNative();\r
90     _FWL_RETURN_VALUE_IF_FAIL(Native, FWL_ERR_Indefinite);\r
91     IFWL_AdapterThreadMgr * ThreadMgr = Native->GetThreadMgr();\r
92     _FWL_RETURN_VALUE_IF_FAIL(ThreadMgr, FWL_ERR_Indefinite);\r
93     return ThreadMgr->Suspend(hThread);\r
94 }\r
95 FWL_ERR FWL_KillThread(FWL_HTHREAD hThread, int32_t iExitCode)\r
96 {\r
97     IFWL_AdapterNative * Native = FWL_GetAdapterNative();\r
98     _FWL_RETURN_VALUE_IF_FAIL(Native, FWL_ERR_Indefinite);\r
99     IFWL_AdapterThreadMgr * ThreadMgr = Native->GetThreadMgr();\r
100     _FWL_RETURN_VALUE_IF_FAIL(ThreadMgr, FWL_ERR_Indefinite);\r
101     return ThreadMgr->Kill(hThread, iExitCode);\r
102 }\r
103 FWL_ERR FWL_StopThread(FWL_HTHREAD hThread, int32_t iExitCode)\r
104 {\r
105     IFWL_AdapterNative * Native = FWL_GetAdapterNative();\r
106     _FWL_RETURN_VALUE_IF_FAIL(Native, FWL_ERR_Indefinite);\r
107     IFWL_AdapterThreadMgr * ThreadMgr = Native->GetThreadMgr();\r
108     _FWL_RETURN_VALUE_IF_FAIL(ThreadMgr, FWL_ERR_Indefinite);\r
109     return ThreadMgr->Stop(hThread, iExitCode);\r
110 }\r
111 FWL_HMUTEX FWL_CreateMutex()\r
112 {\r
113     return NULL;\r
114 }\r
115 FWL_ERR FWL_DestroyMutex(FWL_HMUTEX hMutex)\r
116 {\r
117     return FWL_ERR_Succeeded;\r
118 }\r
119 FWL_ERR FWL_LockMutex(FWL_HMUTEX hMutex)\r
120 {\r
121     return FWL_ERR_Succeeded;\r
122 }\r
123 FWL_ERR FWL_TryLockMutex(FWL_HMUTEX hMutex)\r
124 {\r
125     return FWL_ERR_Succeeded;\r
126 }\r
127 FWL_ERR FWL_UnlockMutex(FWL_HMUTEX hMutex)\r
128 {\r
129     return FWL_ERR_Succeeded;\r
130 }\r
131 FWL_ERR FWL_IsLockedMutex(FWL_HMUTEX hMutex, FX_BOOL &bLocked)\r
132 {\r
133     return FWL_ERR_Succeeded;\r
134 }\r
135 FWL_HSEMAPHORE FWL_CreateSemaphore()\r
136 {\r
137     return (FWL_HSEMAPHORE) IFWL_AdapterSemaphore::Create();\r
138 }\r
139 FWL_ERR FWL_DestroySemaphore(FWL_HSEMAPHORE hSemaphore)\r
140 {\r
141     return ((IFWL_AdapterSemaphore*)hSemaphore)->Destroy();\r
142 }\r
143 FWL_ERR FWL_WaitSemaphore(FWL_HSEMAPHORE hSemaphore)\r
144 {\r
145     return ((IFWL_AdapterSemaphore*)hSemaphore)->Wait();\r
146 }\r
147 FWL_ERR FWL_PostSemaphore(FWL_HSEMAPHORE hSemaphore, int32_t down )\r
148 {\r
149     return ((IFWL_AdapterSemaphore*)hSemaphore)->Post();\r
150 }\r
151 FWL_ERR FWL_GetSemaphoreValue(FWL_HSEMAPHORE hSemaphore, int32_t &value)\r
152 {\r
153     return ((IFWL_AdapterSemaphore*)hSemaphore)->Value((FX_DWORD &)value);\r
154 }\r
155 FWL_ERR FWL_ResetSemaphore(FWL_HSEMAPHORE hSemaphore, int32_t init)\r
156 {\r
157     return ((IFWL_AdapterSemaphore*)hSemaphore)->Reset(init);\r
158 }\r