diff options
author | blacksirius <blacksirius@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-06-03 18:53:02 +0000 |
---|---|---|
committer | blacksirius <blacksirius@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-06-03 18:53:02 +0000 |
commit | 4feeab8c61334ec73172fa01cda951dafde2505f (patch) | |
tree | 078521eec3b26bd7fcfd42c9d1615d35be6b3ec9 /src/common/thread.h | |
parent | 40ede8fd21bdb39c01665c90aa420a03a712c96c (diff) | |
download | hercules-4feeab8c61334ec73172fa01cda951dafde2505f.tar.gz hercules-4feeab8c61334ec73172fa01cda951dafde2505f.tar.bz2 hercules-4feeab8c61334ec73172fa01cda951dafde2505f.tar.xz hercules-4feeab8c61334ec73172fa01cda951dafde2505f.zip |
feature merge bs-coreoptimize->trunk: Atomic Operations, Threading, Spinlock implemnetation. [commit 1/2, windows will followup]
- Added Abstractions for Atomic Operations (lock instructions.. windows guy's may now this as Interlocked* stuff ..)
- Added Threading api abstraction for Pthread based OS's and Windows
- Added Spinlock Implementation (uses CAS / if you need more informations - just read the source - its simple.)
- Due to Interlocked(Compare)Exchange64 .. we now require at least i686 (Pentium Pro) for 32Bit Builds :)
youll also may feel some performance improvements when using 32bit builsd due to "newer" minimal arch
the compiler is now able to use CMOV's ....
================================================================
= Important Warning:
================================================================
Dont use threading at the moment athena is not threadsafe!
you'll mess up everthing when accessing data from other threads .., no synchronization is provided.
A way to process tasks asynchronously will come up after / with the new socket system.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16221 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/thread.h')
-rw-r--r-- | src/common/thread.h | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/common/thread.h b/src/common/thread.h new file mode 100644 index 000000000..d4027811f --- /dev/null +++ b/src/common/thread.h @@ -0,0 +1,115 @@ +#pragma once +#ifndef _rA_THREAD_H_ +#define _rA_THREAD_H_ + +#include "../common/cbasetypes.h" + +typedef struct rAthread *rAthread; +typedef void* (*rAthreadProc)(void*); + +typedef enum RATHREAD_PRIO { + RAT_PRIO_LOW = 0, + RAT_PRIO_NORMAL, + RAT_PRIO_HIGH +} RATHREAD_PRIO; + + +/** + * Creates a new Thread + * + * @param entyPoint - entryProc, + * @param param - general purpose parameter, would be given as parameter to the thread's entrypoint. + * + * @return not NULL if success + */ +rAthread rathread_create( rAthreadProc entryPoint, void *param ); + + +/** + * Creates a new Thread (with more creation options) + * + * @param entyPoint - entryProc, + * @param param - general purpose parameter, would be given as parameter to the thread's entrypoint + * @param szStack - stack Size in bytes + * @param prio - Priority of the Thread @ OS Scheduler.. + * + * @return not NULL if success + */ +rAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szStack, RATHREAD_PRIO prio ); + + +/** + * Destroys the given Thread immediatly + * + * @note The Handle gets invalid after call! dont use it afterwards. + * + * @param handle - thread to destroy. + */ +void rathread_destroy ( rAthread handle ); + + +/** + * Returns the thread handle of the thread calling this function + * + * @note this wont work @ programms main thread + * @note the underlying implementation might not perform very well, cache the value received! + * + * @return not NULL if success + */ +rAthread rathread_self( ); + + +/** + * Returns own thrad id (TID) + * + * @note this is not the operating system THREAD ID! + * + * @return -1 when fails, otherwise >= 0 + */ +int rathread_get_tid(); + + +/** + * Waits for the given thread to terminate + * + * @param handle - thread to wait (join) for + * @param out_Exitcode - [OPTIONAL] - if given => Exitcode (value) of the given thread - if it's terminated + * + * @return true - if the given thread has been terminated. + */ +bool rathread_wait( rAthread handle, void* *out_exitCode ); + + +/** + * Sets the given PRIORITY @ OS Task Scheduler + * + * @param handle - thread to set prio for + * @param rio - the priority (RAT_PRIO_LOW ... ) + */ +void rathread_prio_set( rAthread handle, RATHREAD_PRIO prio ); + + +/** + * Gets the current Prio of the given trhead + * + * @param handle - the thread to get the prio for. + */ +RATHREAD_PRIO rathread_prio_get( rAthread handle); + + +/** + * Tells the OS scheduler to yield the execution of the calling thread + * + * @note: this will not "pause" the thread, + * it just allows the OS to spent the remaining time + * of the slice to another thread. + */ +void rathread_yield(); + + + +void rathread_init(); +void rathread_final(); + + +#endif |