/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* Known contributors to this file:
* Sasha Mikheev
* Steve McClure, 1998
- * Markus Armbruster, 2005-2009
+ * Markus Armbruster, 2005-2012
* Ron Koenderink, 2007-2009
*/
#include <unistd.h>
#include "misc.h"
#include "empthread.h"
+#include "file.h"
#include "prototypes.h"
struct empth_t {
ctx->wakeup = 0;
pthread_setspecific(ctx_key, ctx);
pthread_mutex_lock(&mtx_ctxsw);
- logerror("pthreads initialized");
return 0;
}
int eno;
empth_status("creating new thread %s", name);
+ ef_make_stale();
ctx = malloc(sizeof(empth_t));
if (!ctx) {
empth_t *
empth_self(void)
{
- return pthread_getspecific(ctx_key);
+ return udata ? pthread_getspecific(ctx_key) : NULL;
}
char *
empth_t *ctx = pthread_getspecific(ctx_key);
empth_status("empth_exit");
+ ef_make_stale();
pthread_mutex_unlock(&mtx_ctxsw);
free(ctx->name);
free(ctx);
void
empth_yield(void)
{
+ ef_make_stale();
pthread_mutex_unlock(&mtx_ctxsw);
pthread_mutex_lock(&mtx_ctxsw);
empth_restorectx();
empth_t *ctx;
int res = 0;
+ if (CANT_HAPPEN(fd < 0 || fd >= FD_SETSIZE)) {
+ errno = EBADF;
+ return -1;
+ }
+
+ ef_make_stale();
pthread_mutex_unlock(&mtx_ctxsw);
empth_status("select on %d for %d", fd, flags);
struct timeval tv;
int res;
+ ef_make_stale();
pthread_mutex_unlock(&mtx_ctxsw);
do {
now = time(NULL);
sigset_t set;
int sig, err;
+ ef_make_stale();
sigemptyset(&set);
sigaddset(&set, SIGHUP);
sigaddset(&set, SIGINT);
{
empth_status("wrlock %s %d %d",
rwlock->name, rwlock->nread, rwlock->nwrite);
+ ef_make_stale();
rwlock->nwrite++;
while (rwlock->nread != 0 || rwlock->nwrite != 1) {
empth_status("waiting for wrlock %s", rwlock->name);
pthread_cond_wait(&rwlock->can_write, &mtx_ctxsw);
empth_status("got wrlock %s %d %d",
- rwlock->name, rwlock->nread, rwlock->nwrite);
+ rwlock->name, rwlock->nread, rwlock->nwrite);
empth_restorectx();
}
}
{
empth_status("rdlock %s %d %d",
rwlock->name, rwlock->nread, rwlock->nwrite);
+ ef_make_stale();
while (rwlock->nwrite) {
empth_status("waiting for rdlock %s", rwlock->name);
pthread_cond_wait(&rwlock->can_read, &mtx_ctxsw);