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-2022 The DPS8M Development Team
  10  *
  11  * All rights reserved.
  12  *
  13  * This software is made available under the terms of the ICU
  14  * License, version 1.8.1 or later.  For more details, see the
  15  * LICENSE.md file at the top-level directory of this distribution.
  16  *
  17  * ---------------------------------------------------------------------------
  18  */
  19 
  20 #define tdbg
  21 
  22 #define use_spinlock
  23 
  24 // Wrapper around pthreads
  25 
  26 #ifdef __APPLE__
  27 # include <mach/mach.h>
  28 # include <mach/mach_time.h>
  29 #endif /* ifdef __APPLE__ */
  30 
  31 #include <pthread.h>
  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 
  91 
  92 
  93 #ifndef LOCKLESS
  94 extern pthread_rwlock_t mem_lock;
  95 #endif
  96 
  97 // local lock
  98 void lock_ptr (pthread_mutex_t * lock);
  99 void unlock_ptr (pthread_mutex_t * lock);
 100 
 101 // libuv resource lock
 102 void lock_libuv (void);
 103 void unlock_libuv (void);
 104 bool test_libuv_lock (void);
 105 
 106 // resource lock
 107 #ifndef QUIET_UNUSED
 108 void lock_simh (void);
 109 void unlock_simh (void);
 110 #endif
 111 
 112 // atomic memory lock
 113 #ifndef LOCKLESS
 114 bool get_rmw_lock (void);
 115 void lock_rmw (void);
 116 void lock_mem_rd (void);
 117 void lock_mem_wr (void);
 118 void unlock_rmw (void);
 119 void unlock_mem (void);
 120 void unlock_mem_force (void);
 121 #endif
 122 
 123 // scu lock
 124 void lock_scu (void);
 125 void unlock_scu (void);
 126 
 127 // iom lock
 128 void lock_iom (void);
 129 void unlock_iom (void);
 130 
 131 // testing lock
 132 #ifdef TESTING
 133 void lock_tst (void);
 134 void unlock_tst (void);
 135 bool test_tst_lock (void);
 136 #endif
 137 
 138 #ifdef __APPLE__
 139 int rtsched_thread(pthread_t pthread);
 140 #endif /* ifdef __APPLE__ */
 141 
 142 // CPU threads
 143 struct cpuThreadz_t
 144   {
 145     pthread_t cpuThread;
 146     int cpuThreadArg;
 147 
 148     // run/stop switch
 149     bool run;
 150     pthread_cond_t runCond;
 151     pthread_mutex_t runLock;
 152 
 153     // DIS sleep
 154 #ifdef USE_MONOTONIC
 155 # if !defined __APPLE__ && defined (CLOCK_MONOTONIC)
 156     clockid_t sleepClock;
 157     pthread_condattr_t sleepCondAttr;
 158 # endif
 159 #endif
 160     pthread_cond_t sleepCond;
 161 
 162   };
 163 extern struct cpuThreadz_t cpuThreadz [N_CPU_UNITS_MAX];
 164 
 165 void createCPUThread (uint cpuNum);
 166 void stopCPUThread(void);
 167 #ifdef THREADZ
 168 void cpuRunningWait (void);
 169 #endif
 170 unsigned long sleepCPU (unsigned long usec);
 171 void wakeCPU (uint cpuNum);
 172 
 173 #ifdef IO_THREADZ
 174 // IOM threads
 175 
 176 struct iomThreadz_t
 177   {
 178     pthread_t iomThread;
 179     int iomThreadArg;
 180 
 181     volatile bool ready;
 182 
 183     // interrupt wait
 184     bool intr;
 185     pthread_cond_t intrCond;
 186     pthread_mutex_t intrLock;
 187 
 188 # ifdef tdbg
 189     // debugging
 190     int inCnt;
 191     int outCnt;
 192 # endif
 193   };
 194 extern struct iomThreadz_t iomThreadz [N_IOM_UNITS_MAX];
 195 
 196 void createIOMThread (uint iomNum);
 197 void iomInterruptWait (void);
 198 void iomInterruptDone (void);
 199 void iomDoneWait (uint iomNum);
 200 void setIOMInterrupt (uint iomNum);
 201 void iomRdyWait (uint iomNum);
 202 
 203 // Channel threads
 204 
 205 struct chnThreadz_t
 206   {
 207     bool started;
 208 
 209     pthread_t chnThread;
 210     int chnThreadArg;
 211 
 212     // waiting at the gate
 213     volatile bool ready;
 214 
 215     // connect wait
 216     bool connect;
 217     pthread_cond_t connectCond;
 218     pthread_mutex_t connectLock;
 219 
 220 # ifdef tdbg
 221     // debugging
 222     int inCnt;
 223     int outCnt;
 224 # endif
 225   };
 226 extern struct chnThreadz_t chnThreadz [N_IOM_UNITS_MAX] [MAX_CHANNELS];
 227 
 228 void createChnThread (uint iomNum, uint chnNum, const char * devTypeStr);
 229 void chnConnectWait (void);
 230 void chnConnectDone (void);
 231 void setChnConnect (uint iomNum, uint chnNum);
 232 void chnRdyWait (uint iomNum, uint chnNum);
 233 
 234 #endif
 235 
 236 void initThreadz (void);
 237 void setSignals (void);
 238 
 239 #ifdef IO_ASYNC_PAYLOAD_CHAN_THREAD
 240 extern pthread_cond_t iomCond;
 241 extern pthread_mutex_t iom_start_lock;
 242 #endif

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