Example #1
0
/// Run the interpreter.
void FLLua::run()
{
	LL_INFOS("Lua") << __LINE__ << ": *** THREAD LOOP STARTS HERE ***" << llendl;
	while(1)
	{
		if (!pLuaStack /*|| mError*/ || LLApp::isError() || LLApp::isStopped())
			break;	//Broked.

		bool locked=false;
		mAllowPause=true; //Let FLLUa::CriticalSection() sync with MAIN on first call.
		// Process Hooks
		if(mPendingHooks)
		{
			lockData();
			locked=true;
			mPendingHooks=false;
			while(!mQueuedHooks.empty()) //Allow multiple hooks per loop.
			{
				// Peek at the top of the stack
				HookRequest *hr = mQueuedHooks.front();	
				ExecuteHook(hr);
				mQueuedHooks.pop();
				delete hr; //Say no to memory leaks.
			}
			//if(mError)goto endloop;
		}
		// Process Macros/Raw Commands
		if(mPendingCommands)
		{
			if(!locked)
				lockData();
			locked=true;
			mPendingCommands=false;
			while(!mQueuedCommands.empty())
			{
				// Peek at the top of the stack
				std::string &hr = mQueuedCommands.front(); //byref. faster.
				if(FLLua::isMacro(hr))
					RunMacro(hr); // Run macro.
				else
					RunString(hr); // Run command.
				mQueuedCommands.pop(); //safe to pop now.
				//if(mError)goto endloop;
			} 
		}
		mAllowPause=true;
//endloop:
		if(locked) 
			unlockData(); //Always.
		//if(mError)break;
		yield();
		ms_sleep(10);
	}
	LL_INFOS("Lua") << __LINE__ << ": *** THREAD EXITING ***" << llendl;
}
DemodulatorInstance::~DemodulatorInstance() {
    
    std::lock_guard < std::recursive_mutex > lockData(m_thread_control_mutex);

    //now that DemodulatorInstance are managed through shared_ptr, we 
    //should enter here ONLY when it is no longer used by any piece of code, anywhere.
    //so active wait on IsTerminated(), then die.
#define TERMINATION_SPIN_WAIT_MS (20)
#define MAX_WAIT_FOR_TERMINATION_MS (3000.0)
    //this is a stupid busy plus sleep loop
    int  nbCyclesToWait = (MAX_WAIT_FOR_TERMINATION_MS / TERMINATION_SPIN_WAIT_MS) + 1;
    int currentCycle = 0;

    while (currentCycle < nbCyclesToWait) {
        
        if (isTerminated()) {
            std::cout << "Garbage collected demodulator instance '" << getLabel() << "'... " << std::endl << std::flush;

#if ENABLE_DIGITAL_LAB
            delete activeOutput;
#endif           
            delete demodulatorPreThread;
            delete demodulatorThread;
            delete audioThread;
            delete audioSinkThread;

            break;
        }
        else {
            std::this_thread::sleep_for(std::chrono::milliseconds(TERMINATION_SPIN_WAIT_MS));
        }
        currentCycle++;
    } //end while
}
void DemodulatorInstance::run() {

    std::lock_guard < std::recursive_mutex > lockData(m_thread_control_mutex);

    if (active) {
        return;
    }

    t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
    
#ifdef __APPLE__    // Already using pthreads, might as well do some custom init..
    pthread_attr_t attr;
    size_t size;

    pthread_attr_init(&attr);
    pthread_attr_setstacksize(&attr, 2048000);
    pthread_attr_getstacksize(&attr, &size);
    pthread_create(&t_PreDemod, &attr, &DemodulatorPreThread::pthread_helper, demodulatorPreThread);
    pthread_attr_destroy(&attr);

    pthread_attr_init(&attr);
    pthread_attr_setstacksize(&attr, 2048000);
    pthread_attr_getstacksize(&attr, &size);
    pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
    pthread_attr_destroy(&attr);

//    std::cout << "Initialized demodulator stack size of " << size << std::endl;

#else
    t_PreDemod = new std::thread(&DemodulatorPreThread::threadMain, demodulatorPreThread);
    t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
#endif

    active = true;
}
bool IOConfigDirectory::initWithOffset(int start, int type)
{
    IOReturn status = kIOReturnSuccess;
    const UInt32 *data;
	
    if( !OSObject::init() )
	{
        status = kIOReturnError;
	}
    
	if( status == kIOReturnSuccess )
	{
		fStart = start;
		fType = type;
    
		status = updateROMCache( start, 1 );
	}
	
	if( status == kIOReturnSuccess )
	{
		data = lockData();
		fNumEntries = (OSSwapBigToHostInt32(data[start]) & kConfigLeafDirLength) >> kConfigLeafDirLengthPhase;
		unlockData();
	
		if( fNumEntries > 256 ) // 1k request
		{
			status = kIOReturnNoMemory;
		}
	}
bool LLQueuedThread::completeRequest(handle_t handle)
{
	bool res = false;
	lockData();
	QueuedRequest* req = (QueuedRequest*)mRequestHash.find(handle);
	if (req)
	{
		llassert_always(req->getStatus() != STATUS_QUEUED);
		llassert_always(req->getStatus() != STATUS_INPROGRESS);
#if _DEBUG
// 		LL_INFOS() << llformat("LLQueuedThread::Completed req [%08d]",handle) << LL_ENDL;
#endif
		if (!(req->getFlags() & FLAG_LOCKED))
		{
			mRequestHash.erase(handle);
			req->deleteRequest();
// 			check();
 		}
 		else
 		{
			// Cause deletion immediately after FLAG_LOCKED is released.
 			req->setFlags(FLAG_AUTO_COMPLETE);
 		}
		res = true;
	}
	unlockData();
	return res;
}
void QuotaTracker::updateDatabaseSize(
    const String& originIdentifier, const String& databaseName,
    unsigned long long databaseSize)
{
    MutexLocker lockData(m_dataGuard);
    HashMap<String, SizeMap>::iterator it = m_databaseSizes.add(originIdentifier, SizeMap()).iterator;
    it->second.set(databaseName, databaseSize);
}
void QuotaTracker::updateDatabaseSize(
    const String& originIdentifier, const String& databaseName,
    unsigned long long databaseSize)
{
    MutexLocker lockData(m_dataGuard);
    HashMap<String, SizeMap>::ValueType* it = m_databaseSizes.add(originIdentifier, SizeMap()).storedValue;
    it->value.set(databaseName, databaseSize);
}
Example #8
0
void QuotaTracker::updateDatabaseSize(SecurityOrigin* origin,
                                      const String& databaseName,
                                      unsigned long long databaseSize) {
    MutexLocker lockData(m_dataGuard);
    HashMap<String, SizeMap>::ValueType* it =
        m_databaseSizes.add(origin->toRawString(), SizeMap()).storedValue;
    it->value.set(databaseName, databaseSize);
}
//virtual
// May be called from any thread
S32 LLQueuedThread::getPending()
{
	S32 res;
	lockData();
	res = mRequestQueue.size();
	unlockData();
	return res;
}
Example #10
0
int NET2_TCPAcceptOnIP(IPaddress *ip)
{
  int val = 0;

  lockData();
  val = raw_NET2_TCPAcceptOnIP(ip);
  unlockData();

  return val;
}
Example #11
0
int NET2_TCPAcceptOn(int port)
{
  int val = 0;

  lockData();
  val = raw_NET2_TCPAcceptOn(port);
  unlockData();

  return val;
}
Example #12
0
int NET2_TCPConnectToIP(IPaddress *ip)
{
  int val = 0;

  lockData();
  val = raw_NET2_TCPConnectToIP(ip);
  unlockData();

  return val;
}
Example #13
0
int NET2_UDPSend(IPaddress *ip, char *buf, int len)
{
  int val = -1;

  lockData();
  val = raw_NET2_UDPSend(ip, buf, len);
  unlockData();

  return val;
}
Example #14
0
int NET2_UDPAcceptOn(int port, int size)
{
  int val = -1;

  lockData();
  val = raw_NET2_UDPAcceptOn(port, size);
  unlockData();

  return val;
}
Example #15
0
// MAIN thread
LLQueuedThread::handle_t LLQueuedThread::generateHandle()
{
	lockData();
	while ((mNextHandle == nullHandle()) || (mRequestHash.find(mNextHandle)))
	{
		mNextHandle++;
	}
	unlockData();
	return mNextHandle++;
}
Example #16
0
int NET2_TCPSend(int socket, char *buf, int len)
{
  int val = 0;

  lockData();
  val = raw_NET2_TCPSend(socket, buf, len);
  unlockData();

  return val;
}
Example #17
0
IPaddress *NET2_TCPGetPeerAddress(int s)
{
  IPaddress *ip = NULL;

  lockData();
  ip = raw_NET2_TCPGetPeerAddress(s);
  unlockData();

  return ip;
}
// MAIN thread
void LLQueuedThread::setFlags(handle_t handle, U32 flags)
{
	lockData();
	QueuedRequest* req = (QueuedRequest*)mRequestHash.find(handle);
	if (req)
	{
		req->setFlags(flags);
	}
	unlockData();
}
void LLQueuedThread::abortRequest(handle_t handle, bool autocomplete)
{
	lockData();
	QueuedRequest* req = (QueuedRequest*)mRequestHash.find(handle);
	if (req)
	{
		req->setFlags(FLAG_ABORT | (autocomplete ? FLAG_AUTO_COMPLETE : 0));
	}
	unlockData();
}
Example #20
0
int NET2_TCPConnectTo(char *host, int port)
{
  int val = 0;

  lockData();
  val = raw_NET2_TCPConnectTo(host, port);
  unlockData();

  return val;
}
Example #21
0
UDPpacket *NET2_UDPRead(int socket)
{
  UDPpacket *val = NULL;

  lockData();
  val = raw_NET2_UDPRead(socket);
  unlockData();
  signalRead();

  return val;
}
// MAIN thread
LLQueuedThread::QueuedRequest* LLQueuedThread::getRequest(handle_t handle)
{
	if (handle == nullHandle())
	{
		return 0;
	}
	lockData();
	QueuedRequest* res = (QueuedRequest*)mRequestHash.find(handle);
	unlockData();
	return res;
}
LLQueuedThread::status_t LLQueuedThread::getRequestStatus(handle_t handle)
{
	status_t res = STATUS_EXPIRED;
	lockData();
	QueuedRequest* req = (QueuedRequest*)mRequestHash.find(handle);
	if (req)
	{
		res = req->getStatus();
	}
	unlockData();
	return res;
}
/////////////////////////////////////////////////////////////////////////////
// We have to explicitly re-define some of these methods...
SecureBinaryData & SecureBinaryData::append(SecureBinaryData & sbd2) 
{
   if(sbd2.getSize()==0) 
      return (*this);

   if(getSize()==0) 
      BinaryData::copyFrom(sbd2.getPtr(), sbd2.getSize());
   else
      BinaryData::append(sbd2.getRawRef());

   lockData();
   return (*this);
}
// MAIN thread
void LLQueuedThread::printQueueStats()
{
	lockData();
	if (!mRequestQueue.empty())
	{
		QueuedRequest *req = *mRequestQueue.begin();
		llinfos << llformat("Pending Requests:%d Current status:%d", mRequestQueue.size(), req->getStatus()) << llendl;
	}
	else
	{
		llinfos << "Queued Thread Idle" << llendl;
	}
	unlockData();
}
Example #26
0
static __inline__ int sendEvent(Uint8 code, int data1, int data2) {
	SDL_Event event;

	event.type = SDL_USEREVENT;
	event.user.code = code;
	event.user.data1 = (void *)data1;
	event.user.data2 = (void *)data2;

	SDL_assert(dataLocked);

	unlockData();
	FE_PushEvent(&event);
	lockData();

	return 0;
}
// MAIN thread
bool LLQueuedThread::addRequest(QueuedRequest* req)
{
	if (mStatus == QUITTING)
	{
		return false;
	}
	
	lockData();
	req->setStatus(STATUS_QUEUED);
	mRequestQueue.insert(req);
	mRequestHash.insert(req);
#if _DEBUG
// 	llinfos << llformat("LLQueuedThread::Added req [%08d]",handle) << llendl;
#endif
	unlockData();

	incQueue();

	return true;
}
Example #28
0
void QuotaTracker::getDatabaseSizeAndSpaceAvailableToOrigin(
    const String& originIdentifier, const String& databaseName,
    unsigned long long* databaseSize, unsigned long long* spaceAvailable)
{
    // Extra scope to unlock prior to potentially calling WebKit::Platform.
    {
        MutexLocker lockData(m_dataGuard);
        ASSERT(m_databaseSizes.contains(originIdentifier));
        HashMap<String, SizeMap>::const_iterator it = m_databaseSizes.find(originIdentifier);
        ASSERT(it->second.contains(databaseName));
        *databaseSize = it->second.get(databaseName);

        if (m_spaceAvailableToOrigins.contains(originIdentifier)) {
            *spaceAvailable = m_spaceAvailableToOrigins.get(originIdentifier);
            return;
        }
    }

    // The embedder hasn't pushed this value to us, so we pull it as needed.
    *spaceAvailable = WebKit::Platform::current()->databaseGetSpaceAvailableForOrigin(originIdentifier);
}
void LLQueuedThread::setPriority(handle_t handle, U32 priority)
{
	lockData();
	QueuedRequest* req = (QueuedRequest*)mRequestHash.find(handle);
	if (req)
	{
		if(req->getStatus() == STATUS_INPROGRESS)
		{
			// not in list
			req->setPriority(priority);
		}
		else if(req->getStatus() == STATUS_QUEUED)
		{
			// remove from list then re-insert
			llverify(mRequestQueue.erase(req) == 1);
			req->setPriority(priority);
			mRequestQueue.insert(req);
		}
	}
	unlockData();
}
bool ZmdUpdaterCore::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: catalogData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 1: identityData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 2: catalogSubData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 3: serviceData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 4: updateData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 5: patchData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 6: lockData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 7: infoData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 8: faultData((int)static_QUType_int.get(_o+1),(const QString&)static_QUType_QString.get(_o+2),(const QVariant&)static_QUType_QVariant.get(_o+3)); break;
    case 9: transactData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 10: timerSlot(); break;
    case 11: timerData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    case 12: abortData((const QValueList<QVariant>&)*((const QValueList<QVariant>*)static_QUType_ptr.get(_o+1)),(const QVariant&)static_QUType_QVariant.get(_o+2)); break;
    default:
	return QObject::qt_invoke( _id, _o );
    }
    return TRUE;
}