thr_mutex.c (17706) | thr_mutex.c (22315) |
---|---|
1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 62 unchanged lines hidden (view full) --- 71 /* Reset the mutex flags: */ 72 pmutex->m_flags = 0; 73 74 /* Block signals: */ 75 _thread_kern_sig_block(&status); 76 77 /* Process according to mutex type: */ 78 switch (type) { | 1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 62 unchanged lines hidden (view full) --- 71 /* Reset the mutex flags: */ 72 pmutex->m_flags = 0; 73 74 /* Block signals: */ 75 _thread_kern_sig_block(&status); 76 77 /* Process according to mutex type: */ 78 switch (type) { |
79 /* Fast mutex: */ | 79 /* Fast mutex: */ |
80 case MUTEX_TYPE_FAST: 81 /* Nothing to do here. */ 82 break; 83 | 80 case MUTEX_TYPE_FAST: 81 /* Nothing to do here. */ 82 break; 83 |
84 /* Counting mutex: */ | 84 /* Counting mutex: */ |
85 case MUTEX_TYPE_COUNTING_FAST: 86 /* Reset the mutex count: */ 87 pmutex->m_data.m_count = 0; 88 break; 89 | 85 case MUTEX_TYPE_COUNTING_FAST: 86 /* Reset the mutex count: */ 87 pmutex->m_data.m_count = 0; 88 break; 89 |
90 /* Trap invalid mutex types: */ | 90 /* Trap invalid mutex types: */ |
91 default: 92 /* Return an invalid argument error: */ 93 errno = EINVAL; 94 ret = -1; 95 break; 96 } 97 if (ret == 0) { 98 /* Initialise the rest of the mutex: */ --- 26 unchanged lines hidden (view full) --- 125 errno = EINVAL; 126 ret = -1; 127 } else { 128 /* Block signals: */ 129 _thread_kern_sig_block(&status); 130 131 /* Process according to mutex type: */ 132 switch ((*mutex)->m_type) { | 91 default: 92 /* Return an invalid argument error: */ 93 errno = EINVAL; 94 ret = -1; 95 break; 96 } 97 if (ret == 0) { 98 /* Initialise the rest of the mutex: */ --- 26 unchanged lines hidden (view full) --- 125 errno = EINVAL; 126 ret = -1; 127 } else { 128 /* Block signals: */ 129 _thread_kern_sig_block(&status); 130 131 /* Process according to mutex type: */ 132 switch ((*mutex)->m_type) { |
133 /* Fast mutex: */ | 133 /* Fast mutex: */ |
134 case MUTEX_TYPE_FAST: 135 /* Nothing to do here. */ 136 break; 137 | 134 case MUTEX_TYPE_FAST: 135 /* Nothing to do here. */ 136 break; 137 |
138 /* Counting mutex: */ | 138 /* Counting mutex: */ |
139 case MUTEX_TYPE_COUNTING_FAST: 140 /* Reset the mutex count: */ 141 (*mutex)->m_data.m_count = 0; 142 break; 143 | 139 case MUTEX_TYPE_COUNTING_FAST: 140 /* Reset the mutex count: */ 141 (*mutex)->m_data.m_count = 0; 142 break; 143 |
144 /* Trap undefined mutex types: */ | 144 /* Trap undefined mutex types: */ |
145 default: 146 /* Return an invalid argument error: */ 147 errno = EINVAL; 148 ret = -1; 149 break; 150 } 151 152 /* Clean up the mutex in case that others want to use it: */ --- 190 unchanged lines hidden (view full) --- 343 ret = -1; 344 } 345 /* 346 * Get the next thread from the queue of threads waiting on 347 * the mutex: 348 */ 349 else if (((*mutex)->m_owner = _thread_queue_deq(&(*mutex)->m_queue)) != NULL) { 350 /* Allow the new owner of the mutex to run: */ | 145 default: 146 /* Return an invalid argument error: */ 147 errno = EINVAL; 148 ret = -1; 149 break; 150 } 151 152 /* Clean up the mutex in case that others want to use it: */ --- 190 unchanged lines hidden (view full) --- 343 ret = -1; 344 } 345 /* 346 * Get the next thread from the queue of threads waiting on 347 * the mutex: 348 */ 349 else if (((*mutex)->m_owner = _thread_queue_deq(&(*mutex)->m_queue)) != NULL) { 350 /* Allow the new owner of the mutex to run: */ |
351 (*mutex)->m_owner->state = PS_RUNNING; | 351 PTHREAD_NEW_STATE((*mutex)->m_owner,PS_RUNNING); |
352 } 353 break; 354 355 /* Counting mutex: */ 356 case MUTEX_TYPE_COUNTING_FAST: 357 /* Check if the running thread is not the owner of the mutex: */ 358 if ((*mutex)->m_owner != _thread_run) { 359 /* Return an invalid argument error: */ --- 6 unchanged lines hidden (view full) --- 366 (*mutex)->m_data.m_count--; 367 } 368 /* 369 * Get the next thread from the queue of threads waiting on 370 * the mutex: 371 */ 372 else if (((*mutex)->m_owner = _thread_queue_deq(&(*mutex)->m_queue)) != NULL) { 373 /* Allow the new owner of the mutex to run: */ | 352 } 353 break; 354 355 /* Counting mutex: */ 356 case MUTEX_TYPE_COUNTING_FAST: 357 /* Check if the running thread is not the owner of the mutex: */ 358 if ((*mutex)->m_owner != _thread_run) { 359 /* Return an invalid argument error: */ --- 6 unchanged lines hidden (view full) --- 366 (*mutex)->m_data.m_count--; 367 } 368 /* 369 * Get the next thread from the queue of threads waiting on 370 * the mutex: 371 */ 372 else if (((*mutex)->m_owner = _thread_queue_deq(&(*mutex)->m_queue)) != NULL) { 373 /* Allow the new owner of the mutex to run: */ |
374 (*mutex)->m_owner->state = PS_RUNNING; | 374 PTHREAD_NEW_STATE((*mutex)->m_owner,PS_RUNNING); |
375 } 376 break; 377 378 /* Trap invalid mutex types: */ 379 default: 380 /* Return an invalid argument error: */ 381 errno = EINVAL; 382 ret = -1; 383 break; 384 } 385 386 /* Unblock signals: */ 387 _thread_kern_sig_unblock(status); 388 } 389 390 /* Return the completion status: */ 391 return (ret); 392} 393#endif | 375 } 376 break; 377 378 /* Trap invalid mutex types: */ 379 default: 380 /* Return an invalid argument error: */ 381 errno = EINVAL; 382 ret = -1; 383 break; 384 } 385 386 /* Unblock signals: */ 387 _thread_kern_sig_unblock(status); 388 } 389 390 /* Return the completion status: */ 391 return (ret); 392} 393#endif |