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 // iom lock
 125 void lock_iom (void);
 126 void unlock_iom (void);
 127 
 128 // testing lock
 129 #if defined(TESTING)
 130 void lock_tst (void);
 131 void unlock_tst (void);
 132 bool test_tst_lock (void);
 133 #endif /* if defined(TESTING) */
 134 
 135 // CPU threads
 136 struct cpuThreadz_t
 137   {
 138     pthread_t cpuThread;
 139     int cpuThreadArg;
 140 
 141     // run/stop switch
 142     bool run;
 143     pthread_cond_t runCond;
 144     pthread_mutex_t runLock;
 145 
 146     // DIS sleep
 147 #if defined (USE_MONOTONIC)
 148 # if !defined(__APPLE__) && defined (CLOCK_MONOTONIC)
 149     clockid_t sleepClock;
 150     pthread_condattr_t sleepCondAttr;
 151 # endif /* if !defined(__APPLE__) && defined (CLOCK_MONOTONIC) */
 152 #endif /* if defined (USE_MONOTONIC) */
 153     pthread_cond_t sleepCond;
 154 
 155   };
 156 extern struct cpuThreadz_t cpuThreadz [N_CPU_UNITS_MAX];
 157 
 158 void createCPUThread (uint cpuNum);
 159 void stopCPUThread(void);
 160 #if defined(THREADZ)
 161 void cpuRunningWait (void);
 162 #endif /* if defined(THREADZ) */
 163 unsigned long sleepCPU (unsigned long usec);
 164 void wakeCPU (uint cpuNum);
 165 
 166 #if defined(IO_THREADZ)
 167 // IOM threads
 168 
 169 struct iomThreadz_t
 170   {
 171     pthread_t iomThread;
 172     int iomThreadArg;
 173 
 174     volatile bool ready;
 175 
 176     // interrupt wait
 177     bool intr;
 178     pthread_cond_t intrCond;
 179     pthread_mutex_t intrLock;
 180 
 181 # if defined(tdbg)
 182     // debugging
 183     int inCnt;
 184     int outCnt;
 185 # endif /* if defined(tdbg) */
 186   };
 187 extern struct iomThreadz_t iomThreadz [N_IOM_UNITS_MAX];
 188 
 189 void createIOMThread (uint iomNum);
 190 void iomInterruptWait (void);
 191 void iomInterruptDone (void);
 192 void iomDoneWait (uint iomNum);
 193 void setIOMInterrupt (uint iomNum);
 194 void iomRdyWait (uint iomNum);
 195 
 196 // Channel threads
 197 
 198 struct chnThreadz_t
 199   {
 200     bool started;
 201 
 202     pthread_t chnThread;
 203     int chnThreadArg;
 204 
 205     // waiting at the gate
 206     volatile bool ready;
 207 
 208     // connect wait
 209     bool connect;
 210     pthread_cond_t connectCond;
 211     pthread_mutex_t connectLock;
 212 
 213 # if defined(tdbg)
 214     // debugging
 215     int inCnt;
 216     int outCnt;
 217 # endif /* if defined(tdbg) */
 218   };
 219 extern struct chnThreadz_t chnThreadz [N_IOM_UNITS_MAX] [MAX_CHANNELS];
 220 
 221 void createChnThread (uint iomNum, uint chnNum, const char * devTypeStr);
 222 void chnConnectWait (void);
 223 void chnConnectDone (void);
 224 void setChnConnect (uint iomNum, uint chnNum);
 225 void chnRdyWait (uint iomNum, uint chnNum);
 226 #endif /* if defined(IO_THREADZ) */
 227 
 228 void initThreadz (void);
 229 void setSignals (void);
 230 
 231 #if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
 232 extern pthread_cond_t iomCond;
 233 extern pthread_mutex_t iom_start_lock;
 234 #endif /* if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD) */

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