Commit graph

54 commits

Author SHA1 Message Date
Sam Lantinga 56522034db Fixed building with Visual Studio 2010 2023-01-09 18:30:23 -08:00
Sam Lantinga fde78d12f2 Updated copyright for 2023 2023-01-09 09:41:41 -08:00
Sam Lantinga 63724c113b Removed the vi format comments from the source
Vim users can use the [editorconfig plugin](https://github.com/editorconfig/editorconfig-vim) to automatically set tab spacing for the SDL coding style.

Fixes https://github.com/libsdl-org/SDL/issues/6903
2022-12-26 11:17:23 -08:00
Sam Lantinga 5750bcb174
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
2022-11-30 12:51:59 -08:00
Sam Lantinga c5790359fd
Added precompiled header support for Visual Studio and Xcode (#6710)
Fixes https://github.com/libsdl-org/SDL/issues/6704
2022-11-29 18:34:15 -08:00
Sylvain Becker 6a2200823c
Cleanup add brace (#6545)
* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line
2022-11-27 08:38:43 -08:00
Sam Lantinga 0a48abc860 Switch header convention from #include "SDL.h" to #include <SDL3/SDLh>
I ran this script in the include directory:
```sh
sed -i '' -e 's,#include "\(SDL.*\)",#include <SDL3/\1>,' *.h
```

I ran this script in the src directory:
```sh
for i in ../include/SDL3/SDL*.h
do hdr=$(basename $i)
   if [ x"$(echo $hdr | egrep 'SDL_main|SDL_name|SDL_test|SDL_syswm|SDL_opengl|SDL_egl|SDL_vulkan')" != x ]; then
        find . -type f -exec sed -i '' -e 's,#include "\('$hdr'\)",#include <SDL3/\1>,' {} \;
    else
        find . -type f -exec sed -i '' -e '/#include "'$hdr'"/d' {} \;
    fi
done
```

Fixes https://github.com/libsdl-org/SDL/issues/6575
2022-11-26 22:15:18 -08:00
Sam Lantinga cc1f9eb983 Use Apple's nomenclature for macOS and iOS
Fixes https://github.com/libsdl-org/SDL/issues/6621
2022-11-25 16:00:06 -08:00
Sam Lantinga a635a485bc Re-added WinRT support until we're sure that it's no longer being used 2022-11-23 10:41:43 -08:00
Ozkan Sezer dc2a3e06e9 removed WinRT support. 2022-11-22 23:36:24 +03:00
pionere e5c599f8c6 fix SOLARIS_ATOMICS
- use 'sizeless' int types (int uses 32-bit even if _LP64 is set)
2022-11-09 12:45:14 -05:00
pionere b095df7f5c simplify MSC_ATOMICS
- use _Interlocked(Compare)ExchangePointer in case of _M_IX86 as well
- improve assertions:
  1. add assertions to SDL_AtomicAdd/SDL_AtomicSet and SDL_AtomicCAS
  2. use sizeof(a->value) instead of sizeof(int)
2022-11-08 10:32:31 -08:00
pionere eb670742f5 better SDL_AtomicGet(Ptr) implementation 2022-11-07 09:09:37 -08:00
David Carlier 16e699a761 Proposing exposing as public api the various arch dependent
pause instructions so could be used in app infinite loops.
A handful of games do already so we unify it in one place.
2022-08-04 08:47:39 -07:00
Chris Mumford 98411c0d33 Added include: libkern/OSAtomic.h
When building on macOS without gcc (e.g. clang) where HAVE_GCC_ATOMICS
is not defined, `SDL_AtomicTryLock` will call
`OSAtomicCompareAndSwap32Barrier` which is not yet declared.
Including OSAtomic.h on OSX resolves this error/warning:

    SDL_spinlock.c:125:12: error: implicit declaration of function
      'OSAtomicCompareAndSwap32Barrier' is invalid in
      C99 [-Werror,-Wimplicit-function-declaration]
        return OSAtomicCompareAndSwap32Barrier(0, 1, lock);

This was reported in issue #3885 but marked Invalid and closed - possibly
because the default CMake build uses gcc instead of clang.
2022-07-05 07:50:57 -07:00
chalonverse 3b191580c3
Windows GDK Support (#5830)
* Added GDK

* Simplfied checks in SDL_config_wingdk.h

* Added testgdk sample

* Added GDK readme

* Fixed error in merge of SDL_windows.h

* Additional GDK fixes

* OpenWatcom should not export _SDL_GDKGetTaskQueue

* Formatting fixes

* Moved initialization code into SDL_GDKRunApp
2022-06-27 10:19:39 -07:00
Francisco Javier Trujillo Mata 273d9e4640 Fix atomic support for PS2 2022-06-15 15:15:26 -07:00
Ozkan Sezer 67f12ede3b move bug #5333 fix to headers 2022-02-08 21:32:50 +03:00
Ozkan Sezer 9b817248c5 SDL_spinlock.c: define HAVE_GCC_ATOMICS for windows/clang builds,
... if not already defined.
Fixes https://github.com/libsdl-org/SDL/issues/5333

diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c
index bdd347e..4f10741 100644
--- a/src/atomic/SDL_spinlock.c
+++ b/src/atomic/SDL_spinlock.c
@@ -28,6 +28,12 @@
 #include "SDL_mutex.h"
 #include "SDL_timer.h"

+#if defined(__WIN32__) && defined(__clang__)
+# ifndef HAVE_GCC_ATOMICS
+# define HAVE_GCC_ATOMICS 1
+# endif
+#endif
+
 #if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
 #include <atomic.h>
 #endif
2022-02-08 18:50:02 +03:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Ozkan Sezer 53aa8eec5f minor cleanup for watcom _inline keyword. 2021-11-25 17:00:24 +03:00
Alex R ebdfd0e175 atomic: detect clang separately 2021-09-16 17:33:52 -07:00
Ryan C. Gordon f4eb7f329e
spinlock: Favor gcc-style atomics over MSVC interfaces.
This resolves a problem when using Clang on Windows.

Fixes #4346.
2021-07-27 13:45:33 -04:00
Cameron Gutman 014f507c40 Use specific acquire and release variants of InterlockedExchange on ARM
_InterlockedExchange_rel() is required for correctness on ARM because
the _ReadWriteBarrier() macro is only a compiler memory barrier, not a
hardware memory barrier. Due to ARM's relaxed memory model, this means
the '*lock = 0' write may be observed before the operations inside the
lock, causing possible corruption of data protected by the lock.

_InterlockedExchange_acq() is more efficient on ARM because it avoids an
expensive full memory barrier that _InterlockedExchange() does.
2021-01-03 12:13:40 -06:00
Cameron Gutman 59594a7891 Implement PAUSE_INSTRUCTION() for Windows ARM platforms 2021-01-02 13:43:04 -06:00
Sam Lantinga 9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga d25eff6505 Fixed bug 5429 - spinlock implements PAUSE_INSTRUCTION for PPC platforms
David Carlier

This form of 'or' provides a hint that performance
will probably be improved if shared resources dedicated
to the executing processor are released for use by other
processors
2021-01-02 10:06:22 -08:00
Sam Lantinga 6bd4c717a1 Fixed bug 5402 - ARM support little update proposal
David Carlier

No fix but mostly an update for ARM architecture.
2020-12-17 21:41:23 -08:00
Cameron Cawley 8f1a916ac5 Add basic support for compiling on RISC OS 2020-02-13 20:50:47 +00:00
Sam Lantinga a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Cameron Cawley 85aabec27e atomic: Support compiling on ARMv3 2019-10-11 22:08:53 +01:00
Sam Lantinga 959cfc428e Fixed memory barrier macro check so it isn't quite so fragile 2019-06-30 23:58:31 -07:00
Sam Lantinga a8bea85810 Limit the compile error to the case where we actually define the memory barrier macro as the function 2019-06-30 23:55:28 -07:00
Sam Lantinga cc47810d36 Fixed bug 4683 - SDL_atomic infinite recursion on armv6/armv5 w/ thumb
The real problem is that SDL_atomic.c was built in thumb mode instead of ARM mode, which is required to use the mcr instruction on ARM platforms. Added a compiler error to catch this case so we don't generate code that does infinite recursion.

I also added a potentially better way to handle things on Linux ARM platforms, based on comments in the Chromium headers, which we can try out after 2.0.10 ships.
2019-06-30 23:26:16 -07:00
Sam Lantinga 5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Ozkan Sezer d9fb77a3c1 SDL_atomic.c, SDL_spinlock.c: use lock prefix with xchg in Watcom asm. 2018-09-27 11:55:02 +03:00
Ozkan Sezer 949b8bd8c5 correct the comment correction.. 2018-06-30 20:10:40 +03:00
Ozkan Sezer 67f18a1973 comment correction 2018-06-30 20:04:01 +03:00
Ryan C. Gordon 52857de251 Corrected a comment. 2018-06-29 16:55:55 -04:00
Ryan C. Gordon 3b173f818d Patched to compile on Visual Studio (typo). 2018-06-25 23:00:38 -04:00
Ryan C. Gordon 58168a8c3c atomic: Fight with all the assemblers that don't like REP NOP. :/ 2018-06-25 16:34:16 -04:00
Ryan C. Gordon 5f123e31a3 atomic: Spin locks now try to use the x86 PAUSE instruction for short waits.
Fixes Bugzilla #4151.
2018-06-25 15:58:35 -04:00
Sam Lantinga e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Ozkan Sezer 500378eb52 Add atomics for Watcom/x86 as inline asm
Partially fixes Bugzilla #3758.
2017-08-18 16:35:55 -04:00
Ryan C. Gordon 1d1a0d7f03 atomic: Patched to compile on Android. 2017-04-13 15:28:56 -04:00
Ryan C. Gordon 1c9c7633d9 atomic: favor compiler intrinsics for compare-and-swap over macOS APIs.
The OSAtomicCompareAndSwap* APIs are deprecated as of macOS 10.12.
2017-04-13 13:28:52 -04:00
Ryan C. Gordon 8c00de57f6 atomic: let Clang always use atomic_load_n if available.
(Apple's Clang reports itself as GCC 4.2.1 in preprocessor macros--the final
GNU C compiler Apple shipped--as of the macOS 10.12 SDK.)
2017-04-13 13:22:23 -04:00
Sam Lantinga 7891e72dca __atomic_load_n() appears to be available in GCC 5 but not GCC 4 2017-03-30 06:52:34 -07:00
Ryan C. Gordon f2179944cc Patched to compile on some platforms. 2017-03-29 12:04:17 -04:00
James Legg 1dc9ae5c1e Use GCC's atomic loads in SDL_AtomicGet and SDL_AtomicGetPtr
This fixes errors reported by address sanitizer, and generates simpler
code on x86 architectures.
2017-03-29 15:48:22 +01:00