diff options
author | Mamadou DIOP <bossiel@yahoo.fr> | 2016-02-23 22:00:35 +0100 |
---|---|---|
committer | Mamadou DIOP <bossiel@yahoo.fr> | 2016-02-23 22:00:35 +0100 |
commit | 50dfb4359619563012997bc3ddafb7667741066c (patch) | |
tree | db234c1edc3240a653363b5735fc4077af4b8720 /tinySAK/src/tsk.c | |
parent | 94b2219209038e05dd26395f6fb700be4d1062c0 (diff) | |
download | doubango-50dfb4359619563012997bc3ddafb7667741066c.zip doubango-50dfb4359619563012997bc3ddafb7667741066c.tar.gz |
Add new QoS implementation
Code formatting
Diffstat (limited to 'tinySAK/src/tsk.c')
-rwxr-xr-x | tinySAK/src/tsk.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/tinySAK/src/tsk.c b/tinySAK/src/tsk.c index 195ec96..672cf2d 100755 --- a/tinySAK/src/tsk.c +++ b/tinySAK/src/tsk.c @@ -5,19 +5,19 @@ * * @section LICENSE * -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -79,14 +79,14 @@ tsk_object_def_t; * Below, an example of how to declare an object definition:<br> * @code * //(Object defnition) - static const tsk_object_def_t person_def_t = + static const tsk_object_def_t person_def_t = { sizeof(person_t), person_ctor, person_dtor, person_cmp }; -* @endcode +* @endcode * <h2>6.2 Constructor</h2> * The constructor is only responsible for the initialization and won’t allocate the object. When passed to the constructor, the object is already allocated.<br> * Here is an example:<br> @@ -100,14 +100,14 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app) } return self; } -* @endcode +* @endcode * <h2>6.3 Destructor</h2> * The destructor will free the object’s members and won’t destroy the object itself (Phase 1). The destructor function must return a pointer to itself to allow the caller to perform the second phase.<br> * Here is an example:<br> * @code // (destructor) static tsk_object_t * person_dtor(tsk_object_t * self) - { + { person_t *person = self; if(person){ TSK_FREE(person->name); @@ -115,7 +115,7 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app) } return self; } -* @endcode +* @endcode * <h2>6.4 Comparator</h2> * The comparator function is used to compare two well-defined objects. The objects to compare shall have the same definition (or type). <br> * Here is an example:<br> @@ -126,7 +126,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2) const person_t *p1 = _p1; const person_t *p1 = _p2; int ret; - + // do they have the same name? if((ret = tsk_stricmp(p1->name, p2->name))){ return ret; @@ -135,7 +135,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2) if((ret = tsk_object_cmp(p1->girlfriend, p2->girlfriend))){ return ret; } - + // they are the same return 0; } @@ -144,7 +144,7 @@ static int person_cmp(const tsk_object_t *_p1, const tsk_object_t *_p2) * Reference counting is used to emulate garbage collection. Each well-defined object contains a reference counter field which indicates how many object have a reference to the actual object.<br> * When an object is created (see below) the counter value is initialized to 1; this is automatically done and you have nothing to do. The counter is incremented by 1 when you call @ref tsk_object_ref() and decremented (by 1) when you call @ref tsk_object_unref().<br> * When the counter value reaches zero, then the object is garbaged (freed).<br> -* +* * <h2>6.6 Inheritence</h2> * As you expect, inheritance is not supported in ANSI-C. <br> * As any C Structure could be casted to a pointer to its first element, inheritance could be achieved like this:<br> @@ -163,7 +163,7 @@ student_t* s = tsk_null; //.... ((person_t*)s)->name = tsk_strdup("bob"); * @endcode -* +* * As @code person_t is a well-defined object, then @code student_t is also well-defined.<br> * <h2>6.7 Usage</h2> * Once the object’s definition is declared and all its mandatory functions implemented, it is used like this:<br> @@ -180,7 +180,7 @@ tsk_object_unref(bob); // create a person #define PERSON_CREATE(name) tsk_object_new(&person_def_t, (const char*)name) * @endcode -* +* * As the destructor has fixed parameters, there is a common macro to destroy all kind of well-defined objects. <br> * TSK_OBJECT_SAFE_FREE() is used to destroy any object. <br> * The object will be freed only if; when decremented by 1 the reference count of the object is equal to zero. In all case (freed or not) the pointer value will be set to NULL.<br> @@ -200,7 +200,7 @@ TSK_OBJECT_SAFE_FREE(bob); * * <h2>7 Threading</h2> * The framework provides an operating system agnostic threading functions for both WIN32 and Unix-like systems.<br> -* +* * <h2>7.1 Threads</h2> * You don’t need thousands of functions to manage threads. In the Framework we only need to create, pause and destroy threads.<br> * Threads can be created using @ref tsk_thread_create() and joined using @ref tsk_thread_join().<br> @@ -218,7 +218,7 @@ void test_threads() { void* tid[1] = {tsk_null}; // thread id int arg = 112; // arg to pass to the function - + // creates the thread tsk_thread_create(&tid[0], MyThreadFunction, &arg); @@ -226,7 +226,7 @@ void test_threads() tsk_thread_join(&(tid[0])); } * @endcode -* +* * <h2>7.2 Mutexes</h2> * Mutexes (Mutual exclusion) are used to protect a portion of code or function against concurrent access. Concurrent access happens when two or several threads try to execute the same portion of code at nearly the same time.<br> * @code @@ -234,7 +234,7 @@ void test_threads() // create the mutext tsk_mutex_handle_t *mutex = tsk_mutex_create(); - + tsk_mutex_lock(mutex); // ...portion of code to protect tsk_mutex_unlock(mutex); @@ -243,12 +243,12 @@ tsk_mutex_unlock(mutex); tsk_mutex_destroy(&mutex); * @endcode * Mutexes are not well-defined objects; you should use @ref tsk_mutex_destroy instead of TSK_OBJECT_SAFE_FREE() to destroy them.<br> -* +* * <h2>7.3 Thread-Safe Objects</h2> -* +* * Any C Structure could be declared as thread-safe using @ref TSK_DECLARE_SAFEOBJ macro. It’s not mandatory for the object to be well-defined.<br> * A thread-safe object is initialized using @ref tsk_safeobj_init() and deinitilized using @ref tsk_safeobj_deinit(). To lock and unlock a portion of code which accesses the object you should use @ref tsk_safeobj_lock() and @ref tsk_safeobj_unlock() respectively.<br> -* +* * <h2>7.4 Semaphores</h2> * Only counting semaphores are supported by the framework. * Counting semaphores are used to control the access to a portion of code which might be executed by multiple threads. A thread will have rights to execute the portion of code only if the semaphore’s internal counter value is different than zero. Before executing the code to control, a thread should decrement the counter to check if it has permit.<br> @@ -266,19 +266,19 @@ tsk_semaphore_destroy(&sem); * @endcode * Semaphores are not well-defined objects; you should use @ref tsk_semaphore_destroy instead of TSK_OBJECT_SAFE_FREE() to destroy them.<br> * Mutexes are binary semaphores (counter value is always equals to 1 or 0).<br> -* +* * <h2>7.5 Condition Variables</h2> * Condition variables are used to control the access to a portion of code which might be executed by multiple threads. Each thread will block until a certain condition is signaled or ms milliseconds have passed.<br> * @ref tsk_condwait_create is used to create a condition variable, @ref tsk_condwait_wait() to wait indefinitely until the condition is signaled and @ref tsk_condwait_timedwait() to wait until the condition is signaled or ms milliseconds have passed.<br> * @ref tsk_condwait_signal() is used to alert the first waiting thread that the condition is now true and @ref tsk_condwait_broadcast() is used to alert all waiting threads.<br> * Condition variables are not well-defined objects; you should use @ref tsk_condwait_destroy() instead of TSK_OBJECT_SAFE_FREE() to destroy them.<br> -* +* * <h2>7.6 Runnable</h2> * A <i>runnable</i> object is a well-defined object and is declared using @ref TSK_DECLARE_RUNNABLE() macro.<br> * A <i>runnable</i> object must be explicitly started using @ref tsk_runnable_start() and is implicitly stopped when destroyed. You can explicitly stop the object by calling @ref tsk_runnable_stop().<br> -* +* * <h2>8 Final Sate Machine</h2> -* +* * <h2>9 Timer Manager</h2> * */ |