-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce vmpool to make each vm run on single thread (#272)
* introduce vmpool to make each vm run on single thread * fix lint * use index to rotate * use atomic
- Loading branch information
Showing
4 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
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
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,24 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"sync/atomic" | ||
|
||
"github.com/initia-labs/initia/x/move/types" | ||
) | ||
|
||
func (k Keeper) acquireVM(ctx context.Context) (vm types.VMEngine) { | ||
err := k.moveVMSemaphore.Acquire(ctx, 1) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
idx := atomic.AddUint64(k.moveVMIdx, 1) | ||
vm = k.moveVMs[idx%uint64(len(k.moveVMs))] | ||
|
||
return | ||
} | ||
|
||
func (k Keeper) releaseVM() { | ||
k.moveVMSemaphore.Release(1) | ||
} |