Skip to content

Commit

Permalink
all: run vfmt over files
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon committed Aug 10, 2024
1 parent b3142c1 commit e469f31
Show file tree
Hide file tree
Showing 65 changed files with 2,796 additions and 14,097 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
timeout-minutes: 30
env:
VFLAGS: -cc tcc -no-retry-compilation
SDL2_VERSION: 2.30.0
SDL2_VERSION: 2.0.8
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --quiet -y libsdl2-ttf-dev
sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev
sudo apt-get install --quiet -y libsdl2-mixer-dev libsdl2-image-dev
curl -L https://www.libsdl.org/release/SDL2-${SDL2_VERSION}.tar.gz -o SDL2.tar.gz
tar -zxvf SDL2.tar.gz
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
runs-on: macos-12
timeout-minutes: 60
env:
SDL2_VERSION: 2.30.0
SDL2_VERSION: 2.0.8
steps:
- name: Checkout V
uses: actions/checkout@v2
Expand Down Expand Up @@ -150,8 +150,9 @@ jobs:
timeout-minutes: 30
env:
VFLAGS: -cc gcc -no-retry-compilation
SDL2_VERSION: 2.30.0
SDL2_VERSION: 2.0.8
steps:

- name: Install V
uses: vlang/setup-v@v1
with:
Expand Down Expand Up @@ -185,7 +186,7 @@ jobs:
timeout-minutes: 30
env:
VFLAGS: -cc tcc -no-retry-compilation
SDL2_VERSION: 2.30.0
SDL2_VERSION: 2.0.8
steps:

- name: Install V
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ This will create a directory called "thirdparty" which will be used to download
To successfully run a provided example or your own projects, the sdl dlls must be copied to the main application directory.
e.g.:
```bash
copy thirdparty\SDL2-2.30.0\lib\x64\SDL2.dll examples\basic_window\
copy thirdparty\SDL2-2.0.8\lib\x64\SDL2.dll examples\basic_window\
cd ..
v run sdl\examples\basic_window\main.v
```
Expand Down
137 changes: 20 additions & 117 deletions atomic.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,9 @@ fn C.SDL_AtomicTryLock(lock_ &C.SDL_SpinLock) bool

// atomic_try_lock tries to lock a spin lock by setting it to a non-zero value.
//
// ***Please note that spinlocks are dangerous if you don't know what you're
// doing. Please be careful using any sort of spinlock!***
// `lock_` a pointer to a lock variable
// `lock_` points to the lock.
//
// returns SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held.
//
// NOTE This function is available since SDL 2.0.0.
//
// See also: SDL_AtomicLock
// See also: SDL_AtomicUnlock
pub fn atomic_try_lock(lock_ &SpinLock) bool {
return unsafe { C.SDL_AtomicTryLock(&C.SDL_SpinLock(lock_)) }
}
Expand All @@ -80,57 +73,37 @@ fn C.SDL_AtomicLock(lock_ &C.SDL_SpinLock)

// atomic_lock locks a spin lock by setting it to a non-zero value.
//
// ***Please note that spinlocks are dangerous if you don't know what you're
// doing. Please be careful using any sort of spinlock!***
//
// `lock_` a pointer to a lock variable
//
// NOTE This function is available since SDL 2.0.0.
//
// See also: SDL_AtomicTryLock
// See also: SDL_AtomicUnlock
// `lock_` points to the lock.
pub fn atomic_lock(lock_ &SpinLock) {
unsafe { C.SDL_AtomicLock(&C.SDL_SpinLock(lock_)) }
}

fn C.SDL_AtomicUnlock(lock_ &C.SDL_SpinLock)

// atomic_unlock unlocks a spin lock by setting it to 0.
//
// Always returns immediately.
//
// ***Please note that spinlocks are dangerous if you don't know what you're
// doing. Please be careful using any sort of spinlock!***
//
// `lock_` a pointer to a lock variable
//
// NOTE This function is available since SDL 2.0.0.
// atomic_unlock unlocks a spin lock by setting it to 0. Always returns immediately
//
// See also: SDL_AtomicLock
// See also: SDL_AtomicTryLock
// `lock_` Points to the lock.
pub fn atomic_unlock(lock_ &SpinLock) {
unsafe { C.SDL_AtomicUnlock(&C.SDL_SpinLock(lock_)) }
}

// Memory barriers are designed to prevent reads and writes from being
// reordered by the compiler and being seen out of order on multi-core CPUs.
//
// A typical pattern would be for thread A to write some data and a flag, and
// for thread B to read the flag and get the data. In this case you would
// insert a release barrier between writing the data and the flag,
// A typical pattern would be for thread A to write some data and a flag,
// and for thread B to read the flag and get the data. In this case you
// would insert a release barrier between writing the data and the flag,
// guaranteeing that the data write completes no later than the flag is
// written, and you would insert an acquire barrier between reading the flag
// and reading the data, to ensure that all the reads associated with the flag
// have completed.
// written, and you would insert an acquire barrier between reading the
// flag and reading the data, to ensure that all the reads associated
// with the flag have completed.
//
// In this pattern you should always see a release barrier paired with an
// acquire barrier and you should gate the data reads/writes with a single
// flag variable.
// In this pattern you should always see a release barrier paired with
// an acquire barrier and you should gate the data reads/writes with a
// single flag variable.
//
// For more information on these semantics, take a look at the blog post:
// http://preshing.com/20120913/acquire-and-release-semantics
//
// NOTE This function is available since SDL 2.0.6.
fn C.SDL_MemoryBarrierReleaseFunction()
pub fn memory_barrier_release_function() {
C.SDL_MemoryBarrierReleaseFunction()
Expand All @@ -155,17 +128,9 @@ fn C.SDL_AtomicCAS(a &C.SDL_atomic_t, oldval int, newval int) bool

// atomic_cas sets an atomic variable to a new value if it is currently an old value.
//
// NOTE If you don't know what this function is for, you shouldn't use it!
//
// `a` a pointer to an SDL_atomic_t variable to be modified
// `oldval` the old value
// `newval` the new value
// returns SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.0.
// See also: SDL_AtomicCASPtr
// See also: SDL_AtomicGet
// See also: SDL_AtomicSet
// NOTE If you don't know what this function is for, you shouldn't use it!
pub fn atomic_cas(a &C.SDL_atomic_t, oldval int, newval int) bool {
return unsafe { C.SDL_AtomicCAS(a, oldval, newval) }
}
Expand All @@ -174,35 +139,14 @@ fn C.SDL_AtomicSet(a &C.SDL_atomic_t, v int) int

// atomic_set sets an atomic variable to a value.
//
// This function also acts as a full memory barrier.
//
// NOTE If you don't know what this function is for, you shouldn't use
// it!
//
// `a` a pointer to an SDL_atomic_t variable to be modified
// `v` the desired value
// returns the previous value of the atomic variable.
//
// NOTE This function is available since SDL 2.0.2.
//
// See also: SDL_AtomicGet
// returns The previous value of the atomic variable.
pub fn atomic_set(a &AtomicT, v int) int {
return unsafe { C.SDL_AtomicSet(&C.SDL_atomic_t(a), v) }
}

fn C.SDL_AtomicGet(a &C.SDL_atomic_t) int

// atomic_get gets the value of an atomic variable.
//
// NOTE If you don't know what this function is for, you shouldn't use
// it!
//
// `a` a pointer to an SDL_atomic_t variable
// returns the current value of an atomic variable.
//
// NOTE This function is available since SDL 2.0.2.
//
// See also: SDL_AtomicSet
// atomic_get gets the value of an atomic variable
pub fn atomic_get(a &AtomicT) int {
return unsafe { C.SDL_AtomicGet(&C.SDL_atomic_t(a)) }
}
Expand All @@ -211,19 +155,9 @@ fn C.SDL_AtomicAdd(a &C.SDL_atomic_t, v int) int

// atomic_add adds to an atomic variable.
//
// This function also acts as a full memory barrier.
//
// // NOTE If you don't know what this function is for, you shouldn't use
// it!
//
// `a` a pointer to an SDL_atomic_t variable to be modified
// `v` the desired value to add
// returns The previous value of the atomic variable.
//
// NOTE This function is available since SDL 2.0.2.
//
// See also: SDL_AtomicDecRef
// See also: SDL_AtomicIncRef
// NOTE This same style can be used for any number operation
pub fn atomic_add(a &AtomicT, v int) int {
return unsafe { C.SDL_AtomicAdd(&C.SDL_atomic_t(a), v) }
}
Expand Down Expand Up @@ -251,19 +185,9 @@ fn C.SDL_AtomicCASPtr(a voidptr, oldval voidptr, newval voidptr) bool

// atomic_cas_ptr sets a pointer to a new value if it is currently an old value.
//
// NOTE If you don't know what this function is for, you shouldn't use
// it!
//
// `a` a pointer to a pointer
// `oldval` the old pointer value
// `newval` the new pointer value
// returns SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.0.
//
// See also: SDL_AtomicCAS
// See also: SDL_AtomicGetPtr
// See also: SDL_AtomicSetPtr
// NOTE If you don't know what this function is for, you shouldn't use it!
//
// `a`'s C type is `void **a`
pub fn atomic_cas_ptr(a voidptr, oldval voidptr, newval voidptr) bool {
Expand All @@ -272,39 +196,18 @@ pub fn atomic_cas_ptr(a voidptr, oldval voidptr, newval voidptr) bool {

fn C.SDL_AtomicSetPtr(a voidptr, v voidptr) voidptr

// atomic_set_ptr sets a pointer to a value atomically.
//
// NOTE If you don't know what this function is for, you shouldn't use
// it!
// atomic_set_ptr set a pointer to a value atomically.
//
// `a` a pointer to a pointer
// `v` the desired pointer value
// returns the previous value of the pointer.
//
// NOTE This function is available since SDL 2.0.2.
//
// See also: SDL_AtomicCASPtr
// See also: SDL_AtomicGetPtr
//
// `a`'s C type is `void **a`
pub fn atomic_set_ptr(a voidptr, v voidptr) voidptr {
return C.SDL_AtomicSetPtr(a, v)
}

fn C.SDL_AtomicGetPtr(a voidptr) voidptr

// atomic_get_ptr gets a pointer to a value atomically.
//
// NOTE If you don't know what this function is for, you shouldn't use
// it!
//
// `a` a pointer to a pointer
// returns the current value of a pointer.
//
// NOTE This function is available since SDL 2.0.2.
//
// See also: SDL_AtomicCASPtr
// See also: SDL_AtomicSetPtr
// atomic_get_ptr gets the value of a pointer atomically.
//
// `a`'s C type is `void **a`
pub fn atomic_get_ptr(a voidptr) voidptr {
Expand Down
Loading

0 comments on commit e469f31

Please sign in to comment.