First round of style changes: renamed all member variables from m_var_name to fVarName
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27445 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
fa23653d48
commit
b5d458a508
@ -5,25 +5,27 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
GenericThread::GenericThread(const char * a_thread_name, int32 a_priority, BMessage * a_message)
|
||||
GenericThread::GenericThread(const char * thread_name, int32 a_priority, BMessage * message)
|
||||
:
|
||||
m_thread_data_store(a_message),
|
||||
m_thread_id(spawn_thread(private_thread_function, a_thread_name, a_priority, this)),
|
||||
m_execute_unit(create_sem(1, "m_execute_unit")),
|
||||
m_quit_requested(false),
|
||||
m_thread_is_paused(false)
|
||||
fThreadDataStore(message),
|
||||
fThreadId(spawn_thread(private_thread_function, thread_name, a_priority, this)),
|
||||
fExecuteUnit(create_sem(1, "ExecuteUnit sem")),
|
||||
fQuitRequested(false),
|
||||
fThreadIsPaused(false)
|
||||
{
|
||||
if (m_thread_data_store == NULL)
|
||||
m_thread_data_store = new BMessage();
|
||||
if (fThreadDataStore == NULL)
|
||||
fThreadDataStore = new BMessage();
|
||||
}
|
||||
|
||||
|
||||
GenericThread::~GenericThread()
|
||||
{
|
||||
kill_thread(m_thread_id);
|
||||
kill_thread(fThreadId);
|
||||
|
||||
delete_sem(m_execute_unit);
|
||||
delete_sem(fExecuteUnit);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::ThreadFunction(void)
|
||||
{
|
||||
@ -65,6 +67,7 @@ GenericThread::ThreadFunction(void)
|
||||
return (B_OK);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::ThreadStartup(void)
|
||||
{
|
||||
@ -87,6 +90,7 @@ GenericThread::ExecuteUnit(void)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::ThreadShutdown(void)
|
||||
{
|
||||
@ -96,6 +100,7 @@ GenericThread::ThreadShutdown(void)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::ThreadStartupFailed(status_t a_status)
|
||||
{
|
||||
@ -105,6 +110,7 @@ GenericThread::ThreadStartupFailed(status_t a_status)
|
||||
Quit();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::ExecuteUnitFailed(status_t a_status)
|
||||
{
|
||||
@ -114,6 +120,7 @@ GenericThread::ExecuteUnitFailed(status_t a_status)
|
||||
Quit();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::ThreadShutdownFailed(status_t a_status)
|
||||
{
|
||||
@ -123,6 +130,7 @@ GenericThread::ThreadShutdownFailed(status_t a_status)
|
||||
// (is this good default behaviour?)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::Start(void)
|
||||
{
|
||||
@ -130,18 +138,19 @@ GenericThread::Start(void)
|
||||
|
||||
if (IsPaused())
|
||||
{
|
||||
status = release_sem(m_execute_unit);
|
||||
status = release_sem(fExecuteUnit);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
m_thread_is_paused = false;
|
||||
fThreadIsPaused = false;
|
||||
}
|
||||
|
||||
status = resume_thread(m_thread_id);
|
||||
status = resume_thread(fThreadId);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
GenericThread::private_thread_function(void * a_simple_thread_ptr)
|
||||
{
|
||||
@ -152,126 +161,144 @@ GenericThread::private_thread_function(void * a_simple_thread_ptr)
|
||||
return (status);
|
||||
}
|
||||
|
||||
|
||||
BMessage *
|
||||
GenericThread::GetDataStore(void)
|
||||
{
|
||||
return (m_thread_data_store);
|
||||
return (fThreadDataStore);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::SetDataStore(BMessage * a_message)
|
||||
GenericThread::SetDataStore(BMessage * message)
|
||||
{
|
||||
m_thread_data_store = a_message;
|
||||
fThreadDataStore = message;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::Pause(bool a_do_block, bigtime_t a_timeout)
|
||||
{
|
||||
status_t status = B_OK;
|
||||
|
||||
if (a_do_block)
|
||||
status = acquire_sem(m_execute_unit);
|
||||
status = acquire_sem(fExecuteUnit);
|
||||
// thread will wait on semaphore
|
||||
else
|
||||
status = acquire_sem_etc(m_execute_unit, 1, B_RELATIVE_TIMEOUT, a_timeout);
|
||||
status = acquire_sem_etc(fExecuteUnit, 1, B_RELATIVE_TIMEOUT, a_timeout);
|
||||
// thread will timeout
|
||||
|
||||
if (status == B_OK)
|
||||
{
|
||||
m_thread_is_paused = true;
|
||||
fThreadIsPaused = true;
|
||||
return (B_OK);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::Quit(void)
|
||||
{
|
||||
m_quit_requested = true;
|
||||
fQuitRequested = true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GenericThread::HasQuitBeenRequested(void)
|
||||
{
|
||||
return (m_quit_requested);
|
||||
return (fQuitRequested);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GenericThread::IsPaused(void)
|
||||
{
|
||||
return (m_thread_is_paused);
|
||||
return (fThreadIsPaused);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::Suspend(void)
|
||||
{
|
||||
return (suspend_thread(m_thread_id));
|
||||
return (suspend_thread(fThreadId));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::Resume(void)
|
||||
{
|
||||
release_sem(m_execute_unit); // to counteract Pause()
|
||||
m_thread_is_paused = false;
|
||||
release_sem(fExecuteUnit); // to counteract Pause()
|
||||
fThreadIsPaused = false;
|
||||
|
||||
return (resume_thread(m_thread_id)); // to counteract Suspend()
|
||||
return (resume_thread(fThreadId)); // to counteract Suspend()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::Kill(void)
|
||||
{
|
||||
return (kill_thread(m_thread_id));
|
||||
return (kill_thread(fThreadId));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::ExitWithReturnValue(status_t a_return_value)
|
||||
{
|
||||
exit_thread(a_return_value);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::SetExitCallback(void(*a_callback)(void*), void * a_data)
|
||||
{
|
||||
return (on_exit_thread(a_callback, a_data));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::WaitForThread(status_t * a_exit_value)
|
||||
{
|
||||
return (wait_for_thread(m_thread_id, a_exit_value));
|
||||
return (wait_for_thread(fThreadId, a_exit_value));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::Rename(char * a_name)
|
||||
{
|
||||
return (rename_thread(m_thread_id, a_name));
|
||||
return (rename_thread(fThreadId, a_name));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::SendData(int32 a_code, void * a_buffer, size_t a_buffer_size)
|
||||
{
|
||||
return (send_data(m_thread_id, a_code, a_buffer, a_buffer_size));
|
||||
return (send_data(fThreadId, a_code, a_buffer, a_buffer_size));
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
GenericThread::ReceiveData(thread_id * a_sender, void * a_buffer, size_t a_buffer_size)
|
||||
{
|
||||
return (receive_data(a_sender, a_buffer, a_buffer_size));
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GenericThread::HasData(void)
|
||||
{
|
||||
return (has_data(m_thread_id));
|
||||
return (has_data(fThreadId));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::SetPriority(int32 a_new_priority)
|
||||
{
|
||||
return (set_thread_priority(m_thread_id, a_new_priority));
|
||||
return (set_thread_priority(fThreadId, a_new_priority));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::Snooze(bigtime_t a_microseconds)
|
||||
{
|
||||
@ -280,6 +307,7 @@ GenericThread::Snooze(bigtime_t a_microseconds)
|
||||
Resume();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::SnoozeUntil(bigtime_t a_microseconds, int a_timebase)
|
||||
{
|
||||
@ -288,12 +316,14 @@ GenericThread::SnoozeUntil(bigtime_t a_microseconds, int a_timebase)
|
||||
Resume();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
GenericThread::GetInfo(thread_info * a_thread_info)
|
||||
GenericThread::GetInfo(thread_info * thread_info)
|
||||
{
|
||||
return (get_thread_info(m_thread_id, a_thread_info));
|
||||
return (get_thread_info(fThreadId, thread_info));
|
||||
}
|
||||
|
||||
|
||||
thread_id
|
||||
GenericThread::GetThread(void)
|
||||
{
|
||||
@ -302,6 +332,7 @@ GenericThread::GetThread(void)
|
||||
return (t_thread_info.thread);
|
||||
}
|
||||
|
||||
|
||||
team_id
|
||||
GenericThread::GetTeam(void)
|
||||
{
|
||||
@ -310,6 +341,7 @@ GenericThread::GetTeam(void)
|
||||
return (t_thread_info.team);
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
GenericThread::GetName(void)
|
||||
{
|
||||
@ -318,6 +350,7 @@ GenericThread::GetName(void)
|
||||
return strdup(t_thread_info.name);
|
||||
}
|
||||
|
||||
|
||||
thread_state
|
||||
GenericThread::GetState(void)
|
||||
{
|
||||
@ -326,6 +359,7 @@ GenericThread::GetState(void)
|
||||
return (t_thread_info.state);
|
||||
}
|
||||
|
||||
|
||||
sem_id
|
||||
GenericThread::GetSemaphore(void)
|
||||
{
|
||||
@ -334,6 +368,7 @@ GenericThread::GetSemaphore(void)
|
||||
return (t_thread_info.sem);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
GenericThread::GetPriority(void)
|
||||
{
|
||||
@ -342,6 +377,7 @@ GenericThread::GetPriority(void)
|
||||
return (t_thread_info.priority);
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
GenericThread::GetUserTime(void)
|
||||
{
|
||||
@ -350,6 +386,7 @@ GenericThread::GetUserTime(void)
|
||||
return (t_thread_info.user_time);
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
GenericThread::GetKernelTime(void)
|
||||
{
|
||||
@ -358,6 +395,7 @@ GenericThread::GetKernelTime(void)
|
||||
return (t_thread_info.kernel_time);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
GenericThread::GetStackBase(void)
|
||||
{
|
||||
@ -366,6 +404,7 @@ GenericThread::GetStackBase(void)
|
||||
return (t_thread_info.stack_base);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
GenericThread::GetStackEnd(void)
|
||||
{
|
||||
@ -374,15 +413,17 @@ GenericThread::GetStackEnd(void)
|
||||
return (t_thread_info.stack_end);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::BeginUnit(void)
|
||||
{
|
||||
acquire_sem(m_execute_unit); // thread can not be paused until it releases semaphore
|
||||
acquire_sem(fExecuteUnit); // thread can not be paused until it releases semaphore
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GenericThread::EndUnit(void)
|
||||
{
|
||||
release_sem(m_execute_unit); // thread can now be paused
|
||||
release_sem(fExecuteUnit); // thread can now be paused
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,11 @@
|
||||
class GenericThread
|
||||
{
|
||||
public:
|
||||
GenericThread(const char * a_thread_name = "generic_thread", int32 a_priority = B_NORMAL_PRIORITY, BMessage * a_message = NULL);
|
||||
GenericThread(const char * thread_name = "generic_thread", int32 a_priority = B_NORMAL_PRIORITY, BMessage * message = NULL);
|
||||
virtual ~GenericThread(void);
|
||||
|
||||
BMessage * GetDataStore(void);
|
||||
void SetDataStore(BMessage * a_message);
|
||||
void SetDataStore(BMessage * message);
|
||||
|
||||
status_t Start(void);
|
||||
status_t Pause(bool a_do_block = TRUE, bigtime_t a_timeout = 0);
|
||||
@ -39,7 +39,7 @@ class GenericThread
|
||||
void SnoozeUntil(bigtime_t a_microseconds, int a_timebase = B_SYSTEM_TIMEBASE);
|
||||
|
||||
|
||||
status_t GetInfo(thread_info * a_thread_info);
|
||||
status_t GetInfo(thread_info * thread_info);
|
||||
thread_id GetThread(void);
|
||||
team_id GetTeam(void);
|
||||
char * GetName(void);
|
||||
@ -65,18 +65,18 @@ class GenericThread
|
||||
void BeginUnit(void); // acquire m_execute_cycle
|
||||
void EndUnit(void); // release m_execute_cycle
|
||||
|
||||
BMessage * m_thread_data_store;
|
||||
BMessage * fThreadDataStore;
|
||||
|
||||
private:
|
||||
|
||||
static status_t private_thread_function(void * a_simple_thread_ptr);
|
||||
|
||||
thread_id m_thread_id;
|
||||
thread_id fThreadId;
|
||||
|
||||
sem_id m_execute_unit; // acq./relase within tread_function.. For Pause()
|
||||
sem_id fExecuteUnit; // acq./relase within tread_function.. For Pause()
|
||||
|
||||
bool m_quit_requested;
|
||||
bool m_thread_is_paused;
|
||||
bool fQuitRequested;
|
||||
bool fThreadIsPaused;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user