diff options
Diffstat (limited to 'include/utils/threads.h')
-rw-r--r-- | include/utils/threads.h | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/include/utils/threads.h b/include/utils/threads.h index 0fc533f..5ac0c5e 100644 --- a/include/utils/threads.h +++ b/include/utils/threads.h @@ -124,6 +124,24 @@ typedef int (*android_create_thread_fn)(android_thread_func_t entryFunction, extern void androidSetCreateThreadFunc(android_create_thread_fn func); +// ------------------------------------------------------------------ +// Extra functions working with raw pids. + +// Get pid for the current thread. +extern pid_t androidGetTid(); + +// Change the scheduling group of a particular thread. The group +// should be one of the ANDROID_TGROUP constants. Returns BAD_VALUE if +// grp is out of range, else another non-zero value with errno set if +// the operation failed. +extern int androidSetThreadSchedulingGroup(pid_t tid, int grp); + +// Change the priority AND scheduling group of a particular thread. The priority +// should be one of the ANDROID_PRIORITY constants. Returns INVALID_OPERATION +// if the priority set failed, else another value if just the group set failed; +// in either case errno is set. +extern int androidSetThreadPriority(pid_t tid, int prio); + #ifdef __cplusplus } #endif @@ -191,7 +209,7 @@ inline thread_id_t getThreadId() { class Mutex { public: enum { - NORMAL = 0, + PRIVATE = 0, SHARED = 1 }; @@ -287,7 +305,13 @@ typedef Mutex::Autolock AutoMutex; */ class Condition { public: + enum { + PRIVATE = 0, + SHARED = 1 + }; + Condition(); + Condition(int type); ~Condition(); // Wait on the condition variable. Lock the mutex before calling. status_t wait(Mutex& mutex); @@ -311,6 +335,17 @@ private: inline Condition::Condition() { pthread_cond_init(&mCond, NULL); } +inline Condition::Condition(int type) { + if (type == SHARED) { + pthread_condattr_t attr; + pthread_condattr_init(&attr); + pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + pthread_cond_init(&mCond, &attr); + pthread_condattr_destroy(&attr); + } else { + pthread_cond_init(&mCond, NULL); + } +} inline Condition::~Condition() { pthread_cond_destroy(&mCond); } |