mirror of https://gitee.com/bigwinds/arangodb
added SPIN/MUTEX flag
This commit is contained in:
parent
c4369e97b2
commit
f48ac96d34
|
@ -40,6 +40,18 @@
|
|||
using namespace triagens::basics;
|
||||
using namespace triagens::rest;
|
||||
|
||||
#ifdef TRI_USE_SPIN_LOCK_SCHEDULER_LIBEV
|
||||
#define SCHEDULER_INIT TRI_InitSpin
|
||||
#define SCHEDULER_DESTROY TRI_DestroySpin
|
||||
#define SCHEDULER_LOCK TRI_LockSpin
|
||||
#define SCHEDULER_UNLOCK TRI_UnlockSpin
|
||||
#else
|
||||
#define SCHEDULER_INIT TRI_InitMutex
|
||||
#define SCHEDULER_DESTROY TRI_DestroyMutex
|
||||
#define SCHEDULER_LOCK TRI_LockMutex
|
||||
#define SCHEDULER_UNLOCK TRI_UnlockMutex
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- libev
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -246,7 +258,7 @@ SchedulerLibev::SchedulerLibev (size_t concurrency, int backend)
|
|||
_backend(backend) {
|
||||
|
||||
// setup lock
|
||||
TRI_InitSpin(&_watcherLock);
|
||||
SCHEDULER_INIT(&_watcherLock);
|
||||
|
||||
// report status
|
||||
LOGGER_TRACE << "supported backends: " << ev_supported_backends();
|
||||
|
@ -322,7 +334,7 @@ SchedulerLibev::~SchedulerLibev () {
|
|||
delete[] (ev_async**)_wakers;
|
||||
|
||||
// destroy lock
|
||||
TRI_DestroySpin(&_watcherLock);
|
||||
SCHEDULER_DESTROY(&_watcherLock);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -637,16 +649,16 @@ void SchedulerLibev::rearmTimer (EventToken token, double timeout) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void* SchedulerLibev::lookupWatcher (EventToken token) {
|
||||
TRI_LockSpin(&_watcherLock);
|
||||
SCHEDULER_LOCK(&_watcherLock);
|
||||
|
||||
if (token >= _watchers.size()) {
|
||||
TRI_UnlockSpin(&_watcherLock);
|
||||
SCHEDULER_UNLOCK(&_watcherLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* watcher = _watchers[token];
|
||||
|
||||
TRI_UnlockSpin(&_watcherLock);
|
||||
SCHEDULER_UNLOCK(&_watcherLock);
|
||||
return watcher;
|
||||
}
|
||||
|
||||
|
@ -655,17 +667,17 @@ void* SchedulerLibev::lookupWatcher (EventToken token) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void* SchedulerLibev::lookupWatcher (EventToken token, EventType& type) {
|
||||
TRI_LockSpin(&_watcherLock);
|
||||
SCHEDULER_LOCK(&_watcherLock);
|
||||
|
||||
if (token >= _watchers.size()) {
|
||||
TRI_UnlockSpin(&_watcherLock);
|
||||
SCHEDULER_UNLOCK(&_watcherLock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
type = _types[token];
|
||||
void* watcher = _watchers[token];
|
||||
|
||||
TRI_UnlockSpin(&_watcherLock);
|
||||
SCHEDULER_UNLOCK(&_watcherLock);
|
||||
return watcher;
|
||||
}
|
||||
|
||||
|
@ -686,7 +698,7 @@ void* SchedulerLibev::lookupLoop (EventLoop loop) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
EventToken SchedulerLibev::registerWatcher (void* watcher, EventType type) {
|
||||
TRI_LockSpin(&_watcherLock);
|
||||
SCHEDULER_LOCK(&_watcherLock);
|
||||
|
||||
EventToken token;
|
||||
|
||||
|
@ -702,7 +714,7 @@ EventToken SchedulerLibev::registerWatcher (void* watcher, EventType type) {
|
|||
|
||||
_types[token] = type;
|
||||
|
||||
TRI_UnlockSpin(&_watcherLock);
|
||||
SCHEDULER_UNLOCK(&_watcherLock);
|
||||
return token;
|
||||
}
|
||||
|
||||
|
@ -711,12 +723,12 @@ EventToken SchedulerLibev::registerWatcher (void* watcher, EventType type) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SchedulerLibev::unregisterWatcher (EventToken token) {
|
||||
TRI_LockSpin(&_watcherLock);
|
||||
SCHEDULER_LOCK(&_watcherLock);
|
||||
|
||||
_frees.push_back(token);
|
||||
_watchers[token] = 0;
|
||||
|
||||
TRI_UnlockSpin(&_watcherLock);
|
||||
SCHEDULER_UNLOCK(&_watcherLock);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
#include "BasicsC/locks.h"
|
||||
|
||||
// #define TRI_USE_SPIN_LOCK_SCHEDULER_LIBEV 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class SchedulerLibev
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -284,7 +286,11 @@ namespace triagens {
|
|||
/// @brief watchers lock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_USE_SPIN_LOCK_SCHEDULER_LIBEV
|
||||
TRI_spin_t _watcherLock;
|
||||
#else
|
||||
TRI_mutex_t _watcherLock;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief watchers
|
||||
|
|
|
@ -35,6 +35,18 @@
|
|||
using namespace triagens::basics;
|
||||
using namespace triagens::rest;
|
||||
|
||||
#ifdef TRI_USE_SPIN_LOCK_SCHEDULER_THREAD
|
||||
#define SCHEDULER_INIT TRI_InitSpin
|
||||
#define SCHEDULER_DESTROY TRI_DestroySpin
|
||||
#define SCHEDULER_LOCK TRI_LockSpin
|
||||
#define SCHEDULER_UNLOCK TRI_UnlockSpin
|
||||
#else
|
||||
#define SCHEDULER_INIT TRI_InitMutex
|
||||
#define SCHEDULER_DESTROY TRI_DestroyMutex
|
||||
#define SCHEDULER_LOCK TRI_LockMutex
|
||||
#define SCHEDULER_UNLOCK TRI_UnlockMutex
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -58,7 +70,7 @@ SchedulerThread::SchedulerThread (Scheduler* scheduler, EventLoop loop, bool def
|
|||
hasWork(0) {
|
||||
|
||||
// init lock
|
||||
TRI_InitSpin(&queueLock);
|
||||
SCHEDULER_INIT(&queueLock);
|
||||
|
||||
// allow cancelation
|
||||
allowAsynchronousCancelation();
|
||||
|
@ -69,7 +81,7 @@ SchedulerThread::SchedulerThread (Scheduler* scheduler, EventLoop loop, bool def
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SchedulerThread::~SchedulerThread () {
|
||||
TRI_DestroySpin(&queueLock);
|
||||
SCHEDULER_DESTROY(&queueLock);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -112,7 +124,7 @@ void SchedulerThread::registerTask (Scheduler* scheduler, Task* task) {
|
|||
else {
|
||||
|
||||
// put the register request unto the queue
|
||||
TRI_LockSpin(&queueLock);
|
||||
SCHEDULER_LOCK(&queueLock);
|
||||
|
||||
Work w(SETUP, scheduler, task);
|
||||
queue.push_back(w);
|
||||
|
@ -120,7 +132,7 @@ void SchedulerThread::registerTask (Scheduler* scheduler, Task* task) {
|
|||
|
||||
scheduler->wakeupLoop(loop);
|
||||
|
||||
TRI_UnlockSpin(&queueLock);
|
||||
SCHEDULER_UNLOCK(&queueLock);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +157,7 @@ void SchedulerThread::unregisterTask (Task* task) {
|
|||
else {
|
||||
|
||||
// put the unregister request unto the queue
|
||||
TRI_LockSpin(&queueLock);
|
||||
SCHEDULER_LOCK(&queueLock);
|
||||
|
||||
Work w(CLEANUP, 0, task);
|
||||
queue.push_back(w);
|
||||
|
@ -153,7 +165,7 @@ void SchedulerThread::unregisterTask (Task* task) {
|
|||
|
||||
scheduler->wakeupLoop(loop);
|
||||
|
||||
TRI_UnlockSpin(&queueLock);
|
||||
SCHEDULER_UNLOCK(&queueLock);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +192,7 @@ void SchedulerThread::destroyTask (Task* task) {
|
|||
else {
|
||||
|
||||
// put the unregister request unto the queue
|
||||
TRI_LockSpin(&queueLock);
|
||||
SCHEDULER_LOCK(&queueLock);
|
||||
|
||||
Work w(DESTROY, 0, task);
|
||||
queue.push_back(w);
|
||||
|
@ -188,7 +200,7 @@ void SchedulerThread::destroyTask (Task* task) {
|
|||
|
||||
scheduler->wakeupLoop(loop);
|
||||
|
||||
TRI_UnlockSpin(&queueLock);
|
||||
SCHEDULER_UNLOCK(&queueLock);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,13 +251,13 @@ void SchedulerThread::run () {
|
|||
#endif
|
||||
|
||||
if (hasWork != 0) {
|
||||
TRI_LockSpin(&queueLock);
|
||||
SCHEDULER_LOCK(&queueLock);
|
||||
|
||||
while (! queue.empty()) {
|
||||
Work w = queue.front();
|
||||
queue.pop_front();
|
||||
|
||||
TRI_UnlockSpin(&queueLock);
|
||||
SCHEDULER_UNLOCK(&queueLock);
|
||||
|
||||
switch (w.work) {
|
||||
case CLEANUP:
|
||||
|
@ -262,12 +274,12 @@ void SchedulerThread::run () {
|
|||
break;
|
||||
}
|
||||
|
||||
TRI_LockSpin(&queueLock);
|
||||
SCHEDULER_LOCK(&queueLock);
|
||||
}
|
||||
|
||||
hasWork = 0;
|
||||
|
||||
TRI_UnlockSpin(&queueLock);
|
||||
SCHEDULER_UNLOCK(&queueLock);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,13 +287,13 @@ void SchedulerThread::run () {
|
|||
|
||||
stopped = 1;
|
||||
|
||||
TRI_LockSpin(&queueLock);
|
||||
SCHEDULER_LOCK(&queueLock);
|
||||
|
||||
while (! queue.empty()) {
|
||||
Work w = queue.front();
|
||||
queue.pop_front();
|
||||
|
||||
TRI_UnlockSpin(&queueLock);
|
||||
SCHEDULER_UNLOCK(&queueLock);
|
||||
|
||||
switch (w.work) {
|
||||
case CLEANUP:
|
||||
|
@ -295,10 +307,10 @@ void SchedulerThread::run () {
|
|||
break;
|
||||
}
|
||||
|
||||
TRI_LockSpin(&queueLock);
|
||||
SCHEDULER_LOCK(&queueLock);
|
||||
}
|
||||
|
||||
TRI_UnlockSpin(&queueLock);
|
||||
SCHEDULER_UNLOCK(&queueLock);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "Scheduler/Task.h"
|
||||
#include "Scheduler/TaskManager.h"
|
||||
|
||||
// #define TRI_USE_SPIN_LOCK_SCHEDULER_THREAD 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- forward declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -232,7 +234,11 @@ namespace triagens {
|
|||
/// @brief queue lock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_USE_SPIN_LOCK_SCHEDULER_THREAD
|
||||
TRI_spin_t queueLock;
|
||||
#else
|
||||
TRI_mutex_t queueLock;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief work queue
|
||||
|
|
Loading…
Reference in New Issue