Merge branch 'cpp-11' into crashlog_improvements
# Conflicts: # Makefile.src.in # projects/determineversion.vbs # source.list # src/crashlog.cpp # src/misc.cpp # src/os/unix/crashlog_unix.cpp # src/os/windows/crashlog_win.cpp # src/rev.h # src/thread/thread.h # src/thread/thread_morphos.cpp # src/thread/thread_none.cpp # src/thread/thread_os2.cpp # src/thread/thread_pthread.cpp # src/thread/thread_win32.cpp
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "../../debug.h"
|
||||
#include "../../string_func.h"
|
||||
#include "../../fios.h"
|
||||
#include "../../thread.h"
|
||||
|
||||
|
||||
#include <dirent.h>
|
||||
@@ -43,39 +44,24 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __MORPHOS__
|
||||
#include <exec/types.h>
|
||||
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
|
||||
|
||||
/* The system supplied definition of SIG_IGN does not match */
|
||||
#undef SIG_IGN
|
||||
#define SIG_IGN (void (*)(int))1
|
||||
#endif /* __MORPHOS__ */
|
||||
|
||||
#ifdef __AMIGA__
|
||||
#warning add stack symbol to avoid that user needs to set stack manually (tokai)
|
||||
// ULONG __stack =
|
||||
#ifndef NO_THREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if defined(WITH_SDL)
|
||||
# if defined(WITH_SDL)
|
||||
/* the mac implementation needs this file included in the same file as main() */
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
# include <SDL.h>
|
||||
# endif
|
||||
|
||||
# include "../macosx/macos.h"
|
||||
#endif
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
bool FiosIsRoot(const char *path)
|
||||
{
|
||||
#if !defined(__MORPHOS__) && !defined(__AMIGAOS__)
|
||||
return path[1] == '\0';
|
||||
#else
|
||||
/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
|
||||
const char *s = strchr(path, ':');
|
||||
return s != NULL && s[1] == '\0';
|
||||
#endif
|
||||
}
|
||||
|
||||
void FiosGetDrives(FileList &file_list)
|
||||
@@ -106,15 +92,8 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
int res;
|
||||
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
||||
/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
|
||||
if (FiosIsRoot(path)) {
|
||||
res = seprintf(filename, lastof(filename), "%s:%s", path, ent->d_name);
|
||||
} else // XXX - only next line!
|
||||
#else
|
||||
assert(path[strlen(path) - 1] == PATHSEPCHAR);
|
||||
if (strlen(path) > 2) assert(path[strlen(path) - 2] != PATHSEPCHAR);
|
||||
#endif
|
||||
res = seprintf(filename, lastof(filename), "%s%s", path, ent->d_name);
|
||||
|
||||
/* Could we fully concatenate the path and filename? */
|
||||
@@ -294,74 +273,7 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
#endif
|
||||
|
||||
|
||||
/* multi os compatible sleep function */
|
||||
|
||||
#ifdef __AMIGA__
|
||||
/* usleep() implementation */
|
||||
# include <devices/timer.h>
|
||||
# include <dos/dos.h>
|
||||
|
||||
extern struct Device *TimerBase = NULL;
|
||||
extern struct MsgPort *TimerPort = NULL;
|
||||
extern struct timerequest *TimerRequest = NULL;
|
||||
#endif /* __AMIGA__ */
|
||||
|
||||
void CSleep(int milliseconds)
|
||||
{
|
||||
#if defined(__BEOS__)
|
||||
snooze(milliseconds * 1000);
|
||||
#elif defined(__AMIGA__)
|
||||
{
|
||||
ULONG signals;
|
||||
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
|
||||
|
||||
/* send IORequest */
|
||||
TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
|
||||
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000;
|
||||
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000;
|
||||
SendIO((struct IORequest *)TimerRequest);
|
||||
|
||||
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
|
||||
AbortIO((struct IORequest *)TimerRequest);
|
||||
}
|
||||
WaitIO((struct IORequest *)TimerRequest);
|
||||
}
|
||||
#else
|
||||
usleep(milliseconds * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef __APPLE__
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
uint count = 1;
|
||||
#ifdef HAS_SYSCTL
|
||||
int ncpu = 0;
|
||||
size_t len = sizeof(ncpu);
|
||||
|
||||
#ifdef OPENBSD
|
||||
int name[2];
|
||||
name[0] = CTL_HW;
|
||||
name[1] = HW_NCPU;
|
||||
if (sysctl(name, 2, &ncpu, &len, NULL, 0) < 0) {
|
||||
ncpu = 0;
|
||||
}
|
||||
#else
|
||||
if (sysctlbyname("hw.availcpu", &ncpu, &len, NULL, 0) < 0) {
|
||||
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
|
||||
}
|
||||
#endif /* #ifdef OPENBSD */
|
||||
|
||||
if (ncpu > 0) count = ncpu;
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
long res = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (res > 0) count = res;
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void OSOpenBrowser(const char *url)
|
||||
{
|
||||
pid_t child_pid = fork();
|
||||
@@ -375,4 +287,56 @@ void OSOpenBrowser(const char *url)
|
||||
DEBUG(misc, 0, "Failed to open url: %s", url);
|
||||
exit(0);
|
||||
}
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
void SetCurrentThreadName(const char *threadName) {
|
||||
#if !defined(NO_THREADS) && defined(__GLIBC__)
|
||||
#if __GLIBC_PREREQ(2, 12)
|
||||
if (threadName) pthread_setname_np(pthread_self(), threadName);
|
||||
#endif /* __GLIBC_PREREQ(2, 12) */
|
||||
#endif /* !defined(NO_THREADS) && defined(__GLIBC__) */
|
||||
#if defined(__APPLE__)
|
||||
MacOSSetThreadName(threadName);
|
||||
#endif /* defined(__APPLE__) */
|
||||
}
|
||||
|
||||
int GetCurrentThreadName(char *str, const char *last)
|
||||
{
|
||||
#if !defined(NO_THREADS) && defined(__GLIBC__)
|
||||
#if __GLIBC_PREREQ(2, 12)
|
||||
char buffer[16];
|
||||
int result = pthread_getname_np(pthread_self(), buffer, sizeof(buffer));
|
||||
if (result == 0) {
|
||||
return seprintf(str, last, "%s", buffer);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static pthread_t main_thread;
|
||||
|
||||
void SetSelfAsMainThread()
|
||||
{
|
||||
#if !defined(NO_THREADS)
|
||||
main_thread = pthread_self();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsMainThread()
|
||||
{
|
||||
#if !defined(NO_THREADS)
|
||||
return main_thread == pthread_self();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsNonMainThread()
|
||||
{
|
||||
#if !defined(NO_THREADS)
|
||||
return main_thread != pthread_self();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user