repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / expander / GenericThread.h
blobe3bd9b0025e7c0c971748edc178d4f67f6e2456f
1 // license: public domain
2 // authors: jonas.sundstrom@kirilla.com
3 #ifndef _GENERIC_THREAD_H
4 #define _GENERIC_THREAD_H
7 #include <OS.h>
8 #include <Message.h>
11 class GenericThread {
12 public:
13 GenericThread(
14 const char* threadName = "generic_thread",
15 int32 priority = B_NORMAL_PRIORITY,
16 BMessage* message = NULL);
17 virtual ~GenericThread(void);
19 BMessage* GetDataStore(void);
20 void SetDataStore(BMessage* message);
22 status_t Start(void);
23 status_t Pause(bool shouldBlock = true,
24 bigtime_t timeout = 0);
25 void Quit(void);
26 bool IsPaused(void);
27 bool HasQuitBeenRequested(void);
29 status_t Suspend(void);
30 status_t Resume(void);
31 status_t Kill(void);
33 void ExitWithReturnValue(status_t returnValue);
34 status_t SetExitCallback(void (*callback)(void*),
35 void* data);
36 status_t WaitForThread(status_t* exitValue);
38 status_t Rename(char* name);
40 status_t SendData(int32 code, void* buffer,
41 size_t size);
42 int32 ReceiveData(thread_id* sender, void* buffer,
43 size_t size);
44 bool HasData(void);
46 status_t SetPriority(int32 priority);
48 void Snooze(bigtime_t delay);
49 void SnoozeUntil(bigtime_t delay,
50 int timeBase = B_SYSTEM_TIMEBASE);
52 status_t GetInfo(thread_info* info);
53 thread_id GetThread(void);
54 team_id GetTeam(void);
55 char* GetName(void);
56 thread_state GetState(void);
57 sem_id GetSemaphore(void);
58 int32 GetPriority(void);
59 bigtime_t GetUserTime(void);
60 bigtime_t GetKernelTime(void);
61 void* GetStackBase(void);
62 void* GetStackEnd(void);
64 protected:
65 virtual status_t ThreadFunction(void);
66 virtual status_t ThreadStartup(void);
67 virtual status_t ExecuteUnit(void);
68 virtual status_t ThreadShutdown(void);
70 virtual void ThreadStartupFailed(status_t status);
71 virtual void ExecuteUnitFailed(status_t status);
72 virtual void ThreadShutdownFailed(status_t status);
74 void BeginUnit(void);
75 // acquire m_execute_cycle
76 void EndUnit(void);
77 // release m_execute_cycle
79 BMessage* fThreadDataStore;
81 private:
82 static status_t private_thread_function(void* pointer);
84 thread_id fThreadId;
86 sem_id fExecuteUnit;
87 // acquire/relase within tread_function...
88 // for Pause()
90 bool fQuitRequested;
91 bool fThreadIsPaused;
95 #endif // _GENERIC_THREAD_H