Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7314 in orxonox.OLD for trunk/src/lib/shell


Ignore:
Timestamp:
Apr 17, 2006, 1:19:20 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellBuffer is now ThreadSafe for printing to it
I must say: SDL_Thread's are way easier than simple pThreads

Location:
trunk/src/lib/shell
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_buffer.cc

    r6222 r7314  
    4242
    4343ShellBuffer* ShellBuffer::singletonRef = NULL;
     44SDL_mutex* ShellBuffer::bufferMutex = NULL;
    4445
    4546/**
     
    5253
    5354  this->flush();
     55
     56  if (ShellBuffer::bufferMutex != NULL)
     57    SDL_DestroyMutex(ShellBuffer::bufferMutex);
     58  ShellBuffer::bufferMutex = NULL;
    5459
    5560  ShellBuffer::singletonRef = NULL;
     
    103108  va_start(arguments, line);
    104109
     110  if (ShellBuffer::bufferMutex == NULL)
     111    ShellBuffer::bufferMutex = SDL_CreateMutex();
     112
     113  SDL_mutexP(ShellBuffer::bufferMutex);
    105114#if DEBUG < 3
    106115  if (ShellBuffer::singletonRef == NULL)
    107116#endif
    108 
    109117    vprintf(line, arguments);
    110118#if DEBUG < 3
     
    114122#endif
    115123    ShellBuffer::singletonRef->addBufferLine(line, arguments);
     124  SDL_mutexV(ShellBuffer::bufferMutex);
    116125  return true;
    117126}
  • trunk/src/lib/shell/shell_buffer.h

    r5784 r7314  
    1010#include <stdarg.h>
    1111#include <list>
     12#include <SDL_thread.h>
    1213
    1314#define      SHELL_BUFFER_SIZE       16384         //!< The Size of the input-buffers (should be large enough to carry any kind of input)
     
    6061
    6162    unsigned long            lineCount;                          //!< how many Lines have been written out so far.
     63
     64    static SDL_mutex*        bufferMutex;                        //!< Only one thread may write into the ShellBuffer at a time.
    6265};
    6366
Note: See TracChangeset for help on using the changeset viewer.