Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Standard Library internals
0003  *
0004  * @file nstd_int.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 #ifndef NSTD_INT_H
0036 #define NSTD_INT_H
0037 
0038 #ifdef  __cplusplus
0039 extern "C" {
0040 #endif
0041 
0042 /*---------------------------Includes-----------------------------------*/
0043 #include <ndrstandard.h>
0044 #include <inicfg.h>
0045 #include <sys_primitives.h>
0046 #include <ndebugcmn.h>
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049     
0050 #define NDRX_TPLOGCONFIG_VERSION_INC            0x00000001  /**< increment version */
0051 /*---------------------------Enums--------------------------------------*/
0052 /*---------------------------Typedefs-----------------------------------*/
0053 /**
0054  * Feedback alloc block memory block
0055  * TODO: move to internal header
0056  */
0057 typedef struct ndrx_fpablock ndrx_fpablock_t;
0058 struct  ndrx_fpablock
0059 {
0060     int magic;              /**< magic constant                             */
0061     int poolno;             /**< slot number to which block belongs         */
0062     int flags;              /**< flags for given alloc block                */
0063     volatile ndrx_fpablock_t *next;  /**< Next free block                   */
0064 };
0065 
0066 /**
0067  * One size stack for allocator
0068  */
0069 typedef struct ndrx_fpastack ndrx_fpapool_t;
0070 struct  ndrx_fpastack
0071 {
0072     int bsize;                       /**< this does not include header size          */
0073     int flags;                       /**< flags for given entry                      */
0074     volatile int num_blocks;         /**< min number of blocks int given size range  */
0075     volatile int cur_blocks;         /**< Number of blocks allocated                 */
0076     volatile long allocs;            /**< number of allocs done, for stats           */
0077     volatile ndrx_fpablock_t *stack; /**< stack head                                 */
0078     NDRX_SPIN_LOCKDECL(spinlock);    /**< spinlock for protecting given size         */
0079 };
0080 
0081 /**
0082  * Logging file sink.
0083  * Hashing by file names. If process opens a log it shall search this file sink
0084  * and if file exists, the use it, or create new.
0085  * 
0086  * After normally forced logging close shall done. Which would include
0087  * un-init of the LCF.
0088  * 
0089  * If some thread at some point gets the sink, it shall be valid
0090  * as it must have reference to it perior work. And it will not be removed
0091  * if refcount > 0.
0092  */
0093 typedef struct 
0094 {
0095     char fname[PATH_MAX+1];  /**< The actual file name   */
0096     char fname_org[PATH_MAX+1];  /**< Org filename, before switching to stderr  */
0097     
0098     int writters;   /**< Number of concurrent writters      */
0099     int chwait;     /**< Some thread waits for on wait_cond */
0100     FILE *fp; /**< actual file open for writting            */
0101     
0102     NDRX_SPIN_LOCKDECL (writters_lock);   /**< writters/chwait update spinlock */
0103     MUTEX_LOCKDECLN(busy_lock);          /**< Object is busy, for entry        */
0104     MUTEX_LOCKDECLN(change_lock);        /**< If doing chagnes to the object   */
0105     pthread_cond_t   change_wait;  /**< wait on this if have writters          */
0106     
0107     MUTEX_LOCKDECLN(line_lock);        /**< Line locking (for MT & single file */
0108     
0109     
0110     int refcount;  /**< Number of logger have references, protected by change_lock */
0111     long flags;     /**< is this process level? Use mutex?  */
0112     
0113     int org_is_mkdir;   /**< initial setting of mkdir, used for logrotate      */
0114     int org_buffer_size;/**< initail setting of io buffer size                 */
0115     EX_hash_handle hh; /**< makes this structure hashable                      */
0116     
0117 } ndrx_debug_file_sink_t;
0118 
0119 /*---------------------------Globals------------------------------------*/
0120 /*---------------------------Statics------------------------------------*/
0121 /*---------------------------Prototypes---------------------------------*/
0122     
0123 extern NDRX_API int ndrx_inicfg_get_subsect_int(ndrx_inicfg_t *cfg, 
0124         char **resources, char *section, ndrx_inicfg_section_keyval_t **out);
0125 
0126 extern NDRX_API void ndrx_fpstats(int poolno, ndrx_fpapool_t *p_stats);
0127 
0128 extern NDRX_API void ndrx_init_fail_banner(void);
0129 
0130 extern NDRX_API ndrx_debug_file_sink_t* ndrx_debug_get_sink(const char *fname, int do_lock, 
0131         ndrx_debug_t *dbg_ptr, int *p_ret);
0132 
0133 extern NDRX_API int ndrx_debug_changename(const char *toname, int do_lock, 
0134         ndrx_debug_t *dbg_ptr, ndrx_debug_file_sink_t* fileupdate);
0135 extern NDRX_API void ndrx_debug_force_closeall(void);
0136 extern NDRX_API void ndrx_debug_refcount(int *sinks, int *refs);
0137 extern NDRX_API int ndrx_debug_unset_sink(ndrx_debug_file_sink_t* mysink, int do_lock, int force);
0138 extern NDRX_API void ndrx_debug_addref(ndrx_debug_file_sink_t* mysink);
0139 extern NDRX_API int ndrx_debug_reopen_all(void);
0140 
0141 extern NDRX_API int tplogconfig_int(int logger, int lev, const char *debug_string, const char *module, 
0142         const char *new_file, long flags);
0143 extern NDRX_API int ndrx_debug_is_proc_stderr(void);
0144 extern NDRX_API void ndrx_debug_proc_link_ndrx(long flags);
0145 
0146 extern NDRX_API FILE *ndrx_dbg_fopen_mkdir(const char *filename, const char *mode, 
0147         ndrx_debug_t *dbg_ptr, ndrx_debug_file_sink_t *fsink);
0148 extern NDRX_API int ndrx_init_parse_line(const char *dbgstr, ndrx_debug_t *dbg_ptr, 
0149         char *tmpfname, size_t tmpfnamesz, int *do_match, char *match_nm);
0150 
0151 extern NDRX_API void ndrx_debug_lock(ndrx_debug_file_sink_t* mysink);
0152 extern NDRX_API void ndrx_debug_unlock(ndrx_debug_file_sink_t* mysink);
0153 
0154 
0155 #ifdef  __cplusplus
0156 }
0157 #endif
0158 
0159 #endif  /* NSTD_INT_H */
0160 
0161 /* vim: set ts=4 sw=4 et smartindent: */