From 9c1430324c31b55798488155f03966d9311a97e7 Mon Sep 17 00:00:00 2001 From: Brick <6098371+0x1F9F1@users.noreply.github.com> Date: Thu, 31 Aug 2023 23:14:55 +0100 Subject: [PATCH] Removed SDL_dataqueue --- VisualC-GDK/SDL/SDL.vcxproj | 2 - VisualC-GDK/SDL/SDL.vcxproj.filters | 2 - VisualC-WinRT/SDL-UWP.vcxproj | 2 - VisualC-WinRT/SDL-UWP.vcxproj.filters | 6 - VisualC/SDL/SDL.vcxproj | 2 - VisualC/SDL/SDL.vcxproj.filters | 2 - Xcode/SDL/SDL.xcodeproj/project.pbxproj | 8 - src/SDL_dataqueue.c | 318 ------------------------ src/SDL_dataqueue.h | 38 --- 9 files changed, 380 deletions(-) delete mode 100644 src/SDL_dataqueue.c delete mode 100644 src/SDL_dataqueue.h diff --git a/VisualC-GDK/SDL/SDL.vcxproj b/VisualC-GDK/SDL/SDL.vcxproj index f4419c9ee..05556a850 100644 --- a/VisualC-GDK/SDL/SDL.vcxproj +++ b/VisualC-GDK/SDL/SDL.vcxproj @@ -438,7 +438,6 @@ - $(IntDir)$(TargetName)_cpp.pch @@ -707,7 +706,6 @@ - diff --git a/VisualC-GDK/SDL/SDL.vcxproj.filters b/VisualC-GDK/SDL/SDL.vcxproj.filters index f55ad0342..863cb5f6e 100644 --- a/VisualC-GDK/SDL/SDL.vcxproj.filters +++ b/VisualC-GDK/SDL/SDL.vcxproj.filters @@ -396,7 +396,6 @@ API Headers - @@ -838,7 +837,6 @@ - diff --git a/VisualC-WinRT/SDL-UWP.vcxproj b/VisualC-WinRT/SDL-UWP.vcxproj index c6df98236..c6b9b05d4 100644 --- a/VisualC-WinRT/SDL-UWP.vcxproj +++ b/VisualC-WinRT/SDL-UWP.vcxproj @@ -147,7 +147,6 @@ - @@ -388,7 +387,6 @@ - diff --git a/VisualC-WinRT/SDL-UWP.vcxproj.filters b/VisualC-WinRT/SDL-UWP.vcxproj.filters index 871a43e1e..9e44ed1a2 100644 --- a/VisualC-WinRT/SDL-UWP.vcxproj.filters +++ b/VisualC-WinRT/SDL-UWP.vcxproj.filters @@ -408,9 +408,6 @@ Source Files - - Source Files - Source Files @@ -786,9 +783,6 @@ Source Files - - Source Files - Source Files diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj index 0cea50604..2eae831c5 100644 --- a/VisualC/SDL/SDL.vcxproj +++ b/VisualC/SDL/SDL.vcxproj @@ -385,7 +385,6 @@ - Create @@ -585,7 +584,6 @@ - diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters index 63fd04c06..0be6f82e2 100644 --- a/VisualC/SDL/SDL.vcxproj.filters +++ b/VisualC/SDL/SDL.vcxproj.filters @@ -387,7 +387,6 @@ API Headers - @@ -817,7 +816,6 @@ - diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 5fd66058a..857984c55 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -63,7 +63,6 @@ A75FDBB823E4CBC700529352 /* ReadMe.txt in Resources */ = {isa = PBXBuildFile; fileRef = F59C710300D5CB5801000001 /* ReadMe.txt */; }; A75FDBC523EA380300529352 /* SDL_hidapi_rumble.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDBC323EA380300529352 /* SDL_hidapi_rumble.h */; }; A75FDBCE23EA380300529352 /* SDL_hidapi_rumble.c in Sources */ = {isa = PBXBuildFile; fileRef = A75FDBC423EA380300529352 /* SDL_hidapi_rumble.c */; }; - A7D8A94523E2514000DCD162 /* SDL_dataqueue.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A57023E2513D00DCD162 /* SDL_dataqueue.h */; }; A7D8A94B23E2514000DCD162 /* SDL.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A57123E2513D00DCD162 /* SDL.c */; }; A7D8A95123E2514000DCD162 /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A57323E2513D00DCD162 /* SDL_spinlock.c */; }; A7D8A95723E2514000DCD162 /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A57423E2513D00DCD162 /* SDL_atomic.c */; }; @@ -315,7 +314,6 @@ A7D8BAFD23E2514500DCD162 /* s_floor.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A92523E2514000DCD162 /* s_floor.c */; }; A7D8BB0323E2514500DCD162 /* math_libm.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A92623E2514000DCD162 /* math_libm.h */; }; A7D8BB0923E2514500DCD162 /* k_tan.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A92723E2514000DCD162 /* k_tan.c */; }; - A7D8BB0F23E2514500DCD162 /* SDL_dataqueue.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A92823E2514000DCD162 /* SDL_dataqueue.c */; }; A7D8BB1523E2514500DCD162 /* SDL_mouse.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A92A23E2514000DCD162 /* SDL_mouse.c */; }; A7D8BB1B23E2514500DCD162 /* SDL_mouse_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A92B23E2514000DCD162 /* SDL_mouse_c.h */; }; A7D8BB2123E2514500DCD162 /* scancodes_windows.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A92C23E2514000DCD162 /* scancodes_windows.h */; }; @@ -531,7 +529,6 @@ A75FDBA723E4CB6F00529352 /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE.txt; sourceTree = ""; }; A75FDBC323EA380300529352 /* SDL_hidapi_rumble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_hidapi_rumble.h; sourceTree = ""; }; A75FDBC423EA380300529352 /* SDL_hidapi_rumble.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_rumble.c; sourceTree = ""; }; - A7D8A57023E2513D00DCD162 /* SDL_dataqueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_dataqueue.h; sourceTree = ""; }; A7D8A57123E2513D00DCD162 /* SDL.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL.c; sourceTree = ""; }; A7D8A57323E2513D00DCD162 /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = ""; }; A7D8A57423E2513D00DCD162 /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = ""; }; @@ -812,7 +809,6 @@ A7D8A92523E2514000DCD162 /* s_floor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = s_floor.c; sourceTree = ""; }; A7D8A92623E2514000DCD162 /* math_libm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = math_libm.h; sourceTree = ""; }; A7D8A92723E2514000DCD162 /* k_tan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = k_tan.c; sourceTree = ""; }; - A7D8A92823E2514000DCD162 /* SDL_dataqueue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_dataqueue.c; sourceTree = ""; }; A7D8A92A23E2514000DCD162 /* SDL_mouse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_mouse.c; sourceTree = ""; }; A7D8A92B23E2514000DCD162 /* SDL_mouse_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_mouse_c.h; sourceTree = ""; }; A7D8A92C23E2514000DCD162 /* scancodes_windows.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_windows.h; sourceTree = ""; }; @@ -1108,8 +1104,6 @@ A7D8A5EB23E2513D00DCD162 /* video */, A7D8A7F523E2513F00DCD162 /* SDL_assert_c.h */, A7D8A94423E2514000DCD162 /* SDL_assert.c */, - A7D8A92823E2514000DCD162 /* SDL_dataqueue.c */, - A7D8A57023E2513D00DCD162 /* SDL_dataqueue.h */, A7D8A57523E2513D00DCD162 /* SDL_error_c.h */, A7D8A8BF23E2513F00DCD162 /* SDL_error.c */, F382071C284F362F004DD584 /* SDL_guid.c */, @@ -2070,7 +2064,6 @@ F3F7D9B92933074E00816151 /* SDL_cpuinfo.h in Headers */, F3990E062A788303000D8759 /* SDL_hidapi_ios.h in Headers */, A7D8B98023E2514400DCD162 /* SDL_d3dmath.h in Headers */, - A7D8A94523E2514000DCD162 /* SDL_dataqueue.h in Headers */, A7D8B8A223E2514400DCD162 /* SDL_diskaudio.h in Headers */, A7D8BB3F23E2514500DCD162 /* SDL_displayevents_c.h in Headers */, A7D8BA1923E2514400DCD162 /* SDL_draw.h in Headers */, @@ -2552,7 +2545,6 @@ A7D8BBDB23E2574800DCD162 /* SDL_uikitmetalview.m in Sources */, A7D8BB1523E2514500DCD162 /* SDL_mouse.c in Sources */, A7D8BAD923E2514500DCD162 /* e_rem_pio2.c in Sources */, - A7D8BB0F23E2514500DCD162 /* SDL_dataqueue.c in Sources */, F395C19C2569C68F00942BFF /* SDL_iokitjoystick.c in Sources */, A7D8B4B223E2514300DCD162 /* SDL_sysjoystick.c in Sources */, A7D8B3E023E2514300DCD162 /* SDL_cpuinfo.c in Sources */, diff --git a/src/SDL_dataqueue.c b/src/SDL_dataqueue.c deleted file mode 100644 index 4b3b79c94..000000000 --- a/src/SDL_dataqueue.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2023 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_internal.h" - -#include "./SDL_dataqueue.h" - -typedef struct SDL_DataQueuePacket -{ - size_t datalen; /* bytes currently in use in this packet. */ - size_t startpos; /* bytes currently consumed in this packet. */ - struct SDL_DataQueuePacket *next; /* next item in linked list. */ - Uint8 data[SDL_VARIABLE_LENGTH_ARRAY]; /* packet data */ -} SDL_DataQueuePacket; - -struct SDL_DataQueue -{ - SDL_Mutex *lock; - SDL_DataQueuePacket *head; /* device fed from here. */ - SDL_DataQueuePacket *tail; /* queue fills to here. */ - SDL_DataQueuePacket *pool; /* these are unused packets. */ - size_t packet_size; /* size of new packets */ - size_t queued_bytes; /* number of bytes of data in the queue. */ -}; - -static void SDL_FreeDataQueueList(SDL_DataQueuePacket *packet) -{ - while (packet) { - SDL_DataQueuePacket *next = packet->next; - SDL_free(packet); - packet = next; - } -} - -SDL_DataQueue *SDL_CreateDataQueue(const size_t _packetlen, const size_t initialslack) -{ - SDL_DataQueue *queue = (SDL_DataQueue *)SDL_calloc(1, sizeof(SDL_DataQueue)); - - if (queue == NULL) { - SDL_OutOfMemory(); - } else { - const size_t packetlen = _packetlen ? _packetlen : 1024; - const size_t wantpackets = (initialslack + (packetlen - 1)) / packetlen; - size_t i; - - queue->packet_size = packetlen; - - queue->lock = SDL_CreateMutex(); - if (!queue->lock) { - SDL_free(queue); - return NULL; - } - - for (i = 0; i < wantpackets; i++) { - SDL_DataQueuePacket *packet = (SDL_DataQueuePacket *)SDL_malloc(sizeof(SDL_DataQueuePacket) + packetlen); - if (packet) { /* don't care if this fails, we'll deal later. */ - packet->datalen = 0; - packet->startpos = 0; - packet->next = queue->pool; - queue->pool = packet; - } - } - } - - return queue; -} - -void SDL_DestroyDataQueue(SDL_DataQueue *queue) -{ - if (queue) { - SDL_FreeDataQueueList(queue->head); - SDL_FreeDataQueueList(queue->pool); - SDL_DestroyMutex(queue->lock); - SDL_free(queue); - } -} - -void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack) -{ - const size_t packet_size = queue ? queue->packet_size : 1; - const size_t slackpackets = (slack + (packet_size - 1)) / packet_size; - SDL_DataQueuePacket *packet; - SDL_DataQueuePacket *prev = NULL; - size_t i; - - if (queue == NULL) { - return; - } - - SDL_LockMutex(queue->lock); - - packet = queue->head; - - /* merge the available pool and the current queue into one list. */ - if (packet) { - queue->tail->next = queue->pool; - } else { - packet = queue->pool; - } - - /* Remove the queued packets from the device. */ - queue->tail = NULL; - queue->head = NULL; - queue->queued_bytes = 0; - queue->pool = packet; - - /* Optionally keep some slack in the pool to reduce memory allocation pressure. */ - for (i = 0; packet && (i < slackpackets); i++) { - prev = packet; - packet = packet->next; - } - - if (prev) { - prev->next = NULL; - } else { - queue->pool = NULL; - } - - SDL_UnlockMutex(queue->lock); - - SDL_FreeDataQueueList(packet); /* free extra packets */ -} - -/* You must hold queue->lock before calling this! */ -static SDL_DataQueuePacket *AllocateDataQueuePacket(SDL_DataQueue *queue) -{ - SDL_DataQueuePacket *packet; - - SDL_assert(queue != NULL); - - packet = queue->pool; - if (packet != NULL) { - /* we have one available in the pool. */ - queue->pool = packet->next; - } else { - /* Have to allocate a new one! */ - packet = (SDL_DataQueuePacket *)SDL_malloc(sizeof(SDL_DataQueuePacket) + queue->packet_size); - if (packet == NULL) { - return NULL; - } - } - - packet->datalen = 0; - packet->startpos = 0; - packet->next = NULL; - - SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0)); - if (queue->tail == NULL) { - queue->head = packet; - } else { - queue->tail->next = packet; - } - queue->tail = packet; - return packet; -} - -int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len) -{ - size_t len = _len; - const Uint8 *data = (const Uint8 *)_data; - const size_t packet_size = queue ? queue->packet_size : 0; - SDL_DataQueuePacket *orighead; - SDL_DataQueuePacket *origtail; - size_t origlen; - size_t datalen; - - if (queue == NULL) { - return SDL_InvalidParamError("queue"); - } - - SDL_LockMutex(queue->lock); - - orighead = queue->head; - origtail = queue->tail; - origlen = origtail ? origtail->datalen : 0; - - while (len > 0) { - SDL_DataQueuePacket *packet = queue->tail; - SDL_assert(packet == NULL || (packet->datalen <= packet_size)); - if (packet == NULL || (packet->datalen >= packet_size)) { - /* tail packet missing or completely full; we need a new packet. */ - packet = AllocateDataQueuePacket(queue); - if (packet == NULL) { - /* uhoh, reset so we've queued nothing new, free what we can. */ - if (origtail == NULL) { - packet = queue->head; /* whole queue. */ - } else { - packet = origtail->next; /* what we added to existing queue. */ - origtail->next = NULL; - origtail->datalen = origlen; - } - queue->head = orighead; - queue->tail = origtail; - queue->pool = NULL; - - SDL_UnlockMutex(queue->lock); - SDL_FreeDataQueueList(packet); /* give back what we can. */ - return SDL_OutOfMemory(); - } - } - - datalen = SDL_min(len, packet_size - packet->datalen); - SDL_memcpy(packet->data + packet->datalen, data, datalen); - data += datalen; - len -= datalen; - packet->datalen += datalen; - queue->queued_bytes += datalen; - } - - SDL_UnlockMutex(queue->lock); - - return 0; -} - -size_t SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len) -{ - size_t len = _len; - Uint8 *buf = (Uint8 *)_buf; - Uint8 *ptr = buf; - SDL_DataQueuePacket *packet; - - if (queue == NULL) { - return 0; - } - - SDL_LockMutex(queue->lock); - - for (packet = queue->head; len && packet; packet = packet->next) { - const size_t avail = packet->datalen - packet->startpos; - const size_t cpy = SDL_min(len, avail); - SDL_assert(queue->queued_bytes >= avail); - - SDL_memcpy(ptr, packet->data + packet->startpos, cpy); - ptr += cpy; - len -= cpy; - } - - SDL_UnlockMutex(queue->lock); - - return (size_t)(ptr - buf); -} - -size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len) -{ - size_t len = _len; - Uint8 *buf = (Uint8 *)_buf; - Uint8 *ptr = buf; - SDL_DataQueuePacket *packet; - - if (queue == NULL) { - return 0; - } - - SDL_LockMutex(queue->lock); - - while ((len > 0) && ((packet = queue->head) != NULL)) { - const size_t avail = packet->datalen - packet->startpos; - const size_t cpy = SDL_min(len, avail); - SDL_assert(queue->queued_bytes >= avail); - - SDL_memcpy(ptr, packet->data + packet->startpos, cpy); - packet->startpos += cpy; - ptr += cpy; - queue->queued_bytes -= cpy; - len -= cpy; - - if (packet->startpos == packet->datalen) { /* packet is done, put it in the pool. */ - queue->head = packet->next; - SDL_assert((packet->next != NULL) || (packet == queue->tail)); - packet->next = queue->pool; - queue->pool = packet; - } - } - - SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0)); - - if (queue->head == NULL) { - queue->tail = NULL; /* in case we drained the queue entirely. */ - } - - SDL_UnlockMutex(queue->lock); - - return (size_t)(ptr - buf); -} - -size_t SDL_GetDataQueueSize(SDL_DataQueue *queue) -{ - size_t retval = 0; - if (queue) { - SDL_LockMutex(queue->lock); - retval = queue->queued_bytes; - SDL_UnlockMutex(queue->lock); - } - return retval; -} - -SDL_Mutex *SDL_GetDataQueueMutex(SDL_DataQueue *queue) -{ - return queue ? queue->lock : NULL; -} - diff --git a/src/SDL_dataqueue.h b/src/SDL_dataqueue.h deleted file mode 100644 index c9ea83054..000000000 --- a/src/SDL_dataqueue.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2023 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#ifndef SDL_dataqueue_h_ -#define SDL_dataqueue_h_ - -/* this is not (currently) a public API. But maybe it should be! */ - -struct SDL_DataQueue; -typedef struct SDL_DataQueue SDL_DataQueue; - -SDL_DataQueue *SDL_CreateDataQueue(const size_t packetlen, const size_t initialslack); -void SDL_DestroyDataQueue(SDL_DataQueue *queue); -void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack); -int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *data, const size_t len); -size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *buf, const size_t len); -size_t SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *buf, const size_t len); -size_t SDL_GetDataQueueSize(SDL_DataQueue *queue); -SDL_Mutex *SDL_GetDataQueueMutex(SDL_DataQueue *queue); /* don't destroy this, obviously. */ - -#endif /* SDL_dataqueue_h_ */