POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/include/core/lockobj.h
Go to the documentation of this file.
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 
00018 #ifndef __POK_KERNEL_LOCKOBJ_H__
00019 #define __POK_KERNEL_LOCKOBJ_H__
00020 
00021 #include <types.h>
00022 #include <arch.h>
00023 
00024 #ifndef POK_CONFIG_NB_LOCKOBJECTS
00025 #define POK_CONFIG_NB_LOCKOBJECTS 0
00026 #endif
00027 
00028 /*
00029  * In POK, all locking objects are implemented in the same way. It avoids
00030  * code duplication and save the environnement because we will consume less
00031  * space on your disk and will save trees because stupid people that prints
00032  * the code will consume less paper.
00033  * Moreoever, if all lockobjects share the same code, it will be easy to
00034  * certify and verify the behavior of all.
00035  */
00036 
00037 
00038 typedef enum
00039 {
00040    POK_LOCKOBJ_KIND_MUTEX = 1,
00041    POK_LOCKOBJ_KIND_SEMAPHORE = 2,
00042    POK_LOCKOBJ_KIND_EVENT = 3
00043 }pok_lockobj_kind_t;
00044 
00045 /* All kind of lock objects we have in the kernel */
00046 
00047 typedef enum
00048 {
00049    POK_LOCKOBJ_POLICY_STANDARD = 0,
00050    POK_LOCKOBJ_POLICY_PIP      = 1,
00051    POK_LOCKOBJ_POLICY_PCP      = 2
00052 }pok_locking_policy_t;
00053 
00054 
00055 typedef enum
00056 {
00057    LOCKOBJ_STATE_LOCK = 0,
00058    LOCKOBJ_STATE_UNLOCK = 1,
00059    LOCKOBJ_STATE_WAITEVENT = 2
00060 }pok_mutex_state_t;
00061 
00062 
00063 typedef struct
00064 {
00065    pok_lockobj_kind_t         kind;
00066    pok_locking_policy_t       locking_policy;
00067    pok_queueing_discipline_t  queueing_policy;  
00068    pok_sem_value_t            initial_value;
00069    pok_sem_value_t            max_value;
00070 }pok_lockobj_attr_t;
00071 
00072 typedef struct
00073 {
00074    pok_spinlock_t             spin;
00075    pok_spinlock_t             eventspin;
00076    /* spinlock to enfoce mutual exclusion */
00077 
00078    bool_t                     is_locked;
00079    /* Is the mutex locked ? */
00080    
00081    pok_mutex_state_t          thread_state[POK_CONFIG_NB_THREADS + 2];
00082    /* Describe which thread is blocked in the mutex */
00083    
00084    pok_locking_policy_t       locking_policy;
00085    /* Locking policy */
00086 
00087    pok_queueing_discipline_t  queueing_policy;
00088    /* Locking policy */
00089 
00090    pok_lockobj_kind_t         kind;
00091    
00092    bool_t                     initialized;
00093    /* Is the mutex initialized ? */
00094    
00095    uint16_t                   current_value;
00096    uint16_t                   max_value;
00097 } pok_lockobj_t;
00098 
00099 
00100 typedef enum
00101 {
00102    LOCKOBK_LOCK_REGULAR = 1,
00103    LOCKOBJ_LOCK_TIMED   = 2
00104 }pok_lockobj_lock_kind_t;
00105 
00106 typedef enum
00107 {
00108    LOCKOBJ_OPERATION_LOCK = 1,
00109    LOCKOBJ_OPERATION_UNLOCK = 2,
00110    LOCKOBJ_OPERATION_WAIT = 3,
00111    LOCKOBJ_OPERATION_SIGNAL = 4,
00112    LOCKOBJ_OPERATION_BROADCAST = 5
00113 }pok_lockobj_operation_t;
00114 
00115 typedef struct
00116 {
00117    pok_lockobj_operation_t    operation;
00118    pok_lockobj_kind_t         obj_kind;
00119    pok_lockobj_lock_kind_t    lock_kind;
00120    uint64_t                   time;
00121 }pok_lockobj_lockattr_t;
00122 
00123 
00124 pok_ret_t pok_lockobj_create (pok_lockobj_t* obj, const pok_lockobj_attr_t* attr);
00125 pok_ret_t pok_lockobj_init ();
00126 pok_ret_t pok_lockobj_partition_create (pok_lockobj_id_t* id, const pok_lockobj_attr_t* attr);
00127 pok_ret_t pok_lockobj_lock (pok_lockobj_t* obj, const pok_lockobj_lockattr_t* attr);
00128 pok_ret_t pok_lockobj_unlock (pok_lockobj_t* obj, const pok_lockobj_lockattr_t* attr);
00129 pok_ret_t pok_lockobj_eventwait (pok_lockobj_t* obj, const uint64_t timeout);
00130 pok_ret_t pok_lockobj_eventsignal (pok_lockobj_t* obj);
00131 pok_ret_t pok_lockobj_eventbroadcast (pok_lockobj_t* obj);
00132 pok_ret_t pok_lockobj_partition_wrapper (const pok_lockobj_id_t id, const pok_lockobj_lockattr_t* attr);
00133 
00134 #endif