Skip to content

Commit

Permalink
Merge pull request Meridian59#338 from ckirmse/master
Browse files Browse the repository at this point in the history
fix up blakserv makefile, mutex for linux
  • Loading branch information
Meridian59 committed Jan 8, 2016
2 parents b6581de + d19dba6 commit b0dbe4d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
6 changes: 2 additions & 4 deletions blakserv/makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TOPDIR=..

include $(TOPDIR)/common.mak.linux

CFLAGS += -I $(BLAKINCLUDEDIR)
CFLAGS += -I $(BLAKINCLUDEDIR) -pthread

SOURCEDIR = .

Expand Down Expand Up @@ -96,9 +96,7 @@ $(OUTDIR)/md5.obj : $(TOPDIR)/util/md5.c

$(OUTDIR)/blakserv: $(OBJS)
$(CC) $(CFLAGS) -o $@ -c $(SOURCEDIR)/version.c
$(LINK) $(LIBS) $^ -o$@ $(LINKFLAGS)
$(LINK) $^ $(LIBS) -o$@ $(LINKFLAGS)
$(CP) $@ $(BLAKSERVRUNDIR)

# $(LINK) $@ $(LIBS) $(LINKFLAGS)

include $(TOPDIR)/rules.mak.linux
17 changes: 5 additions & 12 deletions blakserv/mutex_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,13 @@ bool MutexAcquire(Mutex mutex) {
}

bool MutexAcquireWithTimeout(Mutex mutex, int timeoutMs) {
// we'd like to do this to be clean, but it doesn't exist:
timespec ts;

//timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += (timeoutMs / 1000L);
ts.tv_nsec += (timeoutMs - ((timeoutMs / 1000L) * 1000L)) * 1000000L;

//clock_gettime(CLOCK_REALTIME, &ts);
//ts.tv_sec += (timeoutMs / 1000L);
//ts.tv_nsec += (timeoutMs - ((timeoutMs / 1000L) * 1000L)) * 1000000L;

//return pthread_mutex_timedlock(&mutex->mutex, &ts);

// since we only have one thread in the linux version of the server,
// this locking is pointless anyway, so just wait as long as necessary
// (which will always be no waiting at all)
return pthread_mutex_lock(&mutex->mutex) == 0;
return pthread_mutex_timedlock(&mutex->mutex, &ts) == 0;
}

bool MutexRelease(Mutex mutex) {
Expand Down
14 changes: 3 additions & 11 deletions blakserv/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,8 @@ void CloseSession(int session_id)
DeleteBufferList(s->send_list);
s->send_list = NULL;

/* no need to release mutex... we're closing it */
/*
if (!MutexRelease(s->muxSend))
eprintf("File %s line %i release of non-owned mutex\n",__FILE__,__LINE__);
*/

eprintf("File %s line %i release of non-owned mutex\n",__FILE__,__LINE__);
}

if (!MutexAcquireWithTimeout(s->muxReceive,10000))
Expand All @@ -463,14 +459,10 @@ void CloseSession(int session_id)
DeleteBufferList(s->receive_list);
s->receive_list = NULL;

/* no need to release mutex... we're closing it */
/*
if (!MutexRelease(s->muxReceive))
eprintf("File %s line %i release of non-owned mutex\n",__FILE__,__LINE__);
*/

eprintf("File %s line %i release of non-owned mutex\n",__FILE__,__LINE__);
}

if (!MutexClose(s->muxSend))
eprintf("CloseSession error (%s) closing send mutex %i in session %i\n",
GetLastErrorStr(),s->muxSend,s->session_id);
Expand Down
2 changes: 1 addition & 1 deletion rules.mak.linux
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $(OUTDIR)/%.obj : $(OUTDIR)/%.c
$(CC) $(CFLAGS) -I $(SOURCEDIR) -o $@ -c $<

makedirs:
-@mkdir $(OUTDIR)
-@mkdir -p $(OUTDIR)

clean:
@$(RM) $(OUTDIR)/*
Expand Down

0 comments on commit b0dbe4d

Please sign in to comment.