Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
jop::Thread Class Reference

#include <Thread.hpp>

Public Types

enum  Priority {
  Priority::Lowest, Priority::Lower, Priority::Normal, Priority::Higher,
  Priority::Highest
}
 

Public Member Functions

 Thread ()
 Default constructor. More...
 
template<typename F , typename... Args>
 Thread (F &&func, Args &&...args)
 Constructor. More...
 
 Thread (Thread &&other)
 Move constructor. More...
 
Threadoperator= (Thread &&other)
 Move assignment operator. More...
 
 ~Thread ()
 Destructor. More...
 
void join ()
 Wait for the thread to return. More...
 
bool isJoinable () const
 Check if this thread is joinable. More...
 
void detach ()
 Detach the thread. More...
 
bool setPriority (const Priority priority)
 Set thread priority. More...
 
void terminate ()
 Terminate this thread. More...
 
std::thread::id getId () const
 Get the thread identifier. More...
 

Static Public Member Functions

static void attachJavaThread (void *vm, void *mainEnv)
 Attach the calling thread to the Java virtual machine. More...
 
static void detachJavaThread (void *vm)
 Detach the calling thread from the Java virtual machine. More...
 
static _JNIEnv * getCurrentJavaEnv ()
 Get the JNIEnv for the calling thread. More...
 

Detailed Description

Definition at line 36 of file Thread.hpp.

Member Enumeration Documentation

enum jop::Thread::Priority
strong

Thread priority

Enumerator
Lowest 
Lower 
Normal 
Higher 
Highest 

Definition at line 46 of file Thread.hpp.

Constructor & Destructor Documentation

jop::Thread::Thread ( )

Default constructor.

Will not start an actual thread.

template<typename F , typename... Args>
jop::Thread::Thread ( F &&  func,
Args &&...  args 
)
explicit

Constructor.

This will start the thread immediately.

Parameters
funcThe function to use
argsArguments to pass to the function
jop::Thread::Thread ( Thread &&  other)

Move constructor.

jop::Thread::~Thread ( )

Destructor.

If the thread is running and hasn't been detached, this will wait until it returns.

Member Function Documentation

static void jop::Thread::attachJavaThread ( void *  vm,
void *  mainEnv 
)
static

Attach the calling thread to the Java virtual machine.

A thread needs to be attached if it makes any JNI calls.

On operating systems besides Android, this function is no-op.

Parameters
vmPointer to the Java virtual machine, may be null
mainEnvPointer to the NativeActivity JNIEnv, may be null
void jop::Thread::detach ( )

Detach the thread.

After this call the thread is completely independent. join() will have no effect.

static void jop::Thread::detachJavaThread ( void *  vm)
static

Detach the calling thread from the Java virtual machine.

On operating systems besides Android, this function is no-op.

Parameters
vmPointer to the Java virtual machine, may be null
static _JNIEnv* jop::Thread::getCurrentJavaEnv ( )
static

Get the JNIEnv for the calling thread.

Returns
Pointer to the JNIEnv
std::thread::id jop::Thread::getId ( ) const

Get the thread identifier.

Returns
The thread identifier
bool jop::Thread::isJoinable ( ) const

Check if this thread is joinable.

The thread is joinable if it hasn't been detached.

Returns
True if joinable
void jop::Thread::join ( )

Wait for the thread to return.

This will return immediately if the thread is not joinable.

Thread& jop::Thread::operator= ( Thread &&  other)

Move assignment operator.

bool jop::Thread::setPriority ( const Priority  priority)

Set thread priority.

Parameters
priorityThe priority to set
Returns
True if priority was set successfully
void jop::Thread::terminate ( )

Terminate this thread.

This method is unsafe. You should always attempt to make your threads return by themselves before resorting to calling this.


The documentation for this class was generated from the following file: