Warning fixes and cleanups when building with SIMPLE_THREADS

This commit is contained in:
rdb 2018-10-16 21:19:06 +02:00
parent 0c9c698d13
commit 88b0f3327d
7 changed files with 43 additions and 45 deletions

View File

@ -445,7 +445,7 @@ do_flush() {
if (data_sent > 0) {
total_sent += data_sent;
}
double last_report = 0;
while (!okflag && tcp->Active() &&
(data_sent > 0 || tcp->GetLastError() == LOCAL_BLOCKING_ERROR)) {
if (data_sent == 0) {

View File

@ -1,8 +1,4 @@
/* Filename: contextSwitch_longjmp_src.c
* Created by: drose (15Apr10)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
@ -10,7 +6,10 @@
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* @file contextSwitch_longjmp_src.c
* @author drose
* @date 2010-04-15
*/
/* This is the implementation of user-space context switching using
setmp() / longjmp(). This is the hackier implementation,
@ -90,14 +89,14 @@ void
cs_longjmp(cs_jmp_buf env) {
_asm {
mov eax, env;
mov ebx, [eax + 0];
mov edi, [eax + 4];
mov esi, [eax + 8];
mov ebp, [eax + 12];
mov esp, [eax + 16];
mov edx, [eax + 20];
frstor [eax + 24]; /* restore floating-point state */
mov eax, 1; /* return 1 from setjmp: pass 2 return */
@ -251,7 +250,7 @@ setup_context_1(void) {
}
void
init_thread_context(struct ThreadContext *context,
init_thread_context(struct ThreadContext *context,
unsigned char *stack, size_t stack_size,
ThreadFunction *thread_func, void *data) {
/* Copy all of the input parameters to static variables, then begin
@ -263,7 +262,7 @@ init_thread_context(struct ThreadContext *context,
st_data = data;
setup_context_1();
}
}
void
save_thread_context(struct ThreadContext *context,

View File

@ -1,8 +1,4 @@
/* Filename: contextSwitch_posix_src.c
* Created by: drose (15Apr10)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
@ -10,7 +6,10 @@
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* @file contextSwitch_posix_src.c
* @author drose
* @date 2010-04-15
*/
/* This is the implementation of user-space context switching using
posix threads to manage the different execution contexts. This
@ -44,7 +43,7 @@ struct ThreadContext {
pthread_mutex_t _ready_mutex;
pthread_cond_t _ready_cvar;
int _ready_flag;
/* This is set FALSE while the thread is alive, and TRUE if the
thread is to be terminated when it next wakes up. */
int _terminated;
@ -83,19 +82,19 @@ thread_main(void *data) {
}
void
init_thread_context(struct ThreadContext *context,
init_thread_context(struct ThreadContext *context,
unsigned char *stack, size_t stack_size,
ThreadFunction *thread_func, void *data) {
context->_thread_func = thread_func;
context->_data = data;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, stack_size);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_create(&(context->_thread), &attr, thread_main, context);
pthread_attr_destroy(&attr);
pthread_create(&(context->_thread), &attr, thread_main, context);
pthread_attr_destroy(&attr);
}
void
@ -142,7 +141,7 @@ switch_to_thread_context(struct ThreadContext *from_context,
/* We've been rudely terminated. Exit gracefully. */
pthread_exit(NULL);
}
/* Now we have been signaled again, and we're ready to resume the
thread. */
longjmp(from_context->_jmp_context, 1);
@ -164,7 +163,7 @@ alloc_thread_context() {
pthread_mutexattr_init(&attr);
// The symbol PTHREAD_MUTEX_DEFAULT isn't always available?
// pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
int result = pthread_mutex_init(&context->_ready_mutex, &attr);
pthread_mutex_init(&context->_ready_mutex, &attr);
pthread_mutexattr_destroy(&attr);
pthread_cond_init(&context->_ready_cvar, NULL);

View File

@ -1,8 +1,4 @@
/* Filename: contextSwitch_ucontext_src.c
* Created by: drose (15Apr10)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
@ -10,7 +6,10 @@
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* @file contextSwitch_ucontext_src.c
* @author drose
* @date 2010-04-15
*/
/* This is the implementation of user-space context switching using
getcontext() / setcontext(). This is the preferred implementation,
@ -43,7 +42,7 @@ begin_context(ThreadFunction *thread_func, void *data) {
}
void
init_thread_context(struct ThreadContext *context,
init_thread_context(struct ThreadContext *context,
unsigned char *stack, size_t stack_size,
ThreadFunction *thread_func, void *data) {
if (getcontext(&context->_ucontext) != 0) {

View File

@ -1,8 +1,4 @@
/* Filename: contextSwitch_windows_src.c
* Created by: drose (15Apr10)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
@ -10,7 +6,10 @@
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* @file contextSwitch_windows_src.c
* @author drose
* @date 2010-04-15
*/
/* This is the implementation of user-space context switching using
native Windows threading constructs to manage the different
@ -37,7 +36,7 @@ struct ThreadContext {
/* This event is in the signaled state when the thread is ready to
roll. */
HANDLE _ready;
/* This is set FALSE while the thread is alive, and TRUE if the
thread is to be terminated when it next wakes up. */
int _terminated;
@ -71,13 +70,13 @@ thread_main(LPVOID data) {
}
void
init_thread_context(struct ThreadContext *context,
init_thread_context(struct ThreadContext *context,
unsigned char *stack, size_t stack_size,
ThreadFunction *thread_func, void *data) {
context->_thread_func = thread_func;
context->_data = data;
context->_thread = CreateThread(NULL, stack_size,
context->_thread = CreateThread(NULL, stack_size,
thread_main, context, 0, NULL);
}
@ -117,7 +116,7 @@ switch_to_thread_context(struct ThreadContext *from_context,
/* We've been rudely terminated. Exit gracefully. */
ExitThread(1);
}
/* Now we have been signaled again, and we're ready to resume the
thread. */
longjmp(from_context->_jmp_context, 1);

View File

@ -225,7 +225,7 @@ call_python_func(PyObject *function, PyObject *args) {
} else {
// No exception. Restore the thread state normally.
PyThreadState *state = PyThreadState_Swap(orig_thread_state);
PyThreadState_Swap(orig_thread_state);
thread_states.push_back(new_thread_state);
// PyThreadState_Clear(new_thread_state);
// PyThreadState_Delete(new_thread_state);

View File

@ -20,7 +20,9 @@
#include "mainThread.h"
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#endif