Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Enduro/X Standard library thread local storage
0003  *
0004  * @file nstd_tls.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 #ifndef NSTD_TLS_H
0035 #define NSTD_TLS_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <pthread.h>
0043 #include <nerror.h>
0044 #include <nstdutil.h>
0045 #include <ndebugcmn.h>
0046 /*---------------------------Externs------------------------------------*/
0047 /*---------------------------Macros-------------------------------------*/
0048     
0049 #define ERROR_BUFFER_POLL            1024
0050 #define NSTD_TLS_MAGIG          0xa27f0f24
0051     
0052     
0053 #define NSTD_TLS_ENTRY  if (NDRX_UNLIKELY(NULL==G_nstd_tls)) \
0054         {G_nstd_tls = (nstd_tls_t *)ndrx_nstd_tls_new(EXTRUE, EXTRUE);};
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 
0058 /**
0059  * NSTD Library TLS
0060  */
0061 typedef struct
0062 {
0063     int magic; /* have some magic for context data */
0064     
0065     /* ndebug.c */
0066     long M_threadnr; /**< Current thread nr */
0067     long M_threadnr_logopen; /**< Current thread nr, this is where log is open */
0068     
0069     /* nerror.c */
0070     char M_nstd_error_msg_buf[MAX_ERROR_LEN+1];
0071     int M_nstd_error;
0072     char errbuf[MAX_ERROR_LEN+1];
0073     
0074     /* nstdutil.c */
0075     char util_buf1[20][20];
0076     char util_buf2[20][20];
0077     char util_text[20][128];
0078     
0079     /* sys_emqueue.c */
0080     char emq_x[512];
0081     
0082     /* sys_poll.c: */
0083     int M_last_err;
0084     char M_last_err_msg[1024];  /* Last error message */
0085     char poll_strerr[ERROR_BUFFER_POLL];
0086     
0087     /* ndebug.c */
0088     ndrx_debug_t threadlog_tp; /* thread private logging */
0089     
0090     ndrx_debug_t requestlog_tp; /* logfile on per request-basis */
0091 
0092     ndrx_debug_t threadlog_ndrx; /* thread private logging */  
0093     ndrx_debug_t requestlog_ndrx; /* logfile on per request-basis */
0094     
0095     ndrx_debug_t threadlog_ubf; /* thread private logging */  
0096     ndrx_debug_t requestlog_ubf; /* logfile on per request-basis */
0097     
0098     int is_auto; /* is this auto-allocated (thus do the auto-free) */
0099     /* we should have lock inside */
0100     pthread_mutex_t mutex; /* initialize later with PTHREAD_MUTEX_INITIALIZER */
0101     
0102     int user_field_1; /* used for testing where TLS is needed... */
0103     
0104     unsigned int rand_seed; /**< Random seed used by thread             */
0105     int rand_init;  /**< Has random initialized?                        */
0106     
0107 } nstd_tls_t;
0108 
0109 /*---------------------------Globals------------------------------------*/
0110 extern NDRX_API __thread nstd_tls_t *G_nstd_tls; /* Enduro/X standard library TLS */
0111 /*---------------------------Statics------------------------------------*/
0112 /*---------------------------Prototypes---------------------------------*/
0113     
0114 #ifdef  __cplusplus
0115 }
0116 #endif
0117 
0118 #endif  /* NSTD_CONTEXT_H */
0119 
0120 /* vim: set ts=4 sw=4 et smartindent: */