From 50dfb4359619563012997bc3ddafb7667741066c Mon Sep 17 00:00:00 2001 From: Mamadou DIOP Date: Tue, 23 Feb 2016 22:00:35 +0100 Subject: Add new QoS implementation Code formatting --- tinySAK/src/tsk.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'tinySAK/src/tsk.c') 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:
* @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 *

6.2 Constructor

* The constructor is only responsible for the initialization and won’t allocate the object. When passed to the constructor, the object is already allocated.
* Here is an example:
@@ -100,14 +100,14 @@ static tsk_object_t* person_ctor(tsk_object_t * self, va_list * app) } return self; } -* @endcode +* @endcode *

6.3 Destructor

* 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.
* Here is an example:
* @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 *

6.4 Comparator

* The comparator function is used to compare two well-defined objects. The objects to compare shall have the same definition (or type).
* Here is an example:
@@ -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.
* 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().
* When the counter value reaches zero, then the object is garbaged (freed).
-* +* *

6.6 Inheritence

* As you expect, inheritance is not supported in ANSI-C.
* As any C Structure could be casted to a pointer to its first element, inheritance could be achieved like this:
@@ -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.
*

6.7 Usage

* Once the object’s definition is declared and all its mandatory functions implemented, it is used like this:
@@ -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.
* TSK_OBJECT_SAFE_FREE() is used to destroy any object.
* 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.
@@ -200,7 +200,7 @@ TSK_OBJECT_SAFE_FREE(bob); * *

7 Threading

* The framework provides an operating system agnostic threading functions for both WIN32 and Unix-like systems.
-* +* *

7.1 Threads

* You don’t need thousands of functions to manage threads. In the Framework we only need to create, pause and destroy threads.
* Threads can be created using @ref tsk_thread_create() and joined using @ref tsk_thread_join().
@@ -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 -* +* *

7.2 Mutexes

* 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.
* @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.
-* +* *

7.3 Thread-Safe Objects

-* +* * 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.
* 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.
-* +* *

7.4 Semaphores

* 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.
@@ -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.
* Mutexes are binary semaphores (counter value is always equals to 1 or 0).
-* +* *

7.5 Condition Variables

* 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.
* @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.
* @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.
* Condition variables are not well-defined objects; you should use @ref tsk_condwait_destroy() instead of TSK_OBJECT_SAFE_FREE() to destroy them.
-* +* *

7.6 Runnable

* A runnable object is a well-defined object and is declared using @ref TSK_DECLARE_RUNNABLE() macro.
* A runnable 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().
-* +* *

8 Final Sate Machine

-* +* *

9 Timer Manager

* */ -- cgit v1.1