-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alan Jowett <[email protected]>
- Loading branch information
1 parent
69a84e1
commit b1ec1a2
Showing
3 changed files
with
24 additions
and
0 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
Binary file not shown.
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,19 @@ | ||
// Copyright (c) Prevail Verifier contributors. | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include "bpf.h" | ||
|
||
// This sample demonstrates how to use global variables in BPF programs. | ||
// Global variables are shared among all threads in the same BPF program and | ||
// can be used to store global states. They must be declared as `volatile` | ||
// to prevent the compiler from optimizing them away and must accessed | ||
// using atomic operations to avoid race conditions. | ||
|
||
static volatile uint32_t global_var = 0; | ||
static volatile uint32_t global_var_2 = 0; | ||
|
||
int func(void* ctx) { | ||
__sync_fetch_and_add(&global_var, 1); | ||
__sync_fetch_and_add(&global_var_2, 2); | ||
return 0; | ||
} |