OSDN Git Service

add tstools.
[rec10/rec10-git.git] / tstools / DtsEdit / src / gpac / thread.h
diff --git a/tstools/DtsEdit/src/gpac/thread.h b/tstools/DtsEdit/src/gpac/thread.h
new file mode 100644 (file)
index 0000000..ee3a1b6
--- /dev/null
@@ -0,0 +1,271 @@
+/*\r
+ *                     GPAC - Multimedia Framework C SDK\r
+ *\r
+ *                     Copyright (c) Jean Le Feuvre 2000-2005 \r
+ *                                     All rights reserved\r
+ *\r
+ *  This file is part of GPAC / common tools sub-project\r
+ *\r
+ *  GPAC is free software; you can redistribute it and/or modify\r
+ *  it under the terms of the GNU Lesser General Public License as published by\r
+ *  the Free Software Foundation; either version 2, or (at your option)\r
+ *  any later version.\r
+ *   \r
+ *  GPAC is distributed in the hope that it will be useful,\r
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *  GNU Lesser General Public License for more details.\r
+ *   \r
+ *  You should have received a copy of the GNU Lesser General Public\r
+ *  License along with this library; see the file COPYING.  If not, write to\r
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
+ *\r
+ */\r
+\r
+#ifndef _GF_THREAD_H_\r
+#define _GF_THREAD_H_\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*!\r
+ *     \file <gpac/thread.h>\r
+ *     \brief threading functions.\r
+ */\r
+\r
+ /*!\r
+ *     \addtogroup thr_grp threading\r
+ *     \ingroup utils_grp\r
+ *     \brief Threading and Mutual Exclusion Functions\r
+ *\r
+ *This section documents the threading of the GPAC framework. These provide an easy way to implement\r
+ *safe multithreaded tools.\r
+ *     @{\r
+ */\r
+\r
+#include <gpac/tools.h>\r
+\r
+/*!\r
+ *\brief Thread states\r
+ *\r
+ *Inidcates the execution status of a thread\r
+ */\r
+enum\r
+{\r
+       /*! the thread has been initialized but is not started yet*/\r
+       GF_THREAD_STATUS_STOP = 0,\r
+       /*! the thread is running*/\r
+       GF_THREAD_STATUS_RUN = 1,\r
+       /*! the thread has exited its body function*/\r
+       GF_THREAD_STATUS_DEAD = 2\r
+};\r
+\r
+/*!\r
+ *\brief abstracted thread object\r
+ *\r
+ *The abstracted thread object allows you to execute some code independently of the main process of your application.\r
+*/\r
+typedef struct __tag_thread GF_Thread;\r
+\r
+/*!\r
+ *\brief thread constructor\r
+ *\r
+ *Constructs a new thread object\r
+ *\param log name of the thread if any\r
+ */\r
+GF_Thread *gf_th_new(const char *name);\r
+/*!\r
+ *\brief thread destructor\r
+ *\r
+ * Kills the thread if running and destroys the object\r
+ *\param th the thread object\r
+ */\r
+void gf_th_del(GF_Thread *th);\r
+\r
+/*!\r
+ *     \brief thread run function callback\r
+ *\r
+ *The gf_thread_run type is the type for the callback of the \ref gf_thread_run function\r
+ *\param par opaque user data\r
+ *\return exit code of the thread, usually 1 for error and 0 if normal execution\r
+ *\r
+ */\r
+typedef u32 (*gf_thread_run)(void *par);\r
+\r
+/*!\r
+ *\brief thread execution\r
+ *\r
+ *Executes the thread with the given function\r
+ *\param th the thread object\r
+ *\param run the function this thread will call\r
+ *\param par the argument to the function the thread will call\r
+ *\note A thread may be run several times but cannot be run twice in the same time.\r
+ */\r
+GF_Err gf_th_run(GF_Thread *th, gf_thread_run run, void *par);\r
+/*!\r
+ *\brief thread stoping\r
+ *\r
+ *Waits for the thread exit until return\r
+ *\param th the thread object\r
+ */\r
+void gf_th_stop(GF_Thread *th);\r
+/*!\r
+ *\brief thread status query\r
+ *\r
+ *Gets the thread status\r
+ *\param th the thread object\r
+ */\r
+u32 gf_th_status(GF_Thread *th);\r
+\r
+/*!\r
+ * thread priorities\r
+ */\r
+enum\r
+{\r
+       /*!Idle Priority*/\r
+       GF_THREAD_PRIORITY_IDLE=0,\r
+       /*!Less Idle Priority*/\r
+       GF_THREAD_PRIORITY_LESS_IDLE,\r
+       /*!Lowest Priority*/\r
+       GF_THREAD_PRIORITY_LOWEST,\r
+       /*!Low Priority*/\r
+       GF_THREAD_PRIORITY_LOW,\r
+       /*!Normal Priority (the default one)*/\r
+       GF_THREAD_PRIORITY_NORMAL,\r
+       /*!High Priority*/\r
+       GF_THREAD_PRIORITY_HIGH,\r
+       /*!Highest Priority*/\r
+       GF_THREAD_PRIORITY_HIGHEST,\r
+       /*!First real-time priority*/\r
+       GF_THREAD_PRIORITY_REALTIME,\r
+       /*!Last real-time priority*/\r
+       GF_THREAD_PRIORITY_REALTIME_END=255\r
+};\r
+\r
+/*!\r
+ *\brief thread priority\r
+ *\r
+ *Sets the thread execution priority level.\r
+ *\param th the thread object\r
+ *\param priority the desired priority\r
+ *\note this should be used with caution, especially use of real-time priorities.\r
+ */\r
+void gf_th_set_priority(GF_Thread *th, s32 priority);\r
+/*!\r
+ *\brief current thread ID \r
+ *\r
+ *Gets the ID of the current thread the caller is in.\r
+*/\r
+u32 gf_th_id();\r
+\r
+\r
+\r
+/*!\r
+ *\brief abstracted mutex object\r
+ *\r
+ *The abstracted mutex object allows you to make sure that portions of the code (typically access to variables) cannot be executed\r
+ *by two threads (or a thread and the main process) at the same time.\r
+*/\r
+typedef struct __tag_mutex GF_Mutex;\r
+/*\r
+ *\brief mutex constructor\r
+ *\r
+ *Contructs a new mutex object\r
+ *\param log name of the thread if any\r
+*/\r
+GF_Mutex *gf_mx_new(const char *name);\r
+/*\r
+ *\brief mutex denstructor\r
+ *\r
+ *Destroys a mutex object. This will wait for the mutex to be released if needed.\r
+ *\param mx the mutex object\r
+*/\r
+void gf_mx_del(GF_Mutex *mx);\r
+/*\r
+ *\brief mutex locking\r
+ *\r
+ *Locks the mutex object, making sure that another thread locking this mutex cannot exectute until the mutex is unlocked.\r
+ *\param mx the mutex object\r
+ *\return 1 if success, 0 if error locking the mutex (which should never happen)\r
+*/\r
+u32 gf_mx_p(GF_Mutex *mx);\r
+/*\r
+ *\brief mutex unlocking\r
+ *\r
+ *Unlocks the mutex object, allowing other threads waiting on this mutex to continue their execution\r
+ *\param mx the mutex object\r
+*/\r
+void gf_mx_v(GF_Mutex *mx);\r
+/*\r
+ *\brief mutex non-blocking lock\r
+ *\r
+ *Attemps to lock the mutex object without blocking until the object is released.\r
+ *\param mx the mutex object\r
+ *\return 1 if the mutex has been successfully locked, in which case it shall then be unlocked, or 0 if the mutex is locked by another thread.\r
+*/\r
+Bool gf_mx_try_lock(GF_Mutex *mx);\r
+\r
+\r
+/*********************************************************************\r
+                                       Semaphore Object\r
+**********************************************************************/\r
+/*!\r
+ *\brief abstracted semaphore object\r
+ *\r
+ *The abstracted semaphore object allows you to control how portions of the code (typically access to variables) are executed\r
+ *by two threads (or a thread and the main process) at the same time. The best image for a semaphore is a limited set \r
+ *of money coins (always easy to understand hmm?). If no money is in the set, nobody can buy anything until a coin is \r
+ *put back in the set. When the set is full, the money is wasted (call it "the bank"...).\r
+*/\r
+typedef struct __tag_semaphore GF_Semaphore;\r
+/*\r
+ *\brief semaphore constructor\r
+ *\r
+ *Constructs a new semaphore object\r
+ *\param MaxCount the maximum notification count of this semaphore\r
+ *\param InitCount the initial notification count of this semaphore upon construction\r
+ *\return the semaphore object\r
+ */\r
+GF_Semaphore *gf_sema_new(u32 MaxCount, u32 InitCount);\r
+/*\r
+ *\brief semaphore destructor\r
+ *\r
+ *Destructs the semaphore object. This will wait for the semaphore to be released if needed.\r
+ */\r
+void gf_sema_del(GF_Semaphore *sm);\r
+/*\r
+ *\brief semaphore notifivation\r
+ *\r
+ *Notifies the semaphore of a certain amount of releases.\r
+ *\param sm the semaphore object\r
+ *\param nb_rel sm the number of release to notify\r
+ *\return the number of previous notification count in the semaphore \r
+*/\r
+u32 gf_sema_notify(GF_Semaphore *sm, u32 nb_rel);\r
+/*\r
+ *\brief semaphore wait\r
+ *\r
+ *Waits for the semaphore to be accessible (eg, may wait an infinite time).\r
+ *\param sm the semaphore object\r
+*/\r
+void gf_sema_wait(GF_Semaphore *sm);\r
+/*\r
+ *\brief semaphore time wait\r
+ *\r
+ *Waits for a certain for the semaphore to be accessible, and returns when semaphore is accessible or wait time has passed.\r
+ *\param sm the semaphore object\r
+ *\param time_out the amount of time to wait for the release in milliseconds\r
+ *\return returns 1 if the semaphore was released before the timeout, 0 if the semaphore is still not released after the timeout.\r
+*/\r
+Bool gf_sema_wait_for(GF_Semaphore *sm, u32 time_out);\r
+\r
+/*! @} */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif         /*_GF_THREAD_H_*/\r
+\r