forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#31102 from scrocquesel/codegen_race_cond…
…ition Fix gRPC codegen race condition
- Loading branch information
Showing
4 changed files
with
38 additions
and
44 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
core/deployment/src/main/java/io/quarkus/deployment/dev/CodeGenLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.deployment.dev; | ||
|
||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
/** | ||
* Lock that is used to prevent scanning and compiling while code generator is updating sources | ||
* There is a race when testing this, where you can see the intermediate empty state of the | ||
* file, or where the file time changes twice. Codegen hold this lock during modification | ||
* to avoid the race. | ||
*/ | ||
public class CodeGenLock { | ||
|
||
/** | ||
* Allow for multiple code generators to run at the same time but give exclusive run to RuntimeUpdatesProcessor | ||
*/ | ||
private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); | ||
|
||
public static Lock lockForCodeGen() { | ||
return lock.readLock(); | ||
} | ||
|
||
public static Lock lockForCompilation() { | ||
return lock.writeLock(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters