Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10574 in orxonox.OLD for branches/cleanup/src/lib/util/threads


Ignore:
Timestamp:
Feb 7, 2007, 9:21:02 PM (18 years ago)
Author:
bensch
Message:

added new thread classes

Location:
branches/cleanup/src/lib/util/threads
Files:
5 added
2 copied

Legend:

Unmodified
Added
Removed
  • branches/cleanup/src/lib/util/threads/threading.cc

    r10569 r10574  
    1 /*
    2    orxonox - the future of 3D-vertical-scrollers
    3 
    4    Copyright (C) 2004 orx
    5 
    6    This program is free software; you can redistribute it and/or modify
    7    it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2, or (at your option)
    9    any later version.
    10 
    11    ### File Specific:
    12    main-programmer: ...
    13    co-programmer: ...
    14 */
    15 
    16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    17 
    18 #include "threading.h"
    19 
    20 
    21 
    22 namespace OrxThread
    23 {
    24 
    25 /**
    26  * standard constructor
    27  * @todo this constructor is not jet implemented - do it
    28 */
    29 // Thread::Thread()
    30 // {
    31 // }
    32 
    33 
    34 /**
    35  * standard deconstructor
    36 */
    37 // Thread::~Thread()
    38 // {
    39 //   // delete what has to be deleted here
    40 // }
    41 
    42 }
  • branches/cleanup/src/lib/util/threads/threading.h

    r10569 r10574  
    99#define _THREADING_H
    1010
    11 #ifdef HAVE_SDL_H
    12  #include <SDL_thread.h>
    13 #else
    14  #include <SDL/SDL_thread.h>
    15 #endif
    16 
    17 namespace OrxThread
    18 {
    19   //! A class for Wrapping Threads
    20   class Thread
    21   {
    22   public:
    23     Thread(int (*fn)(void *), void *data) { this->thread = SDL_CreateThread(fn, data); };
    24     virtual ~Thread() { SDL_KillThread(this->thread); }
    25     void exit ( int returnCode = 0 );
    26     bool isFinished () const;
    27     bool isRunning () const;
    28     void wait() { SDL_WaitThread(this->thread, NULL); };
    29 
    30     void start();
    31     void terminate();
     11#include "thread.h"
     12#include "mutex.h"
     13#include "mutex_locker.h"
    3214
    3315
    34   private:
    35     SDL_Thread* thread;
    36 
    37   };
    38 
    39   class Mutex
    40   {
    41   public:
    42     Mutex() {  this->mutex = SDL_CreateMutex(); };
    43     ~Mutex() { SDL_DestroyMutex(this->mutex); }
    44 
    45     void lock() { SDL_mutexP(mutex); };
    46     void unlock() { SDL_mutexV(mutex); };
    47 
    48     SDL_mutex* getMutex() const { return this->mutex; };
    49   private:
    50     SDL_mutex* mutex;
    51   };
    52 
    53   //! A Class that locks a Mutex within its scope
    54   class MutexLock
    55   {
    56   public:
    57     //! Locks the Mutex mutex in this Scope.
    58     MutexLock(Mutex* mutex) { SDL_mutexP(mutex->getMutex()); this->mutex = mutex; };
    59     ~MutexLock() { SDL_mutexV(mutex->getMutex()); };
    60   private:
    61     Mutex* mutex;         //!< The Mutex to lock.
    62   };
    63 }
    6416
    6517#endif /* _THREADING_H */
Note: See TracChangeset for help on using the changeset viewer.