| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef _FWL_THREAD_H | 7 #ifndef FWL_THREAD_H_ |
| 8 #define _FWL_THREAD_H | 8 #define FWL_THREAD_H_ |
| 9 |
| 10 // The FWL thread/app code contains three parallel inheritance hierarchies, |
| 11 // which |
| 12 // reference each other via pointers as follows: |
| 13 // |
| 14 // m_pImpl |
| 15 // (nonesuch) IFWL_Thread ----------> CFWL_ThreadImp |
| 16 // | <---------- | |
| 17 // A m_pIface A |
| 18 // | | |
| 19 // (nonesuch) IFWL_NoteThread CFWL_NoteThreadImp |
| 20 // | | |
| 21 // A A |
| 22 // m_pIface | | |
| 23 // CFWL_App --------------> IFWL_App CFWL_AppImp |
| 24 // |
| 25 |
| 26 class CFWL_ThreadImp; |
| 9 class IFWL_NoteDriver; | 27 class IFWL_NoteDriver; |
| 10 class IFWL_Thread; | 28 |
| 11 class IFWL_NoteThread; | |
| 12 typedef struct _FWL_HTHREAD { void* pData; } * FWL_HTHREAD; | 29 typedef struct _FWL_HTHREAD { void* pData; } * FWL_HTHREAD; |
| 30 |
| 13 class IFWL_Thread { | 31 class IFWL_Thread { |
| 14 public: | 32 public: |
| 15 static IFWL_Thread* Create(); | 33 // These call into polymorphic methods in the impl; no need to override. |
| 34 void Release(); |
| 35 FWL_ERR Run(FWL_HTHREAD hThread); |
| 36 |
| 37 CFWL_ThreadImp* GetImpl() const { return m_pImpl; } |
| 38 void SetImpl(CFWL_ThreadImp* pImpl) { m_pImpl = pImpl; } |
| 16 | 39 |
| 17 protected: | 40 protected: |
| 18 virtual ~IFWL_Thread() {} | 41 virtual ~IFWL_Thread() {} |
| 19 | 42 |
| 20 public: | 43 private: |
| 21 virtual void Release() = 0; | 44 CFWL_ThreadImp* m_pImpl; |
| 22 virtual FWL_ERR Run(FWL_HTHREAD hThread) = 0; | |
| 23 }; | 45 }; |
| 24 FWL_HTHREAD FWL_StartThread(IFWL_Thread* pThread, FX_BOOL bSuspended = FALSE); | 46 |
| 25 FWL_ERR FWL_ResumeThread(FWL_HTHREAD hThread); | |
| 26 FWL_ERR FWL_SuspendThread(FWL_HTHREAD hThread); | |
| 27 FWL_ERR FWL_KillThread(FWL_HTHREAD hThread, int32_t iExitCode); | |
| 28 FWL_ERR FWL_StopThread(FWL_HTHREAD hThread, int32_t iExitCode); | |
| 29 FWL_ERR FWL_Sleep(FX_DWORD dwMilliseconds); | |
| 30 class IFWL_NoteThread : public IFWL_Thread { | 47 class IFWL_NoteThread : public IFWL_Thread { |
| 31 public: | 48 public: |
| 32 static IFWL_NoteThread* Create(); | 49 IFWL_NoteDriver* GetNoteDriver(); |
| 33 virtual FWL_ERR Run(FWL_HTHREAD hThread) = 0; | |
| 34 virtual IFWL_NoteDriver* GetNoteDriver() = 0; | |
| 35 }; | 50 }; |
| 36 typedef struct _FWL_HMUTEX { void* pData; } * FWL_HMUTEX; | 51 |
| 37 FWL_HMUTEX FWL_CreateMutex(); | 52 #endif // FWL_THREAD_H_ |
| 38 FWL_ERR FWL_DestroyMutex(FWL_HMUTEX hMutex); | |
| 39 FWL_ERR FWL_LockMutex(FWL_HMUTEX hMutex); | |
| 40 FWL_ERR FWL_TryLockMutex(FWL_HMUTEX hMutex); | |
| 41 FWL_ERR FWL_UnlockMutex(FWL_HMUTEX hMutex); | |
| 42 FWL_ERR FWL_IsLockedMutex(FWL_HMUTEX hMutex, FX_BOOL& bLocked); | |
| 43 typedef struct _FWL_HSEMAPHORE { void* pData; } * FWL_HSEMAPHORE; | |
| 44 FWL_HSEMAPHORE FWL_CreateSemaphore(); | |
| 45 FWL_ERR FWL_DestroySemaphore(FWL_HSEMAPHORE hSemaphore); | |
| 46 FWL_ERR FWL_WaitSemaphore(FWL_HSEMAPHORE hSemaphore); | |
| 47 FWL_ERR FWL_PostSemaphore(FWL_HSEMAPHORE hSemaphore, int32_t down = 1); | |
| 48 FWL_ERR FWL_GetSemaphoreValue(FWL_HSEMAPHORE hSemaphore, int32_t& value); | |
| 49 FWL_ERR FWL_ResetSemaphore(FWL_HSEMAPHORE hSemaphore, int32_t init); | |
| 50 #endif | |
| OLD | NEW |