8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-01 15:20:39 +01:00
firebird-mirror/src/common/classes/Synchronize.h

105 lines
2.4 KiB
C
Raw Normal View History

/*
*
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
* 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
* 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
* Vladyslav Khorsun at 2010
*
* Contributor(s):
*/
#ifndef CLASSES_SYNCHRONIZE_H
#define CLASSES_SYNCHRONIZE_H
#include "../common/classes/SyncObject.h"
2013-04-13 18:31:12 +02:00
#ifndef WIN_NT
#include "fb_pthread.h"
#endif
namespace Firebird {
2011-04-30 04:28:31 +02:00
class Synchronize
{
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;
2013-04-13 18:31:12 +02:00
#ifdef WIN_NT
2011-04-30 04:28:31 +02:00
void* evnt;
#else
2011-04-30 04:28:31 +02:00
pthread_cond_t condition;
pthread_mutex_t mutex;
#endif
};
class Sync;
class SyncObject;
class ThreadSync : public Synchronize
{
2011-04-30 13:38:00 +02:00
friend class SyncObject;
public:
2011-06-24 08:34:16 +02:00
explicit ThreadSync(const char* desc);
virtual ~ThreadSync();
static ThreadSync* findThread();
2011-04-30 04:28:31 +02:00
static ThreadSync* getThread(const char* desc);
static ThreadId getCurrentThreadId();
2011-06-24 08:34:16 +02:00
const char* getWhere() const;
2011-04-30 13:38:00 +02:00
private:
2011-04-30 04:28:31 +02:00
void grantLock(SyncObject* lock);
2011-05-07 21:33:46 +02:00
2011-04-30 13:38:00 +02:00
static void setThread(ThreadSync* thread);
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;
};
} // namespace Firebird
#endif // CLASSES_SYNCHRONIZE_H