emlxs_thread.c (fcf3ce44) | emlxs_thread.c (291a2b48) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 6 unchanged lines hidden (view full) --- 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 6 unchanged lines hidden (view full) --- 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* |
23 * Copyright 2008 Emulex. All rights reserved. | 23 * Copyright 2009 Emulex. All rights reserved. |
24 * Use is subject to License terms. 25 */ 26 | 24 * Use is subject to License terms. 25 */ 26 |
27#include <emlxs.h> |
|
27 | 28 |
28#include "emlxs.h" | |
29 | 29 |
30 | |
31/* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */ 32EMLXS_MSG_DEF(EMLXS_THREAD_C); 33 | 30/* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */ 31EMLXS_MSG_DEF(EMLXS_THREAD_C); 32 |
34static void emlxs_thread(emlxs_thread_t *ethread); 35static void emlxs_taskq_thread(emlxs_taskq_thread_t *tthread); | 33static void emlxs_thread(emlxs_thread_t *ethread); 34static void emlxs_taskq_thread(emlxs_taskq_thread_t *tthread); |
36 37 38static void 39emlxs_taskq_thread(emlxs_taskq_thread_t *tthread) 40{ 41 emlxs_taskq_t *taskq; 42 void (*func) (); 43 void *arg; --- 26 unchanged lines hidden (view full) --- 70 mutex_enter(&tthread->lock); 71 tthread->flags &= ~EMLXS_THREAD_BUSY; 72 } 73 } 74 75 tthread->flags |= EMLXS_THREAD_ENDED; 76 mutex_exit(&tthread->lock); 77 | 35 36 37static void 38emlxs_taskq_thread(emlxs_taskq_thread_t *tthread) 39{ 40 emlxs_taskq_t *taskq; 41 void (*func) (); 42 void *arg; --- 26 unchanged lines hidden (view full) --- 69 mutex_enter(&tthread->lock); 70 tthread->flags &= ~EMLXS_THREAD_BUSY; 71 } 72 } 73 74 tthread->flags |= EMLXS_THREAD_ENDED; 75 mutex_exit(&tthread->lock); 76 |
78 (void) thread_exit(); | 77 thread_exit(); |
79 80 return; 81 | 78 79 return; 80 |
82} /* emlxs_taskq_thread() */ | 81} /* emlxs_taskq_thread() */ |
83 84 85 86uint32_t | 82 83 84 85uint32_t |
87emlxs_taskq_dispatch(emlxs_taskq_t *taskq, void (*func) (), void *arg) { | 86emlxs_taskq_dispatch(emlxs_taskq_t *taskq, void (*func) (), void *arg) 87{ |
88 emlxs_taskq_thread_t *tthread = NULL; 89 90 mutex_enter(&taskq->get_lock); 91 92 /* Make sure taskq is open for business */ 93 if (!taskq->open) { 94 mutex_exit(&taskq->get_lock); 95 return (0); 96 } | 88 emlxs_taskq_thread_t *tthread = NULL; 89 90 mutex_enter(&taskq->get_lock); 91 92 /* Make sure taskq is open for business */ 93 if (!taskq->open) { 94 mutex_exit(&taskq->get_lock); 95 return (0); 96 } |
97 |
|
97 /* Check get_list for a thread */ 98 if (taskq->get_head) { 99 /* Get the next thread */ 100 tthread = taskq->get_head; 101 taskq->get_count--; 102 taskq->get_head = (taskq->get_count) ? tthread->next : NULL; 103 tthread->next = NULL; 104 } | 98 /* Check get_list for a thread */ 99 if (taskq->get_head) { 100 /* Get the next thread */ 101 tthread = taskq->get_head; 102 taskq->get_count--; 103 taskq->get_head = (taskq->get_count) ? tthread->next : NULL; 104 tthread->next = NULL; 105 } |
106 |
|
105 /* Else check put_list for a thread */ 106 else if (taskq->put_head) { 107 108 /* Move put_list to get_list */ 109 mutex_enter(&taskq->put_lock); 110 taskq->get_head = taskq->put_head; 111 taskq->get_count = taskq->put_count; 112 taskq->put_head = NULL; 113 taskq->put_count = 0; 114 mutex_exit(&taskq->put_lock); 115 116 /* Get the next thread */ 117 tthread = taskq->get_head; 118 taskq->get_count--; 119 taskq->get_head = (taskq->get_count) ? tthread->next : NULL; 120 tthread->next = NULL; 121 } | 107 /* Else check put_list for a thread */ 108 else if (taskq->put_head) { 109 110 /* Move put_list to get_list */ 111 mutex_enter(&taskq->put_lock); 112 taskq->get_head = taskq->put_head; 113 taskq->get_count = taskq->put_count; 114 taskq->put_head = NULL; 115 taskq->put_count = 0; 116 mutex_exit(&taskq->put_lock); 117 118 /* Get the next thread */ 119 tthread = taskq->get_head; 120 taskq->get_count--; 121 taskq->get_head = (taskq->get_count) ? tthread->next : NULL; 122 tthread->next = NULL; 123 } |
124 |
|
122 mutex_exit(&taskq->get_lock); 123 124 /* Wake up the thread if one exists */ 125 if (tthread) { 126 mutex_enter(&tthread->lock); 127 tthread->func = func; 128 tthread->arg = arg; 129 cv_signal(&tthread->cv_flag); 130 mutex_exit(&tthread->lock); 131 132 return (1); 133 } | 125 mutex_exit(&taskq->get_lock); 126 127 /* Wake up the thread if one exists */ 128 if (tthread) { 129 mutex_enter(&tthread->lock); 130 tthread->func = func; 131 tthread->arg = arg; 132 cv_signal(&tthread->cv_flag); 133 mutex_exit(&tthread->lock); 134 135 return (1); 136 } |
137 |
|
134 return (0); 135 | 138 return (0); 139 |
136} /* emlxs_taskq_dispatch() */ | 140} /* emlxs_taskq_dispatch() */ |
137 138 139 140void 141emlxs_taskq_create(emlxs_hba_t *hba, emlxs_taskq_t *taskq) 142{ 143 emlxs_taskq_thread_t *tthread; 144 char buf[64]; | 141 142 143 144void 145emlxs_taskq_create(emlxs_hba_t *hba, emlxs_taskq_t *taskq) 146{ 147 emlxs_taskq_thread_t *tthread; 148 char buf[64]; |
145 uint32_t i = 0; | 149 uint32_t i; |
146 147 148 /* If taskq is already open then quit */ 149 if (taskq->open) { 150 return; 151 } | 150 151 152 /* If taskq is already open then quit */ 153 if (taskq->open) { 154 return; 155 } |
156 |
|
152 /* Zero the taskq */ 153 bzero(taskq, sizeof (emlxs_taskq_t)); 154 155 (void) sprintf(buf, "%s%d_thread_taskq_get mutex", DRIVER_NAME, 156 hba->ddiinst); | 157 /* Zero the taskq */ 158 bzero(taskq, sizeof (emlxs_taskq_t)); 159 160 (void) sprintf(buf, "%s%d_thread_taskq_get mutex", DRIVER_NAME, 161 hba->ddiinst); |
157 mutex_init(&taskq->get_lock, buf, MUTEX_DRIVER, (void *) hba->intr_arg); | 162 mutex_init(&taskq->get_lock, buf, MUTEX_DRIVER, 163 (void *)hba->intr_arg); |
158 159 mutex_enter(&taskq->get_lock); 160 161 taskq->hba = hba; 162 163 (void) sprintf(buf, "%s%d_thread_taskq_put mutex", DRIVER_NAME, 164 hba->ddiinst); | 164 165 mutex_enter(&taskq->get_lock); 166 167 taskq->hba = hba; 168 169 (void) sprintf(buf, "%s%d_thread_taskq_put mutex", DRIVER_NAME, 170 hba->ddiinst); |
165 mutex_init(&taskq->put_lock, buf, MUTEX_DRIVER, (void *) hba->intr_arg); | 171 mutex_init(&taskq->put_lock, buf, MUTEX_DRIVER, 172 (void *)hba->intr_arg); |
166 167 for (i = 0; i < EMLXS_MAX_TASKQ_THREADS; i++) { 168 tthread = &taskq->thread_list[i]; 169 tthread->taskq = taskq; 170 171 (void) sprintf(buf, "%s%d_thread%d mutex", DRIVER_NAME, 172 hba->ddiinst, i); 173 mutex_init(&tthread->lock, buf, MUTEX_DRIVER, | 173 174 for (i = 0; i < EMLXS_MAX_TASKQ_THREADS; i++) { 175 tthread = &taskq->thread_list[i]; 176 tthread->taskq = taskq; 177 178 (void) sprintf(buf, "%s%d_thread%d mutex", DRIVER_NAME, 179 hba->ddiinst, i); 180 mutex_init(&tthread->lock, buf, MUTEX_DRIVER, |
174 (void *) hba->intr_arg); | 181 (void *)hba->intr_arg); |
175 176 (void) sprintf(buf, "%s%d_thread%d cv", DRIVER_NAME, 177 hba->ddiinst, i); 178 cv_init(&tthread->cv_flag, buf, CV_DRIVER, NULL); 179 180 tthread->flags |= EMLXS_THREAD_INITD; | 182 183 (void) sprintf(buf, "%s%d_thread%d cv", DRIVER_NAME, 184 hba->ddiinst, i); 185 cv_init(&tthread->cv_flag, buf, CV_DRIVER, NULL); 186 187 tthread->flags |= EMLXS_THREAD_INITD; |
181 tthread->thread = thread_create(NULL, 0, emlxs_taskq_thread, | 188 tthread->thread = 189 thread_create(NULL, 0, emlxs_taskq_thread, |
182 (char *)tthread, 0, &p0, TS_RUN, v.v_maxsyspri - 2); 183 } 184 185 /* Open the taskq */ 186 taskq->open = 1; 187 188 mutex_exit(&taskq->get_lock); 189 190 return; 191 | 190 (char *)tthread, 0, &p0, TS_RUN, v.v_maxsyspri - 2); 191 } 192 193 /* Open the taskq */ 194 taskq->open = 1; 195 196 mutex_exit(&taskq->get_lock); 197 198 return; 199 |
192} /* emlxs_taskq_create() */ | 200} /* emlxs_taskq_create() */ |
193 194 195void 196emlxs_taskq_destroy(emlxs_taskq_t *taskq) 197{ 198 emlxs_taskq_thread_t *tthread; 199 uint32_t i; 200 | 201 202 203void 204emlxs_taskq_destroy(emlxs_taskq_t *taskq) 205{ 206 emlxs_taskq_thread_t *tthread; 207 uint32_t i; 208 |
201 /* hba = taskq->hba; */ 202 | |
203 /* If taskq already closed, then quit */ 204 if (!taskq->open) { 205 return; 206 } | 209 /* If taskq already closed, then quit */ 210 if (!taskq->open) { 211 return; 212 } |
213 |
|
207 mutex_enter(&taskq->get_lock); 208 209 /* If taskq already closed, then quit */ 210 if (!taskq->open) { 211 mutex_exit(&taskq->get_lock); 212 return; 213 } | 214 mutex_enter(&taskq->get_lock); 215 216 /* If taskq already closed, then quit */ 217 if (!taskq->open) { 218 mutex_exit(&taskq->get_lock); 219 return; 220 } |
221 |
|
214 taskq->open = 0; 215 mutex_exit(&taskq->get_lock); 216 217 218 /* No more threads can be dispatched now */ 219 220 /* Kill the threads */ 221 for (i = 0; i < EMLXS_MAX_TASKQ_THREADS; i++) { 222 tthread = &taskq->thread_list[i]; 223 224 /* | 222 taskq->open = 0; 223 mutex_exit(&taskq->get_lock); 224 225 226 /* No more threads can be dispatched now */ 227 228 /* Kill the threads */ 229 for (i = 0; i < EMLXS_MAX_TASKQ_THREADS; i++) { 230 tthread = &taskq->thread_list[i]; 231 232 /* |
225 * If the thread lock can be acquired, it is in one of these 226 * states: 1. Thread not started. 2. Thread asleep. 3. Thread 227 * busy. 4. Thread ended. | 233 * If the thread lock can be acquired, 234 * it is in one of these states: 235 * 1. Thread not started. 236 * 2. Thread asleep. 237 * 3. Thread busy. 238 * 4. Thread ended. |
228 */ 229 mutex_enter(&tthread->lock); 230 tthread->flags |= EMLXS_THREAD_KILLED; 231 cv_signal(&tthread->cv_flag); 232 233 /* Wait for thread to die */ 234 while (!(tthread->flags & EMLXS_THREAD_ENDED)) { 235 mutex_exit(&tthread->lock); --- 8 unchanged lines hidden (view full) --- 244 } 245 246 /* Clean up taskq */ 247 mutex_destroy(&taskq->put_lock); 248 mutex_destroy(&taskq->get_lock); 249 250 return; 251 | 239 */ 240 mutex_enter(&tthread->lock); 241 tthread->flags |= EMLXS_THREAD_KILLED; 242 cv_signal(&tthread->cv_flag); 243 244 /* Wait for thread to die */ 245 while (!(tthread->flags & EMLXS_THREAD_ENDED)) { 246 mutex_exit(&tthread->lock); --- 8 unchanged lines hidden (view full) --- 255 } 256 257 /* Clean up taskq */ 258 mutex_destroy(&taskq->put_lock); 259 mutex_destroy(&taskq->get_lock); 260 261 return; 262 |
252} /* emlxs_taskq_destroy() */ | 263} /* emlxs_taskq_destroy() */ |
253 254 255 256static void 257emlxs_thread(emlxs_thread_t *ethread) 258{ 259 void (*func) (); 260 void *arg1; 261 void *arg2; 262 263 /* | 264 265 266 267static void 268emlxs_thread(emlxs_thread_t *ethread) 269{ 270 void (*func) (); 271 void *arg1; 272 void *arg2; 273 274 /* |
264 * If the thread lock can be acquired, it is in one of these states: 265 * 1. Thread not started. 2. Thread asleep. 3. Thread busy. 4. Thread 266 * ended. | 275 * If the thread lock can be acquired, 276 * it is in one of these states: 277 * 1. Thread not started. 278 * 2. Thread asleep. 279 * 3. Thread busy. 280 * 4. Thread ended. |
267 */ 268 mutex_enter(ðread->lock); 269 ethread->flags |= EMLXS_THREAD_STARTED; 270 271 while (!(ethread->flags & EMLXS_THREAD_KILLED)) { 272 if (!(ethread->flags & EMLXS_THREAD_TRIGGERED)) { 273 ethread->flags |= EMLXS_THREAD_ASLEEP; 274 cv_wait(ðread->cv_flag, ðread->lock); 275 } | 281 */ 282 mutex_enter(ðread->lock); 283 ethread->flags |= EMLXS_THREAD_STARTED; 284 285 while (!(ethread->flags & EMLXS_THREAD_KILLED)) { 286 if (!(ethread->flags & EMLXS_THREAD_TRIGGERED)) { 287 ethread->flags |= EMLXS_THREAD_ASLEEP; 288 cv_wait(ðread->cv_flag, ðread->lock); 289 } |
290 |
|
276 ethread->flags &= 277 ~(EMLXS_THREAD_ASLEEP | EMLXS_THREAD_TRIGGERED); 278 279 if (ethread->func) { 280 func = ethread->func; 281 arg1 = ethread->arg1; 282 arg2 = ethread->arg2; 283 ethread->func = NULL; --- 8 unchanged lines hidden (view full) --- 292 mutex_enter(ðread->lock); 293 ethread->flags &= ~EMLXS_THREAD_BUSY; 294 } 295 } 296 297 ethread->flags |= EMLXS_THREAD_ENDED; 298 mutex_exit(ðread->lock); 299 | 291 ethread->flags &= 292 ~(EMLXS_THREAD_ASLEEP | EMLXS_THREAD_TRIGGERED); 293 294 if (ethread->func) { 295 func = ethread->func; 296 arg1 = ethread->arg1; 297 arg2 = ethread->arg2; 298 ethread->func = NULL; --- 8 unchanged lines hidden (view full) --- 307 mutex_enter(ðread->lock); 308 ethread->flags &= ~EMLXS_THREAD_BUSY; 309 } 310 } 311 312 ethread->flags |= EMLXS_THREAD_ENDED; 313 mutex_exit(ðread->lock); 314 |
300 (void) thread_exit(); | 315 thread_exit(); |
301 302 return; 303 | 316 317 return; 318 |
304} /* emlxs_thread() */ | 319} /* emlxs_thread() */ |
305 306 307void 308emlxs_thread_create(emlxs_hba_t *hba, emlxs_thread_t *ethread) 309{ 310 char buf[64]; 311 312 if (ethread->flags & EMLXS_THREAD_INITD) { 313 return; 314 } | 320 321 322void 323emlxs_thread_create(emlxs_hba_t *hba, emlxs_thread_t *ethread) 324{ 325 char buf[64]; 326 327 if (ethread->flags & EMLXS_THREAD_INITD) { 328 return; 329 } |
330 |
|
315 bzero(ethread, sizeof (emlxs_thread_t)); 316 | 331 bzero(ethread, sizeof (emlxs_thread_t)); 332 |
317 (void) sprintf(buf, "%s%d_thread_%08x mutex", DRIVER_NAME, 318 hba->ddiinst, (int)((uintptr_t)ethread & 0xFFFFFFFF)); 319 mutex_init(ðread->lock, buf, MUTEX_DRIVER, (void *) hba->intr_arg); | 333 (void) sprintf(buf, "%s%d_thread_%08x mutex", DRIVER_NAME, hba->ddiinst, 334 (uint32_t)((uintptr_t)ethread & 0xFFFFFFFF)); 335 mutex_init(ðread->lock, buf, MUTEX_DRIVER, (void *)hba->intr_arg); |
320 321 /* mutex_enter(ðread->lock); */ 322 | 336 337 /* mutex_enter(ðread->lock); */ 338 |
323 (void) sprintf(buf, "%s%d_thread_%08x cv", DRIVER_NAME, 324 hba->ddiinst, (int)((uintptr_t)ethread & 0xFFFFFFFF)); | 339 (void) sprintf(buf, "%s%d_thread_%08x cv", DRIVER_NAME, hba->ddiinst, 340 (uint32_t)((uintptr_t)ethread & 0xFFFFFFFF)); |
325 cv_init(ðread->cv_flag, buf, CV_DRIVER, NULL); 326 327 ethread->hba = hba; 328 ethread->flags |= EMLXS_THREAD_INITD; 329 330 /* mutex_exit(ðread->lock); */ 331 | 341 cv_init(ðread->cv_flag, buf, CV_DRIVER, NULL); 342 343 ethread->hba = hba; 344 ethread->flags |= EMLXS_THREAD_INITD; 345 346 /* mutex_exit(ðread->lock); */ 347 |
332 ethread->thread = thread_create(NULL, 0, emlxs_thread, 333 (char *)ethread, 0, &p0, TS_RUN, v.v_maxsyspri - 2); | 348 ethread->thread = 349 thread_create(NULL, 0, emlxs_thread, (char *)ethread, 0, &p0, 350 TS_RUN, v.v_maxsyspri - 2); |
334 335 return; 336 | 351 352 return; 353 |
337} /* emlxs_thread_create() */ | 354} /* emlxs_thread_create() */ |
338 339 340void 341emlxs_thread_destroy(emlxs_thread_t *ethread) 342{ 343 /* | 355 356 357void 358emlxs_thread_destroy(emlxs_thread_t *ethread) 359{ 360 /* |
344 * If the thread lock can be acquired, it is in one of these states: 345 * 1. Thread not started. 2. Thread asleep. 3. Thread busy. 4. Thread 346 * ended. | 361 * If the thread lock can be acquired, 362 * it is in one of these states: 363 * 1. Thread not started. 364 * 2. Thread asleep. 365 * 3. Thread busy. 366 * 4. Thread ended. |
347 */ 348 if (!(ethread->flags & EMLXS_THREAD_INITD)) { 349 return; 350 } | 367 */ 368 if (!(ethread->flags & EMLXS_THREAD_INITD)) { 369 return; 370 } |
371 |
|
351 mutex_enter(ðread->lock); 352 353 if (ethread->flags & EMLXS_THREAD_ENDED) { 354 return; 355 } | 372 mutex_enter(ðread->lock); 373 374 if (ethread->flags & EMLXS_THREAD_ENDED) { 375 return; 376 } |
377 |
|
356 ethread->flags &= ~EMLXS_THREAD_INITD; 357 ethread->flags |= (EMLXS_THREAD_KILLED | EMLXS_THREAD_TRIGGERED); 358 ethread->func = NULL; 359 ethread->arg1 = NULL; 360 ethread->arg2 = NULL; 361 cv_signal(ðread->cv_flag); 362 363 /* Wait for thread to end */ --- 5 unchanged lines hidden (view full) --- 369 370 mutex_exit(ðread->lock); 371 372 cv_destroy(ðread->cv_flag); 373 mutex_destroy(ðread->lock); 374 375 return; 376 | 378 ethread->flags &= ~EMLXS_THREAD_INITD; 379 ethread->flags |= (EMLXS_THREAD_KILLED | EMLXS_THREAD_TRIGGERED); 380 ethread->func = NULL; 381 ethread->arg1 = NULL; 382 ethread->arg2 = NULL; 383 cv_signal(ðread->cv_flag); 384 385 /* Wait for thread to end */ --- 5 unchanged lines hidden (view full) --- 391 392 mutex_exit(ðread->lock); 393 394 cv_destroy(ðread->cv_flag); 395 mutex_destroy(ðread->lock); 396 397 return; 398 |
377} /* emlxs_thread_destroy() */ | 399} /* emlxs_thread_destroy() */ |
378 379 380void 381emlxs_thread_trigger1(emlxs_thread_t *ethread, void (*func) ()) 382{ 383 384 /* | 400 401 402void 403emlxs_thread_trigger1(emlxs_thread_t *ethread, void (*func) ()) 404{ 405 406 /* |
385 * If the thread lock can be acquired, it is in one of these states: 386 * 1. Thread not started. 2. Thread asleep. 3. Thread busy. 4. Thread 387 * ended. | 407 * If the thread lock can be acquired, 408 * it is in one of these states: 409 * 1. Thread not started. 410 * 2. Thread asleep. 411 * 3. Thread busy. 412 * 4. Thread ended. |
388 */ 389 if (!(ethread->flags & EMLXS_THREAD_INITD)) { 390 return; 391 } | 413 */ 414 if (!(ethread->flags & EMLXS_THREAD_INITD)) { 415 return; 416 } |
417 |
|
392 mutex_enter(ðread->lock); 393 394 if (ethread->flags & EMLXS_THREAD_ENDED) { 395 return; 396 } | 418 mutex_enter(ðread->lock); 419 420 if (ethread->flags & EMLXS_THREAD_ENDED) { 421 return; 422 } |
423 |
|
397 while (!(ethread->flags & EMLXS_THREAD_STARTED)) { 398 mutex_exit(ðread->lock); 399 delay(drv_usectohz(10000)); 400 mutex_enter(ðread->lock); 401 402 if (ethread->flags & EMLXS_THREAD_ENDED) { 403 return; 404 } 405 } 406 407 ethread->flags |= EMLXS_THREAD_TRIGGERED; 408 ethread->func = func; 409 ethread->arg1 = NULL; 410 ethread->arg2 = NULL; 411 412 if (ethread->flags & EMLXS_THREAD_ASLEEP) { 413 cv_signal(ðread->cv_flag); 414 } | 424 while (!(ethread->flags & EMLXS_THREAD_STARTED)) { 425 mutex_exit(ðread->lock); 426 delay(drv_usectohz(10000)); 427 mutex_enter(ðread->lock); 428 429 if (ethread->flags & EMLXS_THREAD_ENDED) { 430 return; 431 } 432 } 433 434 ethread->flags |= EMLXS_THREAD_TRIGGERED; 435 ethread->func = func; 436 ethread->arg1 = NULL; 437 ethread->arg2 = NULL; 438 439 if (ethread->flags & EMLXS_THREAD_ASLEEP) { 440 cv_signal(ðread->cv_flag); 441 } |
442 |
|
415 mutex_exit(ðread->lock); 416 417 return; 418 | 443 mutex_exit(ðread->lock); 444 445 return; 446 |
419} /* emlxs_thread_trigger1() */ | 447} /* emlxs_thread_trigger1() */ |
420 421 422void | 448 449 450void |
423emlxs_thread_trigger2(emlxs_thread_t *ethread, void (*func) (), RING *rp) { | 451emlxs_thread_trigger2(emlxs_thread_t *ethread, void (*func) (), RING *rp) 452{ |
424 425 /* | 453 454 /* |
426 * If the thread lock can be acquired, it is in one of these states: 427 * 1. Thread not started. 2. Thread asleep. 3. Thread busy. 4. Thread 428 * ended. | 455 * If the thread lock can be acquired, 456 * it is in one of these states: 457 * 1. Thread not started. 458 * 2. Thread asleep. 459 * 3. Thread busy. 460 * 4. Thread ended. |
429 */ 430 if (!(ethread->flags & EMLXS_THREAD_INITD)) { 431 return; 432 } | 461 */ 462 if (!(ethread->flags & EMLXS_THREAD_INITD)) { 463 return; 464 } |
465 |
|
433 mutex_enter(ðread->lock); 434 435 if (ethread->flags & EMLXS_THREAD_ENDED) { 436 return; 437 } | 466 mutex_enter(ðread->lock); 467 468 if (ethread->flags & EMLXS_THREAD_ENDED) { 469 return; 470 } |
471 |
|
438 while (!(ethread->flags & EMLXS_THREAD_STARTED)) { 439 mutex_exit(ðread->lock); 440 delay(drv_usectohz(10000)); 441 mutex_enter(ðread->lock); 442 443 if (ethread->flags & EMLXS_THREAD_ENDED) { 444 return; 445 } 446 } 447 448 ethread->flags |= EMLXS_THREAD_TRIGGERED; 449 ethread->func = func; | 472 while (!(ethread->flags & EMLXS_THREAD_STARTED)) { 473 mutex_exit(ðread->lock); 474 delay(drv_usectohz(10000)); 475 mutex_enter(ðread->lock); 476 477 if (ethread->flags & EMLXS_THREAD_ENDED) { 478 return; 479 } 480 } 481 482 ethread->flags |= EMLXS_THREAD_TRIGGERED; 483 ethread->func = func; |
450 ethread->arg1 = (void *) rp; | 484 ethread->arg1 = (void *)rp; |
451 ethread->arg2 = NULL; 452 453 if (ethread->flags & EMLXS_THREAD_ASLEEP) { 454 cv_signal(ðread->cv_flag); 455 } | 485 ethread->arg2 = NULL; 486 487 if (ethread->flags & EMLXS_THREAD_ASLEEP) { 488 cv_signal(ðread->cv_flag); 489 } |
490 |
|
456 mutex_exit(ðread->lock); 457 458 return; 459 | 491 mutex_exit(ðread->lock); 492 493 return; 494 |
460} /* emlxs_thread_trigger2() */ | 495} /* emlxs_thread_trigger2() */ |