activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgliu <sheng...@sina.com>
Subject VC & pthread.h
Date Thu, 09 Nov 2006 02:57:49 GMT

#ifndef ACTIVEMQ_CONCURRENT_MUTEX_H
#define ACTIVEMQ_CONCURRENT_MUTEX_H

// Includes.
#include <activemq/concurrent/Synchronizable.h>
#include <pthread.h>

namespace activemq{
namespace concurrent{
    
  /**
   * Creates a pthread_mutex_t object. The object is created
   * such that successive locks from the same thread is allowed
   * and will be successful.
   * @author  Nathan Mittler
   * @see  pthread_mutex_t
   */
  class Mutex : public Synchronizable
  {
  public:

    /**
     * Constructor - creates and initializes the mutex.
     */
    Mutex()
    {
	    // Create an attributes object and initialize it.
	    // Assign the recursive attribute so that the same thread may
	    // lock this mutex repeatedly.
	    pthread_mutexattr_t attributes;
	    pthread_mutexattr_init( &attributes );

       #if defined(__USE_UNIX98) || defined(__APPLE__)
	        pthread_mutexattr_settype( &attributes, PTHREAD_MUTEX_RECURSIVE );
       #endif

	    // Initialize the mutex.
	    pthread_mutex_init( &mutex, &attributes );
	
	    // Destroy the attributes.
	    pthread_mutexattr_destroy( &attributes );
  	}

    /**
     * Destructor - destroys the mutex object.
     */
    virtual ~Mutex()
    {
	    // Unlock the mutex.
	    unlock();
	
	    // Destroy the mutex.
	    pthread_mutex_destroy( &mutex );
  	}

    /**
     * Locks the object.
     * @return  true if the lock was successful, otherwise false.
     */
    virtual bool lock()
    {
    	return pthread_mutex_lock( &mutex ) == 0;
  	}

    /**
     * Unlocks the object.
     * @return  true if the unlock was successful, otherwise false.
     */
    virtual bool unlock()
    {
    	return pthread_mutex_unlock( &mutex ) == 0;
  	}

  private:       // Data

    /**
     * The mutex object.
     */
    pthread_mutex_t mutex;

  };

}}

#endif // ACTIVEMQ_CONCURRENT_MUTEX_H

I compile these codes by Visual Studio 2005 C++ (Windows XP Sp2)
fatal error C1083: can not open this file :“pthread.h”: No such file or
directory
please help me 
-- 
View this message in context: http://www.nabble.com/VC---pthread.h-tf2599406.html#a7251617
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Mime
View raw message