2213 status = pthread_cond_signal(&_cond[index]); |
2213 status = pthread_cond_signal(&_cond[index]); |
2214 assert_status(status == 0, status, "invariant"); |
2214 assert_status(status == 0, status, "invariant"); |
2215 } |
2215 } |
2216 } |
2216 } |
2217 |
2217 |
|
2218 // Platform Monitor implementation |
|
2219 |
|
2220 os::PlatformMonitor::PlatformMonitor() { |
|
2221 int status = pthread_cond_init(&_cond, _condAttr); |
|
2222 assert_status(status == 0, status, "cond_init"); |
|
2223 status = pthread_mutex_init(&_mutex, _mutexAttr); |
|
2224 assert_status(status == 0, status, "mutex_init"); |
|
2225 } |
|
2226 |
|
2227 os::PlatformMonitor::~PlatformMonitor() { |
|
2228 int status = pthread_cond_destroy(&_cond); |
|
2229 assert_status(status == 0, status, "cond_destroy"); |
|
2230 status = pthread_mutex_destroy(&_mutex); |
|
2231 assert_status(status == 0, status, "mutex_destroy"); |
|
2232 } |
|
2233 |
|
2234 void os::PlatformMonitor::lock() { |
|
2235 int status = pthread_mutex_lock(&_mutex); |
|
2236 assert_status(status == 0, status, "mutex_lock"); |
|
2237 } |
|
2238 |
|
2239 void os::PlatformMonitor::unlock() { |
|
2240 int status = pthread_mutex_unlock(&_mutex); |
|
2241 assert_status(status == 0, status, "mutex_unlock"); |
|
2242 } |
|
2243 |
|
2244 bool os::PlatformMonitor::try_lock() { |
|
2245 int status = pthread_mutex_trylock(&_mutex); |
|
2246 assert_status(status == 0 || status == EBUSY, status, "mutex_trylock"); |
|
2247 return status == 0; |
|
2248 } |
|
2249 |
|
2250 // Must already be locked |
|
2251 int os::PlatformMonitor::wait(jlong millis) { |
|
2252 assert(millis >= 0, "negative timeout"); |
|
2253 if (millis > 0) { |
|
2254 struct timespec abst; |
|
2255 // We have to watch for overflow when converting millis to nanos, |
|
2256 // but if millis is that large then we will end up limiting to |
|
2257 // MAX_SECS anyway, so just do that here. |
|
2258 if (millis / MILLIUNITS > MAX_SECS) { |
|
2259 millis = jlong(MAX_SECS) * MILLIUNITS; |
|
2260 } |
|
2261 to_abstime(&abst, millis * (NANOUNITS / MILLIUNITS), false, false); |
|
2262 |
|
2263 int ret = OS_TIMEOUT; |
|
2264 int status = pthread_cond_timedwait(&_cond, &_mutex, &abst); |
|
2265 assert_status(status == 0 || status == ETIMEDOUT, |
|
2266 status, "cond_timedwait"); |
|
2267 if (status == 0) { |
|
2268 ret = OS_OK; |
|
2269 } |
|
2270 return ret; |
|
2271 } else { |
|
2272 int status = pthread_cond_wait(&_cond, &_mutex); |
|
2273 assert_status(status == 0, status, "cond_wait"); |
|
2274 return OS_OK; |
|
2275 } |
|
2276 } |
|
2277 |
|
2278 void os::PlatformMonitor::notify() { |
|
2279 int status = pthread_cond_signal(&_cond); |
|
2280 assert_status(status == 0, status, "cond_signal"); |
|
2281 } |
|
2282 |
|
2283 void os::PlatformMonitor::notify_all() { |
|
2284 int status = pthread_cond_broadcast(&_cond); |
|
2285 assert_status(status == 0, status, "cond_broadcast"); |
|
2286 } |
2218 |
2287 |
2219 #endif // !SOLARIS |
2288 #endif // !SOLARIS |