Skip to content

Commit

Permalink
8246265: ZGC: Introduce ZConditionLock
Browse files Browse the repository at this point in the history
Reviewed-by: eosterlund, stefank
  • Loading branch information
pliden committed Jun 9, 2020
1 parent 63a3d8f commit cd16b56
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/hotspot/share/gc/z/zLock.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -52,6 +52,20 @@ class ZReentrantLock {
bool is_owned() const;
};

class ZConditionLock {
private:
os::PlatformMonitor _lock;

public:
void lock();
bool try_lock();
void unlock();

bool wait(uint64_t millis = 0);
void notify();
void notify_all();
};

template <typename T>
class ZLocker : public StackObj {
private:
Expand Down
26 changes: 25 additions & 1 deletion src/hotspot/share/gc/z/zLock.inline.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -77,6 +77,30 @@ inline bool ZReentrantLock::is_owned() const {
return owner == thread;
}

inline void ZConditionLock::lock() {
_lock.lock();
}

inline bool ZConditionLock::try_lock() {
return _lock.try_lock();
}

inline void ZConditionLock::unlock() {
_lock.unlock();
}

inline bool ZConditionLock::wait(uint64_t millis) {
return _lock.wait(millis) == OS_OK;
}

inline void ZConditionLock::notify() {
_lock.notify();
}

inline void ZConditionLock::notify_all() {
_lock.notify_all();
}

template <typename T>
inline ZLocker<T>::ZLocker(T* lock) :
_lock(lock) {
Expand Down

0 comments on commit cd16b56

Please sign in to comment.