1693 fatal("pthread_mutexattr_init: %s", os::strerror(status)); |
1693 fatal("pthread_mutexattr_init: %s", os::strerror(status)); |
1694 } |
1694 } |
1695 if ((status = pthread_mutexattr_settype(_mutexAttr, PTHREAD_MUTEX_NORMAL)) != 0) { |
1695 if ((status = pthread_mutexattr_settype(_mutexAttr, PTHREAD_MUTEX_NORMAL)) != 0) { |
1696 fatal("pthread_mutexattr_settype: %s", os::strerror(status)); |
1696 fatal("pthread_mutexattr_settype: %s", os::strerror(status)); |
1697 } |
1697 } |
1698 // Solaris has it's own PlatformMonitor, distinct from the one for POSIX. |
1698 // Solaris has it's own PlatformMutex, distinct from the one for POSIX. |
1699 NOT_SOLARIS(os::PlatformMonitor::init();) |
1699 NOT_SOLARIS(os::PlatformMutex::init();) |
1700 } |
1700 } |
1701 |
1701 |
1702 #ifndef SOLARIS |
1702 #ifndef SOLARIS |
1703 sigset_t sigs; |
1703 sigset_t sigs; |
1704 struct sigaction sigact[NSIG]; |
1704 struct sigaction sigact[NSIG]; |
2272 status = pthread_cond_signal(&_cond[index]); |
2272 status = pthread_cond_signal(&_cond[index]); |
2273 assert_status(status == 0, status, "invariant"); |
2273 assert_status(status == 0, status, "invariant"); |
2274 } |
2274 } |
2275 } |
2275 } |
2276 |
2276 |
2277 // Platform Monitor implementation |
2277 // Platform Mutex/Monitor implementation |
2278 |
2278 |
2279 os::PlatformMonitor::Impl::Impl() : _next(NULL) { |
2279 #if PLATFORM_MONITOR_IMPL_INDIRECT |
2280 int status = pthread_cond_init(&_cond, _condAttr); |
2280 |
2281 assert_status(status == 0, status, "cond_init"); |
2281 os::PlatformMutex::Mutex::Mutex() : _next(NULL) { |
2282 status = pthread_mutex_init(&_mutex, _mutexAttr); |
2282 int status = pthread_mutex_init(&_mutex, _mutexAttr); |
2283 assert_status(status == 0, status, "mutex_init"); |
2283 assert_status(status == 0, status, "mutex_init"); |
2284 } |
2284 } |
2285 |
2285 |
2286 os::PlatformMonitor::Impl::~Impl() { |
2286 os::PlatformMutex::Mutex::~Mutex() { |
2287 int status = pthread_cond_destroy(&_cond); |
2287 int status = pthread_mutex_destroy(&_mutex); |
2288 assert_status(status == 0, status, "cond_destroy"); |
|
2289 status = pthread_mutex_destroy(&_mutex); |
|
2290 assert_status(status == 0, status, "mutex_destroy"); |
2288 assert_status(status == 0, status, "mutex_destroy"); |
2291 } |
2289 } |
2292 |
2290 |
2293 #if PLATFORM_MONITOR_IMPL_INDIRECT |
2291 pthread_mutex_t os::PlatformMutex::_freelist_lock; |
2294 |
2292 os::PlatformMutex::Mutex* os::PlatformMutex::_mutex_freelist = NULL; |
2295 pthread_mutex_t os::PlatformMonitor::_freelist_lock; |
2293 |
2296 os::PlatformMonitor::Impl* os::PlatformMonitor::_freelist = NULL; |
2294 void os::PlatformMutex::init() { |
2297 |
|
2298 void os::PlatformMonitor::init() { |
|
2299 int status = pthread_mutex_init(&_freelist_lock, _mutexAttr); |
2295 int status = pthread_mutex_init(&_freelist_lock, _mutexAttr); |
2300 assert_status(status == 0, status, "freelist lock init"); |
2296 assert_status(status == 0, status, "freelist lock init"); |
2301 } |
2297 } |
2302 |
2298 |
2303 struct os::PlatformMonitor::WithFreeListLocked : public StackObj { |
2299 struct os::PlatformMutex::WithFreeListLocked : public StackObj { |
2304 WithFreeListLocked() { |
2300 WithFreeListLocked() { |
2305 int status = pthread_mutex_lock(&_freelist_lock); |
2301 int status = pthread_mutex_lock(&_freelist_lock); |
2306 assert_status(status == 0, status, "freelist lock"); |
2302 assert_status(status == 0, status, "freelist lock"); |
2307 } |
2303 } |
2308 |
2304 |
2310 int status = pthread_mutex_unlock(&_freelist_lock); |
2306 int status = pthread_mutex_unlock(&_freelist_lock); |
2311 assert_status(status == 0, status, "freelist unlock"); |
2307 assert_status(status == 0, status, "freelist unlock"); |
2312 } |
2308 } |
2313 }; |
2309 }; |
2314 |
2310 |
|
2311 os::PlatformMutex::PlatformMutex() { |
|
2312 { |
|
2313 WithFreeListLocked wfl; |
|
2314 _impl = _mutex_freelist; |
|
2315 if (_impl != NULL) { |
|
2316 _mutex_freelist = _impl->_next; |
|
2317 _impl->_next = NULL; |
|
2318 return; |
|
2319 } |
|
2320 } |
|
2321 _impl = new Mutex(); |
|
2322 } |
|
2323 |
|
2324 os::PlatformMutex::~PlatformMutex() { |
|
2325 WithFreeListLocked wfl; |
|
2326 assert(_impl->_next == NULL, "invariant"); |
|
2327 _impl->_next = _mutex_freelist; |
|
2328 _mutex_freelist = _impl; |
|
2329 } |
|
2330 |
|
2331 os::PlatformMonitor::Cond::Cond() : _next(NULL) { |
|
2332 int status = pthread_cond_init(&_cond, _condAttr); |
|
2333 assert_status(status == 0, status, "cond_init"); |
|
2334 } |
|
2335 |
|
2336 os::PlatformMonitor::Cond::~Cond() { |
|
2337 int status = pthread_cond_destroy(&_cond); |
|
2338 assert_status(status == 0, status, "cond_destroy"); |
|
2339 } |
|
2340 |
|
2341 os::PlatformMonitor::Cond* os::PlatformMonitor::_cond_freelist = NULL; |
|
2342 |
2315 os::PlatformMonitor::PlatformMonitor() { |
2343 os::PlatformMonitor::PlatformMonitor() { |
2316 { |
2344 { |
2317 WithFreeListLocked wfl; |
2345 WithFreeListLocked wfl; |
2318 _impl = _freelist; |
2346 _impl = _cond_freelist; |
2319 if (_impl != NULL) { |
2347 if (_impl != NULL) { |
2320 _freelist = _impl->_next; |
2348 _cond_freelist = _impl->_next; |
2321 _impl->_next = NULL; |
2349 _impl->_next = NULL; |
2322 return; |
2350 return; |
2323 } |
2351 } |
2324 } |
2352 } |
2325 _impl = new Impl(); |
2353 _impl = new Cond(); |
2326 } |
2354 } |
2327 |
2355 |
2328 os::PlatformMonitor::~PlatformMonitor() { |
2356 os::PlatformMonitor::~PlatformMonitor() { |
2329 WithFreeListLocked wfl; |
2357 WithFreeListLocked wfl; |
2330 assert(_impl->_next == NULL, "invariant"); |
2358 assert(_impl->_next == NULL, "invariant"); |
2331 _impl->_next = _freelist; |
2359 _impl->_next = _cond_freelist; |
2332 _freelist = _impl; |
2360 _cond_freelist = _impl; |
|
2361 } |
|
2362 |
|
2363 #else |
|
2364 |
|
2365 os::PlatformMutex::PlatformMutex() { |
|
2366 int status = pthread_mutex_init(&_mutex, _mutexAttr); |
|
2367 assert_status(status == 0, status, "mutex_init"); |
|
2368 } |
|
2369 |
|
2370 os::PlatformMutex::~PlatformMutex() { |
|
2371 int status = pthread_mutex_destroy(&_mutex); |
|
2372 assert_status(status == 0, status, "mutex_destroy"); |
|
2373 } |
|
2374 |
|
2375 os::PlatformMonitor::PlatformMonitor() { |
|
2376 int status = pthread_cond_init(&_cond, _condAttr); |
|
2377 assert_status(status == 0, status, "cond_init"); |
|
2378 } |
|
2379 |
|
2380 os::PlatformMonitor::~PlatformMonitor() { |
|
2381 int status = pthread_cond_destroy(&_cond); |
|
2382 assert_status(status == 0, status, "cond_destroy"); |
2333 } |
2383 } |
2334 |
2384 |
2335 #endif // PLATFORM_MONITOR_IMPL_INDIRECT |
2385 #endif // PLATFORM_MONITOR_IMPL_INDIRECT |
2336 |
2386 |
2337 // Must already be locked |
2387 // Must already be locked |