Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F624131
thread.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
thread.cpp
View Options
#include
<pthread.h>
#include
"thread.h"
namespace
Util
{
Thread
::
Thread
()
:
done
(
false
){
pthread_mutex_init
(
&
doneLock
,
NULL
);
}
Thread
::
Thread
(
void
*
(
*
thread
)(
void
*
),
void
*
arg
){
pthread_mutex_init
(
&
doneLock
,
NULL
);
start
(
thread
,
arg
);
}
static
void
*
do_thread
(
void
*
arg
){
Thread
*
thread
=
(
Thread
*
)
arg
;
thread
->
doRun
();
return
NULL
;
}
void
Thread
::
doRun
(){
this
->
function
(
this
->
arg
);
pthread_mutex_lock
(
&
doneLock
);
this
->
done
=
true
;
pthread_mutex_unlock
(
&
doneLock
);
}
void
Thread
::
start
(
void
*
(
*
thread
)(
void
*
),
void
*
arg
){
done
=
false
;
this
->
arg
=
arg
;
this
->
function
=
thread
;
pthread_create
(
&
this
->
thread
,
NULL
,
do_thread
,
this
);
}
bool
Thread
::
isRunning
(){
pthread_mutex_lock
(
&
doneLock
);
bool
what
=
done
;
pthread_mutex_unlock
(
&
doneLock
);
return
what
;
}
void
Thread
::
kill
(){
/* FIXME: cancel is not implemented for libogc, find another way.
* thread suspend/resume is there, though.
*/
#if !defined(WII)
pthread_cancel
(
thread
);
#endif
pthread_join
(
thread
,
NULL
);
}
Thread
::~
Thread
(){
/* FIXME: Should we join the thread? */
/* pthread_join(thread); */
}
ThreadBoolean
::
ThreadBoolean
(
volatile
bool
&
what
,
pthread_mutex_t
&
lock
)
:
what
(
what
),
lock
(
lock
){
}
bool
ThreadBoolean
::
get
(){
pthread_mutex_lock
(
&
lock
);
bool
b
=
what
;
pthread_mutex_unlock
(
&
lock
);
return
b
;
}
void
ThreadBoolean
::
set
(
bool
value
){
pthread_mutex_lock
(
&
lock
);
what
=
value
;
pthread_mutex_unlock
(
&
lock
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, Nov 14, 10:00 PM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
133045
Default Alt Text
thread.cpp (1 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline