#ifndef LOCKS_H #define LOCKS_H #include "firebird.h" #ifdef WIN_NT // It is relatively easy to avoid using this header. Maybe do the same stuff like // in thd.h ? This is Windows platform maintainers choice #include #else #include #endif namespace Firebird { #ifdef WIN_NT /* Process-local spinlock. Used to manage memory heaps in threaded environment. */ // Windows version of the class class Spinlock { private: CRITICAL_SECTION spinlock; public: Spinlock() { if (!InitializeCriticalSectionAndSpinCount(&spinlock, 4000)) system_call_failed::raise(); } ~Spinlock() { DeleteCriticalSection(&spinlock); } void enter() { EnterCriticalSection(&spinlock); } void leave() { LeaveCriticalSection(&spinlock); } }; #else /* Process-local spinlock. Used to manage memory heaps in threaded environment. */ // Pthreads version of the class class Spinlock { private: pthread_spinlock_t spinlock; public: Spinlock() { if (pthread_spin_init(&spinlock, false)) system_call_failed::raise(); } ~Spinlock() { if (pthread_spin_destroy(&spinlock)) system_call_failed::raise(); } void enter() { if (pthread_spin_lock(&spinlock)) system_call_failed::raise(); } void leave() { if (pthread_spin_unlock(&spinlock)) system_call_failed::raise(); } }; #endif // Spinlock in shared memory. Not implemented yet ! class SharedSpinlock { public: SharedSpinlock() { } ~SharedSpinlock() { } void enter() { } void leave() { } }; } #endif