.ad 8
.bm 8
.fm 4
.bt $Copyright by   Software AG, 1993$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $NME$Project Distributed Database System$veo00c$
.tt 2 $$$
.tt 3 $F.Hoffmann$common_rte_include module$1997-08-07$
***********************************************************
.nf


    ========== licence begin LGPL
    Copyright (C) 2002 SAP AG

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    ========== licence end

.fo
.nf
.sp
Module  : common_rte_include_module
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :

.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :

.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :

.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : F.Hoffmann
.sp
.cp 3
Created : 1995-08-30
.sp
.cp 3
Version : 1995-08-30
.sp
.cp 3
Release :  7.0 	 Date : 1997-08-07
.br
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:

.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:

.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:

.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
/*PRETTY*/


#if defined(_WIN32) || defined(OS2) 
#define KGS_        kgs.
#define VCLOCK_PROTOTYPE
#else
#define KGS_        kgs->
#define VCLOCK_PROTOTYPE       void vclock()
#endif

#define IS_TIME_MEASURE_ACTIVE (KGS_ fTimeMeasure)
#define XPARAM(_param_elem) (((RTE_XPARAM_REC *)(KGS_ XParam))->_param_elem)

#define PAGES_TO_SHIFT(_pages,_shift) \
        {for ( _shift=10; (_pages >> (_shift+1) ) > 0; _shift++ ); }

#define DEVSPACE_PAGE_SHIFT             KGS_ ulDBPageShift
#define PAGES_TO_BYTES(_pages)          ((_pages) << DEVSPACE_PAGE_SHIFT)
#define BYTES_TO_PAGES(_bytes)          ((_bytes) >> DEVSPACE_PAGE_SHIFT)
/*
 *  Values for kernel task type
 */
#define         TT_TI                   11
#define         TT_TL                   12
#define         TT_AL                   13
#define         TT_TW                   14
#define         TT_DW                   15
#define         TT_SN                   16
#define         TT_RC                   17
#define         TT_UT                   18
#define         TT_CS                   19

#define         TT_SV                   30
#define         TT_US                   40

/* --- Values for kernel task states */
#define TSK_INITIALIZED                 10
#define TSK_INACTIVE                    11
#define TSK_MARKED_FOR_STARTUP          12
#define TSK_RUNNING                     13
#define TSK_CONNECTWAIT                 14
#define TSK_VDEVSIZE                    15
#define TSK_VATTACH                     16
#define TSK_V2INFO                      17
#define TSK_VBLOCKIO                    18
#define TSK_V2BLOCKIO                   19
#define TSK_VDETACH                     20
#define TSK_VFOPEN                      21
#define TSK_VFREAD                      22
#define TSK_VFWRITE                     23
#define TSK_VFCLOSE                     24
#define TSK_VRELEASE                    25
#define TSK_VSHUTDOWN                   26
#define TSK_VRECEIVE                    27
#define TSK_VREPLY                      28
#define TSK_VNRESTART                   29
#define TSK_VNSHUTDOWN                  30
#define TSK_VNOPEN                      31
#define TSK_VNREQUEST                   32
#define TSK_VNRECEIVE                   33
#define TSK_VNCLOSE                     34
#define TSK_VBEGEXCL                    35
#define TSK_VENDEXCL                    36
#define TSK_VSUSPEND                    37
#define TSK_VWAIT                       38
#define TSK_VSLEEP                      39
#define TSK_VDIAGINIT                   40
#define TSK_VOPMSG                      41
#define TSK_LOCKED                      42
#define TSK_TERMINATED                  43
#define TSK_RUNNABLE                    44
#define TSK_ASYNOPEN                    45
#define TSK_ASYNCLOSE                   46
#define TSK_ASYNIO                      47
#define TSK_ASYNWAIT_READ               48
#define TSK_ASYNWAIT_WRITE              49
#define TSK_VCREATE                     50
#define TSK_VKILL                       51
#define TSK_IO_READ                     52
#define TSK_IO_WRITE                    53
#define TSK_IO2_READ                    54
#define TSK_IO2_WRITE                   55
#define TSK_VACKNOWLEDGE                56
#define TSK_VNCLEAR                     57
#define TSK_ASYNCNTL                    58
#define TSK_LAST                        59     

#define MAX_SUSPEND_REASONS            256
#define MAX_DEVQUEUELEN_STAT             3

#define TASK_IS_IN_NON_QUEUE            0
#define TASK_IS_IN_IOC_QUEUE            3
#define TASK_IS_IN_COM_QUEUE            4
#define TASK_IS_IN_RUN_QUEUE            6

/***************************************************************/
#if defined(_WIN32) || defined(OS2) 
/***************************************************************/
#define TASK_IS_IN_UToU_QUEUE           1
#define TASK_IS_IN_RAV_QUEUE            2
#define TASK_IS_IN_UKT_QUEUE            3
#define TASK_IS_IN_REX_QUEUE            5

#define  SQL47_CTOP                     sql47c_ctop
#define  SQL47_PTOC                     sql47c_ptoc
/***************************************************************/
#else
/***************************************************************/

#define  SQL47_CTOP                     sql47_ctop
#define  SQL47_PTOC                     sql47_ptoc
#define  NO_ERROR                       0
#define  ERROR                          1
#define  ALLOC_MEM( _MemPtr, _Size ) \
    (( *_MemPtr = (void *)malloc ( _Size )) != NULL ? NO_ERROR : ERROR )
#define  FREE_MEM( _MemPtr ) free ( _MemPtr )
/***************************************************************/
#endif
/***************************************************************/

typedef tsp_c18           XP_KEY_TYPE ;
typedef tsp_c19           XP_KEY_TYPEC ;

struct          xp_value_record
{
        tsp_int2        xp_info ;
        BOOLEAN         xp_fill2 ;
        unsigned char   xp_value_t ;
        union           of_xp_value_t
        {
                tsp_int2        xp_int2 ;
                tsp_int4        xp_int4 ;
                tsp_c8          xp_c8 ;
                tsp_c18         xp_c18 ;
                tsp_c24         xp_c24 ;
                tsp_c40         xp_c40 ;
                tsp_c64         xp_c64 ;
                tsp_cryptname   xp_crypt ;
        }  xp_type ;
 }  ;

typedef struct xp_value_record                  XP_VALUE_REC ;

typedef XP_VALUE_REC*                           XP_PVALUE_REC;
/* --- xp_key --- */

#define XP_HEADER_0             "XP_FST_XP_HEADER_0"
#define XP_DEL_KEY              "XP_FST_XP_DELETE__"


/* --- xp_value_type --- */

#define XP_INT2_TYPE            0
#define XP_INT4_TYPE            1
#define XP_C8_TYPE              2
#define XP_C18_TYPE             3
#define XP_C24_TYPE             4
#define XP_C40_TYPE             5
#define XP_C64_TYPE             6
#define XP_CRYPT_TYPE           7

/* --- xp_ret_code --- */

#define XP_OK                   0
#define XP_KEY_NOT_FOUND        1
#define XP_EOF                  2
#define XP_NOT_OK               3

/* --- xp_open_mode --- */
#define XP_CREATE     1
#define XP_OPEN_BIN   2
#define XP_OPEN_REC   4

/***************************************************************/
#if !defined(_WIN32) && !defined(OS2) 
/***************************************************************/
#define XP_HFILE                        tsp_int4 
#define XP_PHFILE                       XP_HFILE *
#define XP_RETURNCODE                   tsp_int1 
#define XP_PRETURNCODE                  XP_RETURNCODE *

#define IERR_TYPE                        0
#define ERR_TYPE                         1
#define WRN_TYPE                         2
#define INFO_TYPE                        3
/***************************************************************/
#endif
/***************************************************************/

/*
// +---------------------------------------------------------------+
// |   STATE STATISTIC                                             |
// +---------------------------------------------------------------+
*/

 typedef struct action_time_rec
   {
   ULONG                          ulCount;
   ULONG                          ulSec;
   ULONG                          ulMicroSec;
   } ACTION_TIME ;


 typedef struct state_statistic_rec
   {
   ULONG                          ulCount;
   ULONG                          ulRelSec;
   ULONG                          ulRelMicroSec;
   ULONG                          ulSec;
   ULONG                          ulMicroSec;
   } STATE_STATISTIC;

 typedef struct tsk_self_io_statistic_rec
   {
   ULONG                          ulCount;
   ULONG                          ulPageCount;
   ULONG                          ulSec;
   ULONG                          ulMicroSec;
   } TSK_SELF_IO_STATISTIC;


 typedef struct tsk_dev_io_statistic_rec
   {
   ULONG                          ulCount;
   ULONG                          ulPageCount;
   ULONG                          ulRelSec;
   ULONG                          ulRelMicroSec;
   ULONG                          ulSec;
   ULONG                          ulMicroSec;
   } TSK_DEV_IO_STATISTIC;

/*
// +---------------------------------------------------------------+
// |   TASK STATE STATISTIC                                        |
// +---------------------------------------------------------------+
*/

typedef struct task_state_statistic_rec
  {
  TSK_SELF_IO_STATISTIC           SelfIOReadStat, SelfIOWriteStat ;
  TSK_DEV_IO_STATISTIC            DevIOReadStat , DevIOWriteStat ;
  TSK_DEV_IO_STATISTIC            AsynIOReadStat, AsynIOWriteStat ;
  ULONG                           ulDevQueueLen[MAX_DEVQUEUELEN_STAT] ;
  STATE_STATISTIC                 VwaitStat , VsuspStat, VsleepStat ;
  STATE_STATISTIC                 RcvRplStat, RplRcvStat ;
  int                             iRcvRplStartSec, iRcvRplStartMicroSec;
  int  			          iRelStopSec, iRelStopMicroSec;
  ULONG                           ulRcvRplToLong ;
  } TASK_STATE_STATISTIC;

typedef struct devio_statistic_rec
  {
  ACTION_TIME                     DevRead;
  ACTION_TIME                     DevWrite;
  ULONG                           ulIOQueLen;
  ULONG                           ulMaxIOQueLen;
  } DEVIO_STATISTIC_REC ;

/*
// +---------------------------------------------------------------+
// |  TASK STATE REASON INFO                                       |
// +---------------------------------------------------------------+
/*
typedef struct vwait_state_info
  {
  PROCESS_ID                      CollTaskId;
  ULONG                           ulTabId   ;
  } VWAIT_STATE_INFO ;
 
typedef struct vsusp_state_info
  {
  PROCESS_ID                      CollTaskId;
  ULONG                           ulPno   ;
  } VSUSP_STATE_INFO ;

typedef struct io_state_info
  {
  ULONG                           ulPno;
  ULONG                           ulDevno   ;
  } IO_STATE_INFO ;
 
union STATE_INFO
{
  VWAIT_STATE_INFO                VwaitInfo ;
  VSUSP_STATE_INFO                VsuspInfo ;
  IO_STATE_INFO                   IOInfo ;
} ;

// +---------------------------------------------------------------+
// |   TASK QUEUE STATISTIC                                        |
// +---------------------------------------------------------------+
*/
typedef struct task_queue_statistic_rec
  {
#if defined(_WIN32) || defined(OS2) 
  ULONG                           ulUKTQueCount;
  ULONG                           ulUToUQueCount;
#else
  ULONG                           ulXXXQueCount;
  ULONG                           ulIOCQueCount;
#endif
  ULONG                           ulCOMQueCount;
  } QUEUE_STATISTIC;

/*
// +---------------------------------------------------------------+
// |   TASK PRIO STATISTIC                                         |
// +---------------------------------------------------------------+
*/
typedef struct task_prio_statistic_rec
  {
  ULONG                           ulTotalCount;
#if defined(_WIN32) || defined(OS2) 
  ULONG                           ulOtherUkt;
#else
  ULONG                           ulOtherUkp;
#endif
  } PRIO_STATISTIC;



#define MSG_ALL(x) { sql60c_msg_6 x ; }
#define MSG_CD(x)  { sql60c_msg_7 x ; }
#define MSG_D(x)   { sql60c_msg_8 x ; }
#define MSG_DEB(x) { sql60c_msg_9 x ; }
#ifdef	DEBUG
#define MSG_DBG(x) { sql60c_msg_8 x ; }
#else
#define MSG_DBG(x) { }
#endif
#define MSG_O(x)   { sqloutwrite x ; }

/*
 *  Macro to take time of 'to_measure' - action
 */

#define TAKE_ABS_TIME(_StateStat, _ToMeasure)                                 \
          { if ( IS_TIME_MEASURE_ACTIVE )                                     \
              { int  _BegSec, _BegMicroSec, _EndSec, _EndMicroSec;            \
                VCLOCK_PROTOTYPE ;                                            \
                                                                              \
                vclock ( &_BegSec, &_BegMicroSec );                           \
                _ToMeasure;                                                   \
                vclock ( &_EndSec, &_EndMicroSec );                           \
                TIME_DIFF(_BegSec         , _BegMicroSec,                     \
                          _EndSec         , _EndMicroSec,                     \
                          _StateStat.ulSec, _StateStat.ulMicroSec) ;          \
              }                                                               \
            else                                                              \
             _ToMeasure;                                                      \
          }


#define TAKE_REL_ABS_TIME(_pTaskCtrl, _StateStat, _ToMeasure)                 \
          { if ( IS_TIME_MEASURE_ACTIVE )                                     \
              { int  _BegSec, _BegMicroSec, _EndSec, _EndMicroSec;            \
                VCLOCK_PROTOTYPE ;                                            \
                                                                              \
                vclock ( &_BegSec, &_BegMicroSec );                           \
                _ToMeasure;                                                   \
                vclock ( &_EndSec, &_EndMicroSec );                           \
                TIME_DIFF(_BegSec         , _BegMicroSec,                     \
                          _EndSec         , _EndMicroSec,                     \
                          _StateStat.ulSec, _StateStat.ulMicroSec) ;          \
                TIME_DIFF(_BegSec            , _BegMicroSec,                  \
                          _pTaskCtrl->TaskStateStat.iRelStopSec,              \
                          _pTaskCtrl->TaskStateStat.iRelStopMicroSec,         \
                          _StateStat.ulRelSec, _StateStat.ulRelMicroSec) ;    \
              }                                                               \
            else                                                              \
             _ToMeasure;                                                      \
          }


#define TIME_DIFF(_start_sec, _start_ms, _stop_sec, _stop_ms, _sec, _ms ) \
  { int _time_diff_sec = _stop_sec - _start_sec ,      \
        _time_diff_ms  = _stop_ms  - _start_ms  ;      \
    if ( _time_diff_ms < 0 )                           \
      { _time_diff_sec--; _time_diff_ms += 1000000 ; } \ 
    _sec += _time_diff_sec ;                           \
    _ms  += _time_diff_ms  ;                           \
    if ( _ms >= 1000000 )                              \            
      { _sec++; _ms -= 1000000 ; }                     \
  }

/*
 * ================================= ENDE ====================================*
 */

.CM *-END-* code ----------------------------------------
.SP 2
***********************************************************
.PA
