コード例 #1
0
	CallStacksLogLock::CallStacksLogLock()
		: mLocked(false), mOK(false)
	{
		if (!gCallStacksLogMutexp)
		{
			mOK = true;
			return;
		}
		
		const int MAX_RETRIES = 5;
		for (int attempts = 0; attempts < MAX_RETRIES; ++attempts)
		{
			apr_status_t s = apr_thread_mutex_trylock(gCallStacksLogMutexp);
			if (!APR_STATUS_IS_EBUSY(s))
			{
				mLocked = true;
				mOK = true;
				return;
			}

			ms_sleep(1);
		}

		// We're hosed, we can't get the mutex.  Blah.
		std::cerr << "CallStacksLogLock::CallStacksLogLock: failed to get mutex for log"
					<< std::endl;
	}
コード例 #2
0
bool LLMutexImpl::try_lock()
{
	apr_status_t status = apr_thread_mutex_trylock(mMutexImpl);
	if(APR_STATUS_IS_EBUSY(status))
		return false;
	APRExceptionThrower(status);
	return true;
}
コード例 #3
0
ファイル: testcond.c プロジェクト: ohmann/checkapi
static void nested_wait(abts_case *tc, void *data)
{
    toolbox_fnptr_t *fnptr = data;
    toolbox_t box;
    apr_status_t rv, retval;
    apr_thread_cond_t *cond = NULL;
    apr_thread_t *thread = NULL;
    apr_thread_mutex_t *mutex = NULL;

    rv = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_NESTED, p);
    ABTS_SUCCESS(rv);
    ABTS_PTR_NOTNULL(tc, mutex);

    rv = apr_thread_cond_create(&cond, p);
    ABTS_SUCCESS(rv);
    ABTS_PTR_NOTNULL(tc, cond);

    rv = apr_thread_mutex_lock(mutex);
    ABTS_SUCCESS(rv);

    box.tc = tc;
    box.cond = cond;
    box.mutex = mutex;
    box.func = fnptr->func;

    rv = apr_thread_create(&thread, NULL, thread_routine, &box, p);
    ABTS_SUCCESS(rv);

    rv = apr_thread_mutex_unlock(mutex);
    ABTS_SUCCESS(rv);

    /* yield the processor */
    apr_sleep(500000);

    rv = apr_thread_cond_signal(cond);
    ABTS_SUCCESS(rv);

    rv = apr_thread_join(&retval, thread);
    ABTS_SUCCESS(rv);

    rv = apr_thread_mutex_trylock(mutex);
    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EBUSY(rv));

    rv = apr_thread_mutex_trylock(mutex);
    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EBUSY(rv));
}
コード例 #4
0
// non-blocking, but does do a lock/unlock so not free
bool LLMutexBase::isLocked() const
{
	if (mLockingThread.equals_current_thread_inline())
	  return false;		// A call to lock() won't block.
	if (APR_STATUS_IS_EBUSY(apr_thread_mutex_trylock(mAPRMutexp)))
	  return true;
	apr_thread_mutex_unlock(mAPRMutexp);
	return false;
}
コード例 #5
0
ファイル: llthread.cpp プロジェクト: Nora28/imprudence
bool LLMutex::isLocked()
{
	apr_status_t status = apr_thread_mutex_trylock(mAPRMutexp);
	if (APR_STATUS_IS_EBUSY(status))
	{
		return true;
	}
	else
	{
		apr_thread_mutex_unlock(mAPRMutexp);
		return false;
	}
}
コード例 #6
0
bool LLMutexBase::tryLock()
{
	if (mLockingThread.equals_current_thread_inline())
	{ //redundant lock
		mCount++;
		return true;
	}
	bool success = !APR_STATUS_IS_EBUSY(apr_thread_mutex_trylock(mAPRMutexp));
	if (success)
	{
		mLockingThread.reset_inline();
	}
	return success;
}
コード例 #7
0
ファイル: Object.c プロジェクト: dave-nelson/yakka
bool
y_try_lock (void * self)
{
    bool acquired = false;
#if APR_HAS_THREADS
    y_Object * obj = y_OBJECT (self);
        if ( obj ) {
        apr_status_t status = apr_thread_mutex_trylock (obj->protect->mutex);
        if ( ! APR_STATUS_IS_EBUSY (status)) {
            acquired = true;
        }
    }
#endif /* APR_HAS_THREADS */
    return acquired;
}
コード例 #8
0
void LLMutexBase::lock() 
{ 
	if (mLockingThread.equals_current_thread_inline())
	{ //redundant lock
		mCount++;
		return;
	}

	if (APR_STATUS_IS_EBUSY(apr_thread_mutex_trylock(mAPRMutexp)))
	{
	  if (AIThreadID::in_main_thread_inline())
	  {
		LLFastTimer ft1(FT_WAIT_FOR_MUTEX);
		apr_thread_mutex_lock(mAPRMutexp);
	  }
	  else
	  {
		apr_thread_mutex_lock(mAPRMutexp);
	  }
	}
	
	mLockingThread.reset_inline();
}
コード例 #9
0
/* The sample content handler */
static int exipc_handler(request_rec *r)
{
    int gotlock = 0;
    int camped;
    apr_time_t startcamp;
    apr_int64_t timecamped;
    apr_status_t rs; 
    exipc_data *base;
    
    if (strcmp(r->handler, "example_ipc")) {
        return DECLINED;
    }
    
    /* 
     * The main function of the handler, aside from sending the 
     * status page to the client, is to increment the counter in 
     * the shared memory segment. This action needs to be mutexed 
     * out using the global mutex. 
     */
     
    /* 
     * First, acquire the lock. This code is a lot more involved than
     * it usually needs to be, because the process based trylock
     * routine is not implemented on unix platforms. I left it in to
     * show how it would work if trylock worked, and for situations
     * and platforms where trylock works.
     */
    for (camped = 0, timecamped = 0; camped < MAXCAMP; camped++) {
        rs = apr_global_mutex_trylock(exipc_mutex); 
        if (APR_STATUS_IS_EBUSY(rs)) {
            apr_sleep(CAMPOUT);
        } else if (APR_SUCCESS == rs) {
            gotlock = 1; 
            break; /* Get out of the loop */
        } else if (APR_STATUS_IS_ENOTIMPL(rs)) {
            /* If it's not implemented, just hang in the mutex. */
            startcamp = apr_time_now();
            rs = apr_global_mutex_lock(exipc_mutex);
            timecamped = (apr_int64_t) (apr_time_now() - startcamp);
            if (APR_SUCCESS == rs) {
                gotlock = 1;
                break; /* Out of the loop */
            } else {
                /* Some error, log and bail */
                ap_log_error(APLOG_MARK, APLOG_ERR, rs, r->server, 
                             "Child %ld failed to acquire lock", 
                             (long int)getpid());
                break; /* Out of the loop without having the lock */
            }                
        } else {
            /* Some other error, log and bail */
            ap_log_error(APLOG_MARK, APLOG_ERR, rs, r->server, 
                         "Child %ld failed to try and acquire lock", 
                         (long int)getpid());
            break; /* Out of the loop without having the lock */
            
        }
        /* 
         * The only way to get to this point is if the trylock worked
         * and returned BUSY. So, bump the time and try again
         */
        timecamped += CAMPOUT;
        ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_NOTICE, 
                     0, r->server, "Child %ld camping out on mutex for %d " 
                     "microseconds",
                     (long int) getpid(), timecamped);
    } /* Lock acquisition loop */
    
    /* Sleep for a millisecond to make it a little harder for
     * httpd children to acquire the lock. 
     */
    apr_sleep(SLEEPYTIME);
    
    r->content_type = "text/html";      

    if (!r->header_only) {
        ap_rputs(HTML_HEADER, r);
        if (gotlock) {
            /* Increment the counter */
            base = (exipc_data *)apr_shm_baseaddr_get(exipc_shm);
            base->counter++;
            /* Send a page with our pid and the new value of the counter. */
            ap_rprintf(r, "<p>Lock acquired after %ld microseoncds.</p>\n", 
                       (long int) timecamped); 
            ap_rputs("<table border=\"1\">\n", r);
            ap_rprintf(r, "<tr><td>Child pid:</td><td>%d</td></tr>\n", 
                       (int) getpid());
            ap_rprintf(r, "<tr><td>Counter:</td><td>%u</td></tr>\n", 
                       (unsigned int)base->counter);
            ap_rputs("</table>\n", r);
        } else {
            /* 
             * Send a page saying that we couldn't get the lock. Don't say
             * what the counter is, because without the lock the value could
             * race. 
             */
            ap_rprintf(r, "<p>Child %d failed to acquire lock "
                       "after camping out for %d microseconds.</p>\n", 
                       (int) getpid(), (int) timecamped);
        }
        ap_rputs(HTML_FOOTER, r); 
    } /* r->header_only */
    
    /* Release the lock */
    if (gotlock)
        rs = apr_global_mutex_unlock(exipc_mutex); 
    /* Swallowing the result because what are we going to do with it at 
     * this stage? 
     */

    return OK;
}
コード例 #10
0
ファイル: errno.c プロジェクト: LuaDist/lua-apr
void status_to_name(lua_State *L, apr_status_t status)
{
  /* Use a switch statement for fast number to string mapping: */
  switch (status) {
#   ifdef APR_ANONYMOUS
    case APR_ANONYMOUS:
      lua_pushliteral(L, "ANONYMOUS");
      return;
#   endif
#   ifdef APR_BADARG
    case APR_BADARG:
      lua_pushliteral(L, "BADARG");
      return;
#   endif
#   ifdef APR_BADCH
    case APR_BADCH:
      lua_pushliteral(L, "BADCH");
      return;
#   endif
#   ifdef APR_DETACH
    case APR_DETACH:
      lua_pushliteral(L, "DETACH");
      return;
#   endif
#   ifdef APR_EABOVEROOT
    case APR_EABOVEROOT:
      lua_pushliteral(L, "EABOVEROOT");
      return;
#   endif
#   ifdef APR_EABSOLUTE
    case APR_EABSOLUTE:
      lua_pushliteral(L, "EABSOLUTE");
      return;
#   endif
#   ifdef APR_EACCES
    case APR_EACCES:
      lua_pushliteral(L, "EACCES");
      return;
#   endif
#   ifdef APR_EAFNOSUPPORT
    case APR_EAFNOSUPPORT:
      lua_pushliteral(L, "EAFNOSUPPORT");
      return;
#   endif
#   ifdef APR_EAGAIN
    case APR_EAGAIN:
      lua_pushliteral(L, "EAGAIN");
      return;
#   endif
#   ifdef APR_EBADDATE
    case APR_EBADDATE:
      lua_pushliteral(L, "EBADDATE");
      return;
#   endif
#   ifdef APR_EBADF
    case APR_EBADF:
      lua_pushliteral(L, "EBADF");
      return;
#   endif
#   ifdef APR_EBADIP
    case APR_EBADIP:
      lua_pushliteral(L, "EBADIP");
      return;
#   endif
#   ifdef APR_EBADMASK
    case APR_EBADMASK:
      lua_pushliteral(L, "EBADMASK");
      return;
#   endif
#   ifdef APR_EBADPATH
    case APR_EBADPATH:
      lua_pushliteral(L, "EBADPATH");
      return;
#   endif
#   ifdef APR_EBUSY
    case APR_EBUSY:
      lua_pushliteral(L, "EBUSY");
      return;
#   endif
#   ifdef APR_ECONNABORTED
    case APR_ECONNABORTED:
      lua_pushliteral(L, "ECONNABORTED");
      return;
#   endif
#   ifdef APR_ECONNREFUSED
    case APR_ECONNREFUSED:
      lua_pushliteral(L, "ECONNREFUSED");
      return;
#   endif
#   ifdef APR_ECONNRESET
    case APR_ECONNRESET:
      lua_pushliteral(L, "ECONNRESET");
      return;
#   endif
#   ifdef APR_EDSOOPEN
    case APR_EDSOOPEN:
      lua_pushliteral(L, "EDSOOPEN");
      return;
#   endif
#   ifdef APR_EEXIST
    case APR_EEXIST:
      lua_pushliteral(L, "EEXIST");
      return;
#   endif
#   ifdef APR_EFTYPE
    case APR_EFTYPE:
      lua_pushliteral(L, "EFTYPE");
      return;
#   endif
#   ifdef APR_EGENERAL
    case APR_EGENERAL:
      lua_pushliteral(L, "EGENERAL");
      return;
#   endif
#   ifdef APR_EHOSTUNREACH
    case APR_EHOSTUNREACH:
      lua_pushliteral(L, "EHOSTUNREACH");
      return;
#   endif
#   ifdef APR_EINCOMPLETE
    case APR_EINCOMPLETE:
      lua_pushliteral(L, "EINCOMPLETE");
      return;
#   endif
#   ifdef APR_EINIT
    case APR_EINIT:
      lua_pushliteral(L, "EINIT");
      return;
#   endif
#   ifdef APR_EINPROGRESS
    case APR_EINPROGRESS:
      lua_pushliteral(L, "EINPROGRESS");
      return;
#   endif
#   ifdef APR_EINTR
    case APR_EINTR:
      lua_pushliteral(L, "EINTR");
      return;
#   endif
#   ifdef APR_EINVAL
    case APR_EINVAL:
      lua_pushliteral(L, "EINVAL");
      return;
#   endif
#   ifdef APR_EINVALSOCK
    case APR_EINVALSOCK:
      lua_pushliteral(L, "EINVALSOCK");
      return;
#   endif
#   ifdef APR_EMFILE
    case APR_EMFILE:
      lua_pushliteral(L, "EMFILE");
      return;
#   endif
#   ifdef APR_EMISMATCH
    case APR_EMISMATCH:
      lua_pushliteral(L, "EMISMATCH");
      return;
#   endif
#   ifdef APR_ENAMETOOLONG
    case APR_ENAMETOOLONG:
      lua_pushliteral(L, "ENAMETOOLONG");
      return;
#   endif
#   ifdef APR_ENETUNREACH
    case APR_ENETUNREACH:
      lua_pushliteral(L, "ENETUNREACH");
      return;
#   endif
#   ifdef APR_ENFILE
    case APR_ENFILE:
      lua_pushliteral(L, "ENFILE");
      return;
#   endif
#   ifdef APR_ENODIR
    case APR_ENODIR:
      lua_pushliteral(L, "ENODIR");
      return;
#   endif
#   ifdef APR_ENOENT
    case APR_ENOENT:
      lua_pushliteral(L, "ENOENT");
      return;
#   endif
#   ifdef APR_ENOLOCK
    case APR_ENOLOCK:
      lua_pushliteral(L, "ENOLOCK");
      return;
#   endif
#   ifdef APR_ENOMEM
    case APR_ENOMEM:
      lua_pushliteral(L, "ENOMEM");
      return;
#   endif
#   ifdef APR_ENOPOLL
    case APR_ENOPOLL:
      lua_pushliteral(L, "ENOPOLL");
      return;
#   endif
#   ifdef APR_ENOPOOL
    case APR_ENOPOOL:
      lua_pushliteral(L, "ENOPOOL");
      return;
#   endif
#   ifdef APR_ENOPROC
    case APR_ENOPROC:
      lua_pushliteral(L, "ENOPROC");
      return;
#   endif
#   ifdef APR_ENOSHMAVAIL
    case APR_ENOSHMAVAIL:
      lua_pushliteral(L, "ENOSHMAVAIL");
      return;
#   endif
#   ifdef APR_ENOSOCKET
    case APR_ENOSOCKET:
      lua_pushliteral(L, "ENOSOCKET");
      return;
#   endif
#   ifdef APR_ENOSPC
    case APR_ENOSPC:
      lua_pushliteral(L, "ENOSPC");
      return;
#   endif
#   ifdef APR_ENOSTAT
    case APR_ENOSTAT:
      lua_pushliteral(L, "ENOSTAT");
      return;
#   endif
#   ifdef APR_ENOTDIR
    case APR_ENOTDIR:
      lua_pushliteral(L, "ENOTDIR");
      return;
#   endif
#   ifdef APR_ENOTEMPTY
    case APR_ENOTEMPTY:
      lua_pushliteral(L, "ENOTEMPTY");
      return;
#   endif
#   ifdef APR_ENOTENOUGHENTROPY
    case APR_ENOTENOUGHENTROPY:
      lua_pushliteral(L, "ENOTENOUGHENTROPY");
      return;
#   endif
#   ifdef APR_ENOTHDKEY
    case APR_ENOTHDKEY:
      lua_pushliteral(L, "ENOTHDKEY");
      return;
#   endif
#   ifdef APR_ENOTHREAD
    case APR_ENOTHREAD:
      lua_pushliteral(L, "ENOTHREAD");
      return;
#   endif
#   ifdef APR_ENOTIME
    case APR_ENOTIME:
      lua_pushliteral(L, "ENOTIME");
      return;
#   endif
#   ifdef APR_ENOTIMPL
    case APR_ENOTIMPL:
      lua_pushliteral(L, "ENOTIMPL");
      return;
#   endif
#   ifdef APR_ENOTSOCK
    case APR_ENOTSOCK:
      lua_pushliteral(L, "ENOTSOCK");
      return;
#   endif
#   ifdef APR_EOF
    case APR_EOF:
      lua_pushliteral(L, "EOF");
      return;
#   endif
#   ifdef APR_EPATHWILD
    case APR_EPATHWILD:
      lua_pushliteral(L, "EPATHWILD");
      return;
#   endif
#   ifdef APR_EPIPE
    case APR_EPIPE:
      lua_pushliteral(L, "EPIPE");
      return;
#   endif
#   ifdef APR_EPROC_UNKNOWN
    case APR_EPROC_UNKNOWN:
      lua_pushliteral(L, "EPROC_UNKNOWN");
      return;
#   endif
#   ifdef APR_ERELATIVE
    case APR_ERELATIVE:
      lua_pushliteral(L, "ERELATIVE");
      return;
#   endif
#   ifdef APR_ESPIPE
    case APR_ESPIPE:
      lua_pushliteral(L, "ESPIPE");
      return;
#   endif
#   ifdef APR_ESYMNOTFOUND
    case APR_ESYMNOTFOUND:
      lua_pushliteral(L, "ESYMNOTFOUND");
      return;
#   endif
#   ifdef APR_ETIMEDOUT
    case APR_ETIMEDOUT:
      lua_pushliteral(L, "ETIMEDOUT");
      return;
#   endif
#   ifdef APR_EXDEV
    case APR_EXDEV:
      lua_pushliteral(L, "EXDEV");
      return;
#   endif
#   ifdef APR_FILEBASED
    case APR_FILEBASED:
      lua_pushliteral(L, "FILEBASED");
      return;
#   endif
#   ifdef APR_INCHILD
    case APR_INCHILD:
      lua_pushliteral(L, "INCHILD");
      return;
#   endif
#   ifdef APR_INCOMPLETE
    case APR_INCOMPLETE:
      lua_pushliteral(L, "INCOMPLETE");
      return;
#   endif
#   ifdef APR_INPARENT
    case APR_INPARENT:
      lua_pushliteral(L, "INPARENT");
      return;
#   endif
#   ifdef APR_KEYBASED
    case APR_KEYBASED:
      lua_pushliteral(L, "KEYBASED");
      return;
#   endif
#   ifdef APR_NOTDETACH
    case APR_NOTDETACH:
      lua_pushliteral(L, "NOTDETACH");
      return;
#   endif
#   ifdef APR_NOTFOUND
    case APR_NOTFOUND:
      lua_pushliteral(L, "NOTFOUND");
      return;
#   endif
#   ifdef APR_SUCCESS
    case APR_SUCCESS:
      lua_pushliteral(L, "SUCCESS");
      return;
#   endif
#   ifdef APR_TIMEUP
    case APR_TIMEUP:
      lua_pushliteral(L, "TIMEUP");
      return;
#   endif
  }

  /* If the switch statement fails we fall back to the following monstrosity :-) */
  if (0) ;
# ifdef APR_STATUS_IS_ANONYMOUS
  else if (APR_STATUS_IS_ANONYMOUS(status)) {
    lua_pushliteral(L, "ANONYMOUS");
    return;
  }
# endif
# ifdef APR_STATUS_IS_BADARG
  else if (APR_STATUS_IS_BADARG(status)) {
    lua_pushliteral(L, "BADARG");
    return;
  }
# endif
# ifdef APR_STATUS_IS_BADCH
  else if (APR_STATUS_IS_BADCH(status)) {
    lua_pushliteral(L, "BADCH");
    return;
  }
# endif
# ifdef APR_STATUS_IS_DETACH
  else if (APR_STATUS_IS_DETACH(status)) {
    lua_pushliteral(L, "DETACH");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EABOVEROOT
  else if (APR_STATUS_IS_EABOVEROOT(status)) {
    lua_pushliteral(L, "EABOVEROOT");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EABSOLUTE
  else if (APR_STATUS_IS_EABSOLUTE(status)) {
    lua_pushliteral(L, "EABSOLUTE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EACCES
  else if (APR_STATUS_IS_EACCES(status)) {
    lua_pushliteral(L, "EACCES");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EAFNOSUPPORT
  else if (APR_STATUS_IS_EAFNOSUPPORT(status)) {
    lua_pushliteral(L, "EAFNOSUPPORT");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EAGAIN
  else if (APR_STATUS_IS_EAGAIN(status)) {
    lua_pushliteral(L, "EAGAIN");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EBADDATE
  else if (APR_STATUS_IS_EBADDATE(status)) {
    lua_pushliteral(L, "EBADDATE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EBADF
  else if (APR_STATUS_IS_EBADF(status)) {
    lua_pushliteral(L, "EBADF");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EBADIP
  else if (APR_STATUS_IS_EBADIP(status)) {
    lua_pushliteral(L, "EBADIP");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EBADMASK
  else if (APR_STATUS_IS_EBADMASK(status)) {
    lua_pushliteral(L, "EBADMASK");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EBADPATH
  else if (APR_STATUS_IS_EBADPATH(status)) {
    lua_pushliteral(L, "EBADPATH");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EBUSY
  else if (APR_STATUS_IS_EBUSY(status)) {
    lua_pushliteral(L, "EBUSY");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ECONNABORTED
  else if (APR_STATUS_IS_ECONNABORTED(status)) {
    lua_pushliteral(L, "ECONNABORTED");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ECONNREFUSED
  else if (APR_STATUS_IS_ECONNREFUSED(status)) {
    lua_pushliteral(L, "ECONNREFUSED");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ECONNRESET
  else if (APR_STATUS_IS_ECONNRESET(status)) {
    lua_pushliteral(L, "ECONNRESET");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EDSOOPEN
  else if (APR_STATUS_IS_EDSOOPEN(status)) {
    lua_pushliteral(L, "EDSOOPEN");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EEXIST
  else if (APR_STATUS_IS_EEXIST(status)) {
    lua_pushliteral(L, "EEXIST");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EFTYPE
  else if (APR_STATUS_IS_EFTYPE(status)) {
    lua_pushliteral(L, "EFTYPE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EGENERAL
  else if (APR_STATUS_IS_EGENERAL(status)) {
    lua_pushliteral(L, "EGENERAL");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EHOSTUNREACH
  else if (APR_STATUS_IS_EHOSTUNREACH(status)) {
    lua_pushliteral(L, "EHOSTUNREACH");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EINCOMPLETE
  else if (APR_STATUS_IS_EINCOMPLETE(status)) {
    lua_pushliteral(L, "EINCOMPLETE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EINIT
  else if (APR_STATUS_IS_EINIT(status)) {
    lua_pushliteral(L, "EINIT");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EINPROGRESS
  else if (APR_STATUS_IS_EINPROGRESS(status)) {
    lua_pushliteral(L, "EINPROGRESS");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EINTR
  else if (APR_STATUS_IS_EINTR(status)) {
    lua_pushliteral(L, "EINTR");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EINVAL
  else if (APR_STATUS_IS_EINVAL(status)) {
    lua_pushliteral(L, "EINVAL");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EINVALSOCK
  else if (APR_STATUS_IS_EINVALSOCK(status)) {
    lua_pushliteral(L, "EINVALSOCK");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EMFILE
  else if (APR_STATUS_IS_EMFILE(status)) {
    lua_pushliteral(L, "EMFILE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EMISMATCH
  else if (APR_STATUS_IS_EMISMATCH(status)) {
    lua_pushliteral(L, "EMISMATCH");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENAMETOOLONG
  else if (APR_STATUS_IS_ENAMETOOLONG(status)) {
    lua_pushliteral(L, "ENAMETOOLONG");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENETUNREACH
  else if (APR_STATUS_IS_ENETUNREACH(status)) {
    lua_pushliteral(L, "ENETUNREACH");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENFILE
  else if (APR_STATUS_IS_ENFILE(status)) {
    lua_pushliteral(L, "ENFILE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENODIR
  else if (APR_STATUS_IS_ENODIR(status)) {
    lua_pushliteral(L, "ENODIR");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOENT
  else if (APR_STATUS_IS_ENOENT(status)) {
    lua_pushliteral(L, "ENOENT");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOLOCK
  else if (APR_STATUS_IS_ENOLOCK(status)) {
    lua_pushliteral(L, "ENOLOCK");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOMEM
  else if (APR_STATUS_IS_ENOMEM(status)) {
    lua_pushliteral(L, "ENOMEM");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOPOLL
  else if (APR_STATUS_IS_ENOPOLL(status)) {
    lua_pushliteral(L, "ENOPOLL");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOPOOL
  else if (APR_STATUS_IS_ENOPOOL(status)) {
    lua_pushliteral(L, "ENOPOOL");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOPROC
  else if (APR_STATUS_IS_ENOPROC(status)) {
    lua_pushliteral(L, "ENOPROC");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOSHMAVAIL
  else if (APR_STATUS_IS_ENOSHMAVAIL(status)) {
    lua_pushliteral(L, "ENOSHMAVAIL");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOSOCKET
  else if (APR_STATUS_IS_ENOSOCKET(status)) {
    lua_pushliteral(L, "ENOSOCKET");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOSPC
  else if (APR_STATUS_IS_ENOSPC(status)) {
    lua_pushliteral(L, "ENOSPC");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOSTAT
  else if (APR_STATUS_IS_ENOSTAT(status)) {
    lua_pushliteral(L, "ENOSTAT");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTDIR
  else if (APR_STATUS_IS_ENOTDIR(status)) {
    lua_pushliteral(L, "ENOTDIR");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTEMPTY
  else if (APR_STATUS_IS_ENOTEMPTY(status)) {
    lua_pushliteral(L, "ENOTEMPTY");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTENOUGHENTROPY
  else if (APR_STATUS_IS_ENOTENOUGHENTROPY(status)) {
    lua_pushliteral(L, "ENOTENOUGHENTROPY");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTHDKEY
  else if (APR_STATUS_IS_ENOTHDKEY(status)) {
    lua_pushliteral(L, "ENOTHDKEY");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTHREAD
  else if (APR_STATUS_IS_ENOTHREAD(status)) {
    lua_pushliteral(L, "ENOTHREAD");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTIME
  else if (APR_STATUS_IS_ENOTIME(status)) {
    lua_pushliteral(L, "ENOTIME");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTIMPL
  else if (APR_STATUS_IS_ENOTIMPL(status)) {
    lua_pushliteral(L, "ENOTIMPL");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ENOTSOCK
  else if (APR_STATUS_IS_ENOTSOCK(status)) {
    lua_pushliteral(L, "ENOTSOCK");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EOF
  else if (APR_STATUS_IS_EOF(status)) {
    lua_pushliteral(L, "EOF");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EPATHWILD
  else if (APR_STATUS_IS_EPATHWILD(status)) {
    lua_pushliteral(L, "EPATHWILD");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EPIPE
  else if (APR_STATUS_IS_EPIPE(status)) {
    lua_pushliteral(L, "EPIPE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EPROC_UNKNOWN
  else if (APR_STATUS_IS_EPROC_UNKNOWN(status)) {
    lua_pushliteral(L, "EPROC_UNKNOWN");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ERELATIVE
  else if (APR_STATUS_IS_ERELATIVE(status)) {
    lua_pushliteral(L, "ERELATIVE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ESPIPE
  else if (APR_STATUS_IS_ESPIPE(status)) {
    lua_pushliteral(L, "ESPIPE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ESYMNOTFOUND
  else if (APR_STATUS_IS_ESYMNOTFOUND(status)) {
    lua_pushliteral(L, "ESYMNOTFOUND");
    return;
  }
# endif
# ifdef APR_STATUS_IS_ETIMEDOUT
  else if (APR_STATUS_IS_ETIMEDOUT(status)) {
    lua_pushliteral(L, "ETIMEDOUT");
    return;
  }
# endif
# ifdef APR_STATUS_IS_EXDEV
  else if (APR_STATUS_IS_EXDEV(status)) {
    lua_pushliteral(L, "EXDEV");
    return;
  }
# endif
# ifdef APR_STATUS_IS_FILEBASED
  else if (APR_STATUS_IS_FILEBASED(status)) {
    lua_pushliteral(L, "FILEBASED");
    return;
  }
# endif
# ifdef APR_STATUS_IS_INCHILD
  else if (APR_STATUS_IS_INCHILD(status)) {
    lua_pushliteral(L, "INCHILD");
    return;
  }
# endif
# ifdef APR_STATUS_IS_INCOMPLETE
  else if (APR_STATUS_IS_INCOMPLETE(status)) {
    lua_pushliteral(L, "INCOMPLETE");
    return;
  }
# endif
# ifdef APR_STATUS_IS_INPARENT
  else if (APR_STATUS_IS_INPARENT(status)) {
    lua_pushliteral(L, "INPARENT");
    return;
  }
# endif
# ifdef APR_STATUS_IS_KEYBASED
  else if (APR_STATUS_IS_KEYBASED(status)) {
    lua_pushliteral(L, "KEYBASED");
    return;
  }
# endif
# ifdef APR_STATUS_IS_NOTDETACH
  else if (APR_STATUS_IS_NOTDETACH(status)) {
    lua_pushliteral(L, "NOTDETACH");
    return;
  }
# endif
# ifdef APR_STATUS_IS_NOTFOUND
  else if (APR_STATUS_IS_NOTFOUND(status)) {
    lua_pushliteral(L, "NOTFOUND");
    return;
  }
# endif
# ifdef APR_STATUS_IS_TIMEUP
  else if (APR_STATUS_IS_TIMEUP(status)) {
    lua_pushliteral(L, "TIMEUP");
    return;
  }
# endif

  lua_pushinteger(L, status);
}
コード例 #11
0
ファイル: _apachemodule.c プロジェクト: AlfiyaZi/mod_python
static PyObject *_global_trylock(PyObject *self, PyObject *args)
{

    PyObject *server;
    PyObject *key;
    server_rec *s;
    py_global_config *glb;
    int index = -1;
    apr_status_t rv;

    if (! PyArg_ParseTuple(args, "OO|i", &server, &key, &index))
        return NULL;

    if (!  MpServer_Check(server)) {
        PyErr_SetString(PyExc_TypeError,
                        "First argument must be a server object");
        return NULL;
    }

    s = ((serverobject *)server)->server;

    apr_pool_userdata_get((void **)&glb, MP_CONFIG_KEY,
                          s->process->pool);

    if ((index >= (glb->nlocks)) || (index < -1)) {
        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                     "Index %d is out of range for number of global mutex locks", index);
        PyErr_SetString(PyExc_ValueError,
                        "Lock index is out of range for number of global mutex locks");
        return NULL;
    }

    if (index == -1) {

        int hash = PyObject_Hash(key);
        if (hash == -1) {
            return NULL;
        }
        else {
            hash = abs(hash);
        }

        /* note that this will never result in 0,
         * which is reserved for things like dbm
         * locking (see Session.py)
         */

        index = (hash % (glb->nlocks-1)+1);
    }

    /*
     * ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
     *           "_global_trylock at index %d from pid %d", index, getpid());
     */
    Py_BEGIN_ALLOW_THREADS
    rv = apr_global_mutex_trylock(glb->g_locks[index]);
    Py_END_ALLOW_THREADS

    if (rv == APR_SUCCESS) {
        /*
         * ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
         *         "_global_trylock DONE at index %d from pid %d", index, getpid());
         */
        Py_INCREF(Py_True);
        return Py_True;
    }
    else if(APR_STATUS_IS_EBUSY(rv)) {
        /*
         * ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
         *         "_global_trylock BUSY at index %d from pid %d", index, getpid());
         */
        Py_INCREF(Py_False);
        return Py_False;
    }
    else {
        ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
                     "Failed to acquire global mutex lock at index %d", index);
        PyErr_SetString(PyExc_ValueError,
                        "Failed to acquire global mutex lock");
        return NULL;
    }
}