root/src/dps8/threadz.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 07828852-f630-11ec-a049-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2013-2019 Charles Anthony
   9  * Copyright (c) 2021-2024 The DPS8M Development Team
  10  *
  11  * This software is made available under the terms of the ICU License.
  12  * See the LICENSE.md file at the top-level directory of this distribution.
  13  *
  14  * ---------------------------------------------------------------------------
  15  */
  16 
  17 #define tdbg
  18 
  19 #define use_spinlock
  20 
  21 // Wrapper around pthreads
  22 
  23 #if defined(__APPLE__)
  24 # include <mach/mach.h>
  25 # include <mach/mach_time.h>
  26 #endif /* if defined(__APPLE__) */
  27 
  28 #include <pthread.h>
  29 
  30 
  31 
  32 
  33 
  34 
  35 
  36 
  37 
  38 
  39 
  40 
  41 
  42 
  43 
  44 
  45 
  46 
  47 
  48 
  49 
  50 
  51 
  52 
  53 
  54 
  55 
  56 
  57 
  58 
  59 
  60 
  61 
  62 
  63 
  64 
  65 
  66 
  67 
  68 
  69 
  70 
  71 
  72 
  73 
  74 
  75 
  76 
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 
  85 
  86 
  87 
  88 
  89 
  90 #if !defined(LOCKLESS)
  91 extern pthread_rwlock_t mem_lock;
  92 #endif /* if !defined(LOCKLESS) */
  93 
  94 // local lock
  95 void lock_ptr (pthread_mutex_t * lock);
  96 void unlock_ptr (pthread_mutex_t * lock);
  97 
  98 // libuv resource lock
  99 void lock_libuv (void);
 100 void unlock_libuv (void);
 101 bool test_libuv_lock (void);
 102 
 103 // resource lock
 104 #if !defined(QUIET_UNUSED)
 105 void lock_simh (void);
 106 void unlock_simh (void);
 107 #endif /* if !defined(QUIET_UNUSED) */
 108 
 109 // atomic memory lock
 110 #if !defined(LOCKLESS)
 111 bool get_rmw_lock (void);
 112 void lock_rmw (void);
 113 void lock_mem_rd (void);
 114 void lock_mem_wr (void);
 115 void unlock_rmw (void);
 116 void unlock_mem (void);
 117 void unlock_mem_force (void);
 118 #endif /* if !defined(LOCKLESS) */
 119 
 120 // scu lock
 121 void lock_scu (void);
 122 void unlock_scu (void);
 123 
 124 // synchronous clock lock
 125 // void lockSync (void);
 126 // void unlockSync (void);
 127 
 128 // iom lock
 129 void lock_iom (void);
 130 void unlock_iom (void);
 131 
 132 // testing lock
 133 #if defined(TESTING)
 134 void lock_tst (void);
 135 void unlock_tst (void);
 136 bool test_tst_lock (void);
 137 #endif /* if defined(TESTING) */
 138 
 139 // CPU threads
 140 struct cpuThreadz_t
 141   {
 142     pthread_t cpuThread;
 143     int cpuThreadArg;
 144 
 145     // run/stop switch
 146     bool run;
 147     pthread_cond_t runCond;
 148     pthread_mutex_t runLock;
 149 
 150     // DIS sleep
 151 #if defined (USE_MONOTONIC)
 152 # if !defined(__APPLE__) && defined (CLOCK_MONOTONIC)
 153     clockid_t sleepClock;
 154     pthread_condattr_t sleepCondAttr;
 155 # endif /* if !defined(__APPLE__) && defined (CLOCK_MONOTONIC) */
 156 #endif /* if defined (USE_MONOTONIC) */
 157     pthread_cond_t sleepCond;
 158 
 159   };
 160 extern struct cpuThreadz_t cpuThreadz [N_CPU_UNITS_MAX];
 161 
 162 void createCPUThread (uint cpuNum);
 163 void stopCPUThread(void);
 164 #if defined(THREADZ)
 165 void cpuRunningWait (void);
 166 #endif /* if defined(THREADZ) */
 167 unsigned long sleepCPU (unsigned long usec);
 168 void wakeCPU (uint cpuNum);
 169 
 170 #if defined(IO_THREADZ)
 171 // IOM threads
 172 
 173 struct iomThreadz_t
 174   {
 175     pthread_t iomThread;
 176     int iomThreadArg;
 177 
 178     volatile bool ready;
 179 
 180     // interrupt wait
 181     bool intr;
 182     pthread_cond_t intrCond;
 183     pthread_mutex_t intrLock;
 184 
 185 # if defined(tdbg)
 186     // debugging
 187     int inCnt;
 188     int outCnt;
 189 # endif /* if defined(tdbg) */
 190   };
 191 extern struct iomThreadz_t iomThreadz [N_IOM_UNITS_MAX];
 192 
 193 void createIOMThread (uint iomNum);
 194 void iomInterruptWait (void);
 195 void iomInterruptDone (void);
 196 void iomDoneWait (uint iomNum);
 197 void setIOMInterrupt (uint iomNum);
 198 void iomRdyWait (uint iomNum);
 199 
 200 // Channel threads
 201 
 202 struct chnThreadz_t
 203   {
 204     bool started;
 205 
 206     pthread_t chnThread;
 207     int chnThreadArg;
 208 
 209     // waiting at the gate
 210     volatile bool ready;
 211 
 212     // connect wait
 213     bool connect;
 214     pthread_cond_t connectCond;
 215     pthread_mutex_t connectLock;
 216 
 217 # if defined(tdbg)
 218     // debugging
 219     int inCnt;
 220     int outCnt;
 221 # endif /* if defined(tdbg) */
 222   };
 223 extern struct chnThreadz_t chnThreadz [N_IOM_UNITS_MAX] [MAX_CHANNELS];
 224 
 225 void createChnThread (uint iomNum, uint chnNum, const char * devTypeStr);
 226 void chnConnectWait (void);
 227 void chnConnectDone (void);
 228 void setChnConnect (uint iomNum, uint chnNum);
 229 void chnRdyWait (uint iomNum, uint chnNum);
 230 #endif /* if defined(IO_THREADZ) */
 231 
 232 void initThreadz (void);
 233 void setSignals (void);
 234 
 235 #if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
 236 extern pthread_cond_t iomCond;
 237 extern pthread_mutex_t iom_start_lock;
 238 #endif /* if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD) */

/* [previous][next][first][last][top][bottom][index][help] */