Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /*! \addtogroup osclproc OSCL Proc
     19  *
     20  * @{
     21  */
     22 
     23 
     24 
     25 /** \file oscl_scheduler_threadcontext.h
     26     \brief Thread context functions needed by oscl scheduler.
     27 */
     28 
     29 #ifndef OSCL_SCHEDULER_THREAD_CONTEXT_H_INCLUDED
     30 #define OSCL_SCHEDULER_THREAD_CONTEXT_H_INCLUDED
     31 
     32 #ifndef OSCL_AOSTATUS_H_INCLUDED
     33 #include "oscl_aostatus.h"
     34 #endif
     35 
     36 #ifndef OSCL_DOUBLE_LIST_H_INCLUDED
     37 #include "oscl_double_list.h"
     38 #endif
     39 
     40 #ifndef OSCL_MUTEX_H_INCLUDED
     41 #include "oscl_mutex.h"
     42 #endif
     43 
     44 /**
     45 //Thread context type
     46 */
     47 enum TPVThreadContext
     48 {
     49     EPVThreadContext_InThread //context is in-thread
     50     , EPVThreadContext_OsclThread //some other thread that has Oscl initialized
     51     , EPVThreadContext_NonOsclThread //some thread that does not have Oscl initialized
     52     , EPVThreadContext_Undetermined
     53 };
     54 
     55 /**
     56 //
     57 // Thread context class.
     58 //
     59 */
     60 class OsclExecSchedulerCommonBase;
     61 class PVActiveBase;
     62 class OsclBrewThreadYield;
     63 class PVThreadContext
     64 {
     65     public:
     66 
     67         OSCL_IMPORT_REF PVThreadContext();
     68         OSCL_IMPORT_REF ~PVThreadContext();
     69         /**
     70         //compare caller's thread context to this one.
     71         */
     72         OSCL_IMPORT_REF bool IsSameThreadContext();
     73 
     74         /**
     75         //static routine to get a unique thread ID for
     76         //caller's thread context.
     77         */
     78         OSCL_IMPORT_REF static uint32 Id();
     79 
     80         /**
     81         //enter and exit thread context.
     82         */
     83         OSCL_IMPORT_REF void EnterThreadContext();
     84         OSCL_IMPORT_REF void ExitThreadContext();
     85 
     86         /**
     87         // a static utility to tell whether the calling
     88         // thread has any scheduler-- either Oscl scheduler
     89         // or native scheduler.
     90         */
     91         OSCL_IMPORT_REF static bool ThreadHasScheduler();
     92 
     93     private:
     94 
     95         /**
     96         //leave if caller's thread doesn't match
     97         //given thread.
     98         */
     99         static void LeaveIfWrongThread(PVThreadContext &a);
    100 
    101 
    102         bool iOpen;
    103 
    104         /**
    105         //complete & cancel requests for this thread context.
    106         */
    107         void PendComplete(PVActiveBase*, int32 aReason, TPVThreadContext aCallingContext);
    108 
    109 
    110         OsclExecSchedulerCommonBase *iScheduler;
    111 
    112         /**
    113         //the thread ID is OS-specific.
    114         */
    115         TOsclThreadId iThreadId;
    116 
    117         friend class PVActiveBase;
    118         friend class OsclActiveObject;
    119         friend class OsclTimerObject;
    120         friend class OsclExecScheduler;
    121         friend class OsclCoeActiveScheduler;
    122         friend class OsclExecSchedulerCommonBase;
    123         friend class OsclExecSchedulerBase;
    124         friend class OsclCoeActiveSchedulerBase;
    125 };
    126 
    127 
    128 
    129 
    130 #endif //
    131 
    132 
    133 /*! @} */
    134