UFO: Alien Invasion
Loading...
Searching...
No Matches
sv_log.cpp
Go to the documentation of this file.
1
7
8/*
9All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25*/
26
27#include "server.h"
28#include "sv_log.h"
30#include <SDL_thread.h>
31
32static SDL_mutex* svLogMutex;
34
35static void SV_LogPrintOutput (const char* string)
36{
37 Com_Printf("%s", string);
38}
39
45{
46 SDL_LockMutex(svLogMutex);
49 SDL_UnlockMutex(svLogMutex);
50}
51
60void SV_LogAdd (const char* format, va_list ap)
61{
62 char msg[1024];
63
64 Q_vsnprintf(msg, sizeof(msg), format, ap);
65
66 SDL_LockMutex(svLogMutex);
68 SDL_UnlockMutex(svLogMutex);
69}
70
71void SV_LogInit (void)
72{
73 const size_t svHunkSize = 32768;
74 svLogMutex = SDL_CreateMutex();
75 svLogHunk = STRHUNK_Create(svHunkSize);
76}
77
78void SV_LogShutdown (void)
79{
80 SDL_DestroyMutex(svLogMutex);
81 svLogMutex = nullptr;
83}
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
void format(__printf__, 1, 2)))
Main server include file.
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition shared.cpp:535
bool STRHUNK_Add(stringHunk_t *hunk, const char *string)
stringHunk_t * STRHUNK_Create(size_t size)
void STRHUNK_Delete(stringHunk_t **hunk)
void STRHUNK_Visit(stringHunk_t *hunk, stringHunkVisitor_t visitor)
void STRHUNK_Reset(stringHunk_t *hunk)
Header for string hunk management.
void SV_LogInit(void)
Definition sv_log.cpp:71
static void SV_LogPrintOutput(const char *string)
Definition sv_log.cpp:35
static SDL_mutex * svLogMutex
Definition sv_log.cpp:32
void SV_LogAdd(const char *format, va_list ap)
Async version to add a log entry for the game lib.
Definition sv_log.cpp:60
void SV_LogShutdown(void)
Definition sv_log.cpp:78
void SV_LogHandleOutput(void)
Handle the log output from the main thread by reading the strings from the dbuffer the game lib threa...
Definition sv_log.cpp:44
static stringHunk_t * svLogHunk
Definition sv_log.cpp:33
game lib logging handling