Nife version Beta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

227 lines
6.5 KiB

  1. /* Copyright (C) 2011-2022 Patrick H. E. Foubet - S.E.R.I.A.N.E.
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or any
  5. later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>
  12. *******************************************************************/
  13. /* mth.h : for multi-threading implementation */
  14. extern void TH_init(void);
  15. #ifndef __NIFE_MTH_H__
  16. #define __NIFE_MTH_H__
  17. #include <stdio.h>
  18. #include <stdint.h>
  19. #include <setjmp.h>
  20. #include <pthread.h>
  21. #define LSTACKL 512
  22. #define LSTACKC 512
  23. #define LSTACKS 512
  24. #define MAXSTRING 512
  25. #define NBTRSUITE 10
  26. #define LBUF 512
  27. #define VIDE ((void*)NULL)
  28. #ifdef _MULTI_THREADING_
  29. extern pthread_key_t k_Base, k_StkN, k_FIns, k_NetK, k_NLig, k_NTab, k_Vars,
  30. k_FTyp, k_Doub, k_Echo, k_StkL, k_iStL, k_StkC, k_iStC, k_bufC, k_Run,
  31. k_WPid, k_fEnC, k_sEnC, k_inSP, k_iTs, k_FdIn, k_bufP, k_bufP2, k_trSu,
  32. k_EnvI, k_modPr;
  33. #define StackN *((void**)pthread_getspecific(k_StkN))
  34. #define _MODIF_STACKN_(x) *((void**)pthread_getspecific(k_StkN))=x
  35. #define _ADDR_STACKN_ (void**)pthread_getspecific(k_StkN)
  36. #define DOUBLE *((bool*)pthread_getspecific(k_Doub))
  37. #define _MODIF_DOUBLE_(x) *((bool*)pthread_getspecific(k_Doub))=x
  38. #define MODEPR *((bool*)pthread_getspecific(k_modPr))
  39. #define _MODIF_MODEPR_(x) *((bool*)pthread_getspecific(k_modPr))=x
  40. #define ECHOOFF *((bool*)pthread_getspecific(k_Echo))
  41. #define _MODIF_ECHOOFF_(x) *((bool*)pthread_getspecific(k_Echo))=x
  42. #define NBLIG *((short*)pthread_getspecific(k_NLig))
  43. #define _MODIF_NBLIG_(x) *((short*)pthread_getspecific(k_NLig))=x
  44. #define NBTAB *((short*)pthread_getspecific(k_NTab))
  45. #define _MODIF_NBTAB_(x) *((short*)pthread_getspecific(k_NTab))=x
  46. #define VARS *((short*)pthread_getspecific(k_Vars))
  47. #define _MODIF_VARS_(x) *((short*)pthread_getspecific(k_Vars))=x
  48. #define FCT_TYP *((short*)pthread_getspecific(k_FTyp))
  49. #define _MODIF_FCT_TYP_(x) *((short*)pthread_getspecific(k_FTyp))=x
  50. #define FCT_INST *((void**)pthread_getspecific(k_FIns))
  51. #define _MODIF_FCT_INST_(x) *((void**)pthread_getspecific(k_FIns))=x
  52. #define NetKey *((uint32_t*)pthread_getspecific(k_NetK))
  53. #define _MODIF_NetKey_(x) *((uint32_t*)pthread_getspecific(k_NetK))=x
  54. #define _ADDV_NetKey_ pthread_getspecific(k_NetK)
  55. #define stackL ((bool*)pthread_getspecific(k_StkL))
  56. #define i_StackL *((int*)pthread_getspecific(k_iStL))
  57. #define _MODIF_i_StackL_(x) *((int*)pthread_getspecific(k_iStL))=x
  58. #define stackC ((char**)pthread_getspecific(k_StkC))
  59. #define i_StackC *((int*)pthread_getspecific(k_iStC))
  60. #define _MODIF_i_StackC_(x) *((int*)pthread_getspecific(k_iStC))=x
  61. #define bufC ((char*)pthread_getspecific(k_bufC))
  62. #define bufP ((char*)pthread_getspecific(k_bufP))
  63. #define bufP2 ((char*)pthread_getspecific(k_bufP2))
  64. #define traiteSuite ((PFC*)pthread_getspecific(k_trSu))
  65. #define RUN *((bool*)pthread_getspecific(k_Run))
  66. #define _MODIF_RUN_(x) *((bool*)pthread_getspecific(k_Run))=x
  67. #define WAITPID *((bool*)pthread_getspecific(k_WPid))
  68. #define _MODIF_WAITPID_(x) *((bool*)pthread_getspecific(k_WPid))=x
  69. #define stringEnCours *((bool*)pthread_getspecific(k_sEnC))
  70. #define _MODIF_stringEnCours_(x) *((bool*)pthread_getspecific(k_sEnC))=x
  71. #define fctEnCours *((bool*)pthread_getspecific(k_fEnC))
  72. #define _MODIF_fctEnCours_(x) *((bool*)pthread_getspecific(k_fEnC))=x
  73. #define inSonProc *((bool*)pthread_getspecific(k_inSP))
  74. #define _MODIF_inSonProc_(x) *((bool*)pthread_getspecific(k_inSP))=x
  75. #define FD_IN *((int*)pthread_getspecific(k_FdIn))
  76. #define _MODIF_FD_IN_(x) *((int*)pthread_getspecific(k_FdIn))=x
  77. #define iTS *((int*)pthread_getspecific(k_iTs))
  78. #define _MODIF_iTS_(x) *((int*)pthread_getspecific(k_iTs))=x
  79. #define ENV_INT (jmp_buf*)pthread_getspecific(k_EnvI)
  80. #else /* *************** NOT _MULTI_THREADING_ ******************** */
  81. extern void * G_TStackN[];
  82. extern char ** G_TStackC[];
  83. extern int G_TiStackC[];
  84. extern bool * G_TStackL[];
  85. extern int G_TiStackL[];
  86. extern int G_i_TStackN;
  87. extern int G_i_TStackC;
  88. extern int G_i_TStackL;
  89. extern void * G_StackN;
  90. extern int G_Double;
  91. extern short G_ModePr;
  92. extern int G_EchoOff;
  93. extern int G_NBTAB;
  94. extern int G_NBLIG;
  95. extern short G_VARS;
  96. extern short G_FCT_TYP;
  97. extern void * G_F_INS;
  98. extern uint32_t G_NetKey;
  99. extern bool * G_stackL;
  100. extern int G_i_stackL;
  101. extern char ** G_stackC;
  102. extern int G_i_stackC;
  103. extern char G_bufC[];
  104. extern short G_Run;
  105. extern short G_WAITPID;
  106. extern short G_strEnCours;
  107. extern short G_fctEnCours;
  108. extern short G_inSonProc;
  109. extern int G_FD_IN;
  110. extern int G_iTS;
  111. extern char G_bufP[];
  112. extern char G_bufP2[];
  113. extern PFC G_traiteSuite[];
  114. /* a regler */
  115. extern jmp_buf G_ENV_INT;
  116. #define RUN G_Run
  117. #define _MODIF_RUN_(x) G_Run=(x)
  118. #define WAITPID G_WAITPID
  119. #define _MODIF_WAITPID_(x) G_WAITPID=(x)
  120. #define stringEnCours G_strEnCours
  121. #define _MODIF_stringEnCours_(x) G_strEnCours=(x)
  122. #define fctEnCours G_fctEnCours
  123. #define _MODIF_fctEnCours_(x) G_fctEnCours=(x)
  124. #define inSonProc G_inSonProc
  125. #define _MODIF_inSonProc_(x) G_inSonProc=(x)
  126. #define FD_IN G_FD_IN
  127. #define _MODIF_FD_IN_(x) G_FD_IN=(x)
  128. #define iTS G_iTS
  129. #define _MODIF_iTS_(x) G_iTS=(x)
  130. #define stackL G_stackL
  131. #define i_StackL G_i_stackL
  132. #define _MODIF_i_StackL_(x) G_i_stackL=(x)
  133. #define stackC G_stackC
  134. #define i_StackC G_i_stackC
  135. #define _MODIF_i_StackC_(x) G_i_stackC=(x)
  136. #define bufC G_bufC
  137. #define bufP G_bufP
  138. #define bufP2 G_bufP2
  139. #define traiteSuite G_traiteSuite
  140. #define StackN G_StackN
  141. #define _MODIF_STACKN_(x) G_StackN=(x)
  142. #define _ADDR_STACKN_ &G_StackN
  143. #define DOUBLE G_Double
  144. #define _MODIF_DOUBLE_(x) G_Double=(x)
  145. #define MODEPR G_ModePr
  146. #define _MODIF_MODEPR_(x) G_ModePr=(x)
  147. #define ECHOOFF G_EchoOff
  148. #define _MODIF_ECHOOFF_(x) G_EchoOff=(x)
  149. #define NBLIG G_NBLIG
  150. #define _MODIF_NBLIG_(x) G_NBLIG=(x)
  151. #define NBTAB G_NBTAB
  152. #define _MODIF_NBTAB_(x) G_NBTAB=(x)
  153. #define VARS G_VARS
  154. #define _MODIF_VARS_(x) G_VARS=(x)
  155. #define FCT_TYP G_FCT_TYP
  156. #define _MODIF_FCT_TYP_(x) G_FCT_TYP=(x)
  157. #define FCT_INST G_F_INS
  158. #define _MODIF_FCT_INST_(x) G_F_INS=(x)
  159. #define NetKey G_NetKey
  160. #define _MODIF_NetKey_(x) G_NetKey=(x)
  161. #define _ADDV_NetKey_ (void*)&G_NetKey
  162. #define ENV_INT G_ENV_INT
  163. #endif /* _MULTI_THREADING_ */
  164. #endif