2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // based on ThreadPrimitive from the Be Newsletter
36 // e.moon 12jul99: now in cortex namespace
37 // - The stop mechanism has changed a bit; it's now up to the
38 // run() implementation to indicate that it has completed by
41 // e.moon 11may99: brought into the beDub support kit
43 #ifndef __BasicThread_H__
44 #define __BasicThread_H__
47 #include <KernelKit.h>
51 #include "cortex_defs.h"
52 __BEGIN_CORTEX_NAMESPACE
60 virtual ~BasicThread() {
68 int32 priority
=B_LOW_PRIORITY
,
70 bool killOnDelete
=true) :
74 m_name(name
? name
: "BasicThread [?]"),
78 bool running() const { return m_running
; }
79 bool stopping() const { return m_stopping
; }
81 thread_id
thread() const { return m_thread
; }
82 const char* name() const { return m_name
.String(); }
90 m_thread
= spawn_thread(
96 status_t err
= resume_thread(m_thread
);
102 // reworked 12jul99 e.moon
103 status_t
stop(bool wait
=true) {
108 thread_id thread
= m_thread
; // +++++ is this safe?
117 while(wait_for_thread(thread
, &ret
) == B_INTERRUPTED
) {
118 PRINT(("stopping thread %" B_PRId32
": B_INTERRUPTED\n",
126 protected: // internal methods
128 // Blunt force trauma.
129 // added 12jul99 e.moon
134 kill_thread(m_thread
);
142 // Call this method at the end of your run() implementation.
143 // added 12jul99 e.moon
150 private: // static impl. methods
151 static status_t
Run(void* user
) {
153 BasicThread
* instance
= static_cast<BasicThread
*>(user
);
158 private: // impl members
167 __END_CORTEX_NAMESPACE
168 #endif /* __BasicThread_H__ */