missing
stamp-h1
neonserv
-neonserv.exe
+neonserv*.exe
libmysql.dll
+pthreadGC2.dll
motd.txt
\ No newline at end of file
static pthread_mutex_t synchronized_recv;
struct ParseOrder {
- unsigned long tid;
+ unsigned int tid;
struct ParseOrder *next;
};
struct ParseOrder *parse_order = NULL;
return 1;
}
#else
-static int connect_socket(struct ClientSocket *client) {
+static int _connect_socket(struct ClientSocket *client) {
if((client->flags & SOCKET_FLAG_CONNECTED)) return 1;
struct hostent *host;
struct sockaddr_in addr;
}
#if HAVE_THREADS
-static void clientsocket_start_of_recv(unsigned long tid) {
+static void clientsocket_start_of_recv(unsigned int tid) {
SYNCHRONIZE(whohandler_sync);
struct ParseOrder *entry, *last;
for(last = parse_order; last; last = last->next) {
DESYNCHRONIZE(whohandler_sync);
}
-static void clientsocket_end_of_recv(unsigned long tid) {
+static void clientsocket_end_of_recv(unsigned int tid) {
SYNCHRONIZE(whohandler_sync);
struct ParseOrder *entry, *last = NULL;
for(entry = parse_order; entry; entry = entry->next) {
DESYNCHRONIZE(whohandler_sync);
}
-int clientsocket_parseorder_top(unsigned long tid) {
+int clientsocket_parseorder_top(unsigned int tid) {
if(parse_order && parse_order->tid == tid)
return 1;
else
sock->bufferpos -= used;
}
is_synchronized = 0;
- unsigned long tid = syscall(SYS_gettid);
+ unsigned int tid = (unsigned int) pthread_self_tid();
clientsocket_start_of_recv(tid);
DESYNCHRONIZE(synchronized_recv);
parse_lines(sock, linesbuf, used);
int write_socket_force(struct ClientSocket *client, char* msg, int len);
int write_socket(struct ClientSocket *client, char* msg, int len);
#ifdef HAVE_THREADS
-int clientsocket_parseorder_top(unsigned long tid);
+int clientsocket_parseorder_top(unsigned int tid);
#endif
void socket_loop(int timeout_seconds);
void putsock(struct ClientSocket *client, const char *text, ...) PRINTF_LIKE(2, 3);
if(do_match) {
#ifdef HAVE_THREADS
- unsigned long tid = syscall(SYS_gettid);
+ unsigned int tid = (unsigned int) pthread_self_tid();
while(!clientsocket_parseorder_top(tid)) {
usleep(1000); //1ms
}
int argc = 0;
char *argv[MAXNUMPARAMS];
#ifdef HAVE_THREADS
- printf("[%lu recv %lu] %s\n", syscall(SYS_gettid), (unsigned long) strlen(line), line);
+ printf("[%d recv %lu] %s\n", getCurrentThreadID(), (unsigned long) strlen(line), line);
#else
printf("[recv %lu] %s\n", (unsigned long) strlen(line), line);
#endif
#include "ConfigParser.h"
#include "bots.h"
+#ifdef WIN32
+typedef uint32_t socklen_t;
+#endif
+
#define QSERVER_TIMEOUT 30
#define QSERVER_MAXCLIENTS 100
if (server_sockfd < 0)
return;
struct sockaddr_in serv_addr;
- bzero((char *) &serv_addr, sizeof(serv_addr));
+ memset(&serv_addr, 0, sizeof(serv_addr));
int portno = get_int_field("QServer.port");
if(!portno)
portno = 7499;
struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, type, 0);
if(entry == NULL) return;
#ifdef HAVE_THREADS
- unsigned long tid = syscall(SYS_gettid);
+ unsigned int tid = (unsigned int) pthread_self_tid();
while(!clientsocket_parseorder_top(tid)) {
usleep(1000); //1ms
}
struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, type, 0);
if(entry == NULL) return;
#ifdef HAVE_THREADS
- unsigned long tid = syscall(SYS_gettid);
+ unsigned int tid = (unsigned int) pthread_self_tid();
while(!clientsocket_parseorder_top(tid)) {
usleep(1000); //1ms
}
#ifdef HAVE_THREADS
content[0] = get_language_string(user, "NS_NETINFO_THREADS");
- sprintf(tmp, "%d (current tid: %lu)", running_threads, syscall(SYS_gettid));
+ sprintf(tmp, "%d (current thread: %i)", running_threads, getCurrentThreadID());
content[1] = tmp;
table_add(table, content);
#endif
}
#ifdef HAVE_THREADS
+pthread_t *current_threads = NULL;
+
void * thread_main(void *arg) {
time_t socket_wait;
while(running) {
running_threads--;
return NULL;
}
+
+int getCurrentThreadID() {
+ if(!current_threads) return 0;
+ int i;
+ unsigned int my_tid = (unsigned int) pthread_self_tid();
+ for(i = 0; i < running_threads; i++) {
+ #ifdef WIN32
+ if((unsigned int) current_threads[i].p == my_tid)
+ #else
+ if((unsigned int) current_threads[i] == my_tid)
+ #endif
+ return i+1;
+ }
+ return 0;
+}
+
#endif
int main(int argc, char *argv[]) {
int worker_threads = get_int_field("General.worker_threads");
if(!worker_threads) worker_threads = 1;
-
running = 1;
#ifdef HAVE_THREADS
- pthread_t tid[worker_threads];
int tid_id = 0;
+ current_threads = calloc(worker_threads, sizeof(*current_threads));
for(tid_id = 0; tid_id < worker_threads; tid_id++) {
running_threads++;
- pthread_create(&tid[tid_id], NULL, thread_main, NULL);
+ pthread_create(¤t_threads[tid_id], NULL, thread_main, NULL);
}
int usleep_delay = 1000000 / TICKS_PER_SECOND;
while(running) {
usleep(usleep_delay);
}
for(tid_id = 0; tid_id < worker_threads; tid_id++) {
- pthread_join(tid[tid_id], NULL);
+ pthread_join(current_threads[tid_id], NULL);
}
running_threads = 0;
#else
#define NEONSERV_VERSION "5.3"
#define VERSION_PATCHLEVEL 543
-#include <features.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
#include <malloc.h>
#else
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <time.h>
#ifdef HAVE_THREADS
#include <pthread.h>
-#include <sys/syscall.h>
+#ifdef WIN32
+#define pthread_self_tid() pthread_self().p
+#else
+#define pthread_self_tid() pthread_self()
+#endif
#define THREAD_MUTEX_INIT(var) { \
pthread_mutexattr_t mutex_attr; \
pthread_mutexattr_init(&mutex_attr);\
extern int running_threads;
extern pthread_mutex_t cache_sync;
extern pthread_mutex_t whohandler_sync, whohandler_mass_sync;
+
+int getCurrentThreadID();
#endif
int stricmp (const char *s1, const char *s2);
#define DATABASE_VERSION "15"
struct mysql_conn_struct {
- unsigned long tid;
+ unsigned int tid;
MYSQL *mysql_conn;
struct used_result *used_results;
struct escaped_string *escaped_strings;
struct mysql_conn_struct *get_mysql_conn_struct() {
SYNCHRONIZE(synchronized);
struct mysql_conn_struct *mysql_conn;
- unsigned long tid;
+ unsigned int tid;
#ifdef HAVE_THREADS
- tid = syscall(SYS_gettid);
+ tid = (unsigned int) pthread_self_tid();
#else
tid = 1;
#endif