2011-04-28 16:35:58 +02:00
|
|
|
/*
|
|
|
|
*
|
2011-04-30 04:28:31 +02:00
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/idpl.html.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on
|
|
|
|
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
|
|
|
|
* express or implied. See the License for the specific
|
2011-04-28 16:35:58 +02:00
|
|
|
* language governing rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The contents of this file or any work derived from this file
|
2011-04-30 04:28:31 +02:00
|
|
|
* may not be distributed under any other license whatsoever
|
|
|
|
* without the express prior written permission of the original
|
2011-04-28 16:35:58 +02:00
|
|
|
* author.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The Original Code was created by James A. Starkey for IBPhoenix.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997 - 2000, 2001, 2003 James A. Starkey
|
|
|
|
* Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
2011-04-28 18:59:29 +02:00
|
|
|
* The Code was ported into Firebird Open Source RDBMS project by
|
2011-04-28 16:35:58 +02:00
|
|
|
* Vladyslav Khorsun at 2010
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CLASSES_SYNCHRONIZE_H
|
|
|
|
#define CLASSES_SYNCHRONIZE_H
|
|
|
|
|
2012-03-01 09:55:43 +01:00
|
|
|
#include "../common/classes/SyncObject.h"
|
2011-04-28 16:35:58 +02:00
|
|
|
|
2011-05-23 17:33:19 +02:00
|
|
|
#ifndef _WIN32
|
2012-02-29 08:08:01 +01:00
|
|
|
#include "fb_pthread.h"
|
2011-05-23 17:33:19 +02:00
|
|
|
#endif
|
|
|
|
|
2011-04-28 16:35:58 +02:00
|
|
|
|
|
|
|
namespace Firebird {
|
|
|
|
|
2011-04-30 04:28:31 +02:00
|
|
|
class Synchronize
|
2011-04-28 16:35:58 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Synchronize();
|
|
|
|
virtual ~Synchronize();
|
|
|
|
|
|
|
|
virtual void shutdown();
|
|
|
|
void wake();
|
|
|
|
bool sleep(int milliseconds);
|
|
|
|
void sleep();
|
|
|
|
|
|
|
|
protected:
|
2011-04-30 04:28:31 +02:00
|
|
|
bool shutdownInProgress;
|
|
|
|
bool sleeping;
|
|
|
|
volatile bool wakeup;
|
|
|
|
///SINT64 waitTime;
|
2011-04-28 16:35:58 +02:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2011-04-30 04:28:31 +02:00
|
|
|
void* evnt;
|
2011-05-23 17:33:19 +02:00
|
|
|
#else
|
2011-04-30 04:28:31 +02:00
|
|
|
pthread_cond_t condition;
|
|
|
|
pthread_mutex_t mutex;
|
2011-04-28 16:35:58 +02:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Sync;
|
|
|
|
class SyncObject;
|
|
|
|
|
|
|
|
class ThreadSync : public Synchronize
|
|
|
|
{
|
2011-04-30 13:38:00 +02:00
|
|
|
friend class SyncObject;
|
|
|
|
|
2011-04-28 16:35:58 +02:00
|
|
|
public:
|
2011-06-24 08:34:16 +02:00
|
|
|
explicit ThreadSync(const char* desc);
|
2011-04-28 16:35:58 +02:00
|
|
|
virtual ~ThreadSync();
|
|
|
|
|
|
|
|
static ThreadSync* findThread();
|
2011-04-30 04:28:31 +02:00
|
|
|
static ThreadSync* getThread(const char* desc);
|
2012-03-01 09:55:43 +01:00
|
|
|
static ThreadId getCurrentThreadId();
|
2011-04-28 16:35:58 +02:00
|
|
|
|
2011-06-24 08:34:16 +02:00
|
|
|
const char* getWhere() const;
|
2011-04-28 16:35:58 +02:00
|
|
|
|
|
|
|
static void validateLocks();
|
2011-04-30 13:38:00 +02:00
|
|
|
|
|
|
|
private:
|
2011-04-30 04:28:31 +02:00
|
|
|
void grantLock(SyncObject* lock);
|
2011-04-30 13:38:00 +02:00
|
|
|
void init(const char* description);
|
2011-05-07 21:33:46 +02:00
|
|
|
|
2011-04-30 13:38:00 +02:00
|
|
|
static void setThread(ThreadSync* thread);
|
2011-04-28 16:35:58 +02:00
|
|
|
|
2012-03-01 09:55:43 +01:00
|
|
|
ThreadId threadId;
|
2011-04-30 04:28:31 +02:00
|
|
|
ThreadSync* nextWaiting; // next thread in sleep que (see SyncObject)
|
|
|
|
ThreadSync* prevWaiting; // previous thread in sleep que (see SyncObject)
|
2011-04-30 13:38:00 +02:00
|
|
|
SyncType lockType; // requested lock type (see SyncObject)
|
2011-04-30 04:28:31 +02:00
|
|
|
volatile bool lockGranted;
|
|
|
|
Sync* lockPending;
|
|
|
|
Sync* locks;
|
|
|
|
const char* description;
|
2011-04-28 16:35:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Firebird
|
|
|
|
|
|
|
|
#endif // CLASSES_SYNCHRONIZE_H
|