// This test creates a single lock that is ordered < N resources, then
// repeatedly exercises this order k times.
static nsresult
OneLockNDeps(const int N, const int K)
{
    moz_lock_t lock = NEWLOCK("deadlockDetector.scalability.t2.master");
    moz_lock_t* locks = new moz_lock_t[N];
    if (!locks)
        NS_RUNTIMEABORT("couldn't allocate lock array");

    for (int i = 0; i < N; ++i)
        locks[i] =
            NEWLOCK("deadlockDetector.scalability.t2.dep");

    // establish orders
    {AUTOLOCK(m, lock);
        for (int i = 0; i < N; ++i)
            AUTOLOCK(s, locks[i]);
    }

    // exercise order check
    {AUTOLOCK(m, lock);
        for (int i = 0; i < K; ++i)
            for (int j = 0; j < N; ++j)
                AUTOLOCK(s, locks[i]);
    }

    for (int i = 0; i < N; ++i)
        DELETELOCK(locks[i]);
    delete[] locks;

    PASS();
}
static nsresult
OneLockNDepsUsedSeveralTimes(const size_t N, const size_t K)
{
    // Create master lock.
    moz_lock_t lock_1 = NEWLOCK("deadlockDetector.scalability.t4.master");
    for (size_t n = 0; n < N; n++) {
        // Create child lock.
        moz_lock_t lock_2 = NEWLOCK("deadlockDetector.scalability.t4.child");

        // First lock the master.
        AUTOLOCK(m, lock_1);

        // Now lock and unlock the child a few times.
        for (size_t k = 0; k < K; k++) {
            AUTOLOCK(c, lock_2);
        }

        // Destroy the child lock.
        DELETELOCK(lock_2);
    }

    // Cleanup the master lock.
    DELETELOCK(lock_1);

    PASS();
}
static nsresult
MaxDepsNsq(const int N, const int K)
{
    moz_lock_t* locks = new moz_lock_t[N];
    if (!locks)
        NS_RUNTIMEABORT("couldn't allocate lock array");

    for (int i = 0; i < N; ++i)
        locks[i] = NEWLOCK("deadlockDetector.scalability.t3");

    for (int i = 0; i < N; ++i) {
        AUTOLOCK(al1, locks[i]);
        for (int j = i+1; j < N; ++j)
            AUTOLOCK(al2, locks[j]);
    }

    for (int i = 0; i < K; ++i) {
        for (int j = 0; j < N; ++j) {
            AUTOLOCK(al1, locks[j]);
            for (int k = j+1; k < N; ++k)
                AUTOLOCK(al2, locks[k]);
        }
    }

    for (int i = 0; i < N; ++i)
        DELETELOCK(locks[i]);
    delete[] locks;

    PASS();
}
Example #4
0
void NetManager::FreeChannel(NetChannelBase* pBase)
{
	AUTOLOCK(m_mutexChannels);

	if(pBase != NULL)
	{
		pBase->m_RefCount--;
		if( pBase->m_RefCount <= 0 )
		{
			AUTOLOCK( m_destroyQueueLock );
			m_destroyQueue.push_back(pBase);
		}
	}
}
Example #5
0
void NetChannel::OnExitSending()
{
	AUTOLOCK( m_MutexSending );

	m_bHasStartSending = false;
	m_hExitSending.SetEvent();
}
Example #6
0
int32 NetManager::AddNewConnection(NetChannelBase* pBase, bool bSocketIsAccepted, bool bWait)
{
	if(!pBase)
		return -1;

	pBase->SetID(-1);
	pBase->m_bCreateByAccept = bSocketIsAccepted;

	if(bWait)
		pBase->m_hProcNewNotify.CreateEvent( false, false);

	{
		AUTOLOCK( m_mutexChannels );
		m_newSocketQueue.push_back(pBase);
		pBase->m_RefCount++;
	}

	int32 nChannelID = -1;
	if(bWait)
	{
		pBase->m_hProcNewNotify.Wait();
		nChannelID = pBase->GetID();
	}

	return nChannelID;
}
bool gyro_sensor::process_event(void)
{
	sensor_event_t event;

	if (m_sensor_hal->is_data_ready(true) == false)
		return true;

	m_sensor_hal->get_sensor_data(event.data);

	AUTOLOCK(m_client_info_mutex);

	if (get_client_cnt(GYROSCOPE_EVENT_UNPROCESSED_DATA_REPORT_ON_TIME)) {
		event.sensor_id = get_id();
		event.event_type = GYROSCOPE_EVENT_UNPROCESSED_DATA_REPORT_ON_TIME;
		push(event);
	}

	if (get_client_cnt(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME)) {
		event.sensor_id = get_id();
		event.event_type = GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME;
		raw_to_base(event.data);
		push(event);
	}

	return true;
}
bool pir_long_sensor::set_interval(unsigned long interval)
{
	AUTOLOCK(m_mutex);

	INFO("Polling interval is set to %dms", interval);

	return m_sensor_hal->set_interval(interval);
}
Example #9
0
void TaskQueueWithLevel::PushTask(DBTask* pTask, DBATaskLevel taskLevel)
{
	assert(pTask);
	assert( taskLevel < eDBATL_MAX && taskLevel >= eDBATL_0);
	AUTOLOCK(m_mutex);

	m_tasks[taskLevel].push_back(pTask->GetListNode());
}
bool temperature_sensor_hal::update_value(bool wait)
{
	int temperature_raw = 0;
	bool temperature = false;
	int read_input_cnt = 0;
	const int INPUT_MAX_BEFORE_SYN = 10;
	unsigned long long fired_time = 0;
	bool syn = false;

	struct input_event temperature_event;
	DBG("temperature event detection!");

	while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
		int len = read(m_node_handle, &temperature_event, sizeof(temperature_event));
		if (len != sizeof(temperature_event)) {
			ERR("temperature_file read fail, read_len = %d\n",len);
			return false;
		}

		++read_input_cnt;

		if (temperature_event.type == EV_REL) {
			switch (temperature_event.code) {
				case REL_HWHEEL:
					temperature_raw = (int)temperature_event.value;
					temperature = true;
					break;
				default:
					ERR("temperature_event event[type = %d, code = %d] is unknown.", temperature_event.type, temperature_event.code);
					return false;
					break;
			}
		} else if (temperature_event.type == EV_SYN) {
			syn = true;
			fired_time = sensor_hal::get_timestamp(&temperature_event.time);
		} else {
			ERR("temperature_event event[type = %d, code = %d] is unknown.", temperature_event.type, temperature_event.code);
			return false;
		}
	}

	if (syn == false) {
		ERR("EV_SYN didn't come until %d inputs had come", read_input_cnt);
		return false;
	}

	AUTOLOCK(m_value_mutex);

	if (temperature)
		m_temperature = temperature_raw;

	m_fired_time = fired_time;

	DBG("m_temperature = %d, time = %lluus", m_temperature, m_fired_time);

	return true;
}
bool humidity_sensor_hal::disable(void)
{
	AUTOLOCK(m_mutex);

	set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT);

	INFO("Humidity sensor real stopping");
	return true;
}
int humidity_sensor_hal::get_sensor_data(sensor_data_t &data)
{
	AUTOLOCK(m_value_mutex);
	data.accuracy = SENSOR_ACCURACY_GOOD;
	data.timestamp = m_fired_time ;
	data.value_count = 1;
	data.values[0] = (float) m_humidity;

	return 0;
}
bool rv_raw_sensor::process_event(void)
{
	sensor_event_t event;

	if (!m_sensor_hal->is_data_ready(true))
		return true;

	m_sensor_hal->get_sensor_data(event.data);

	AUTOLOCK(m_client_info_mutex);
	AUTOLOCK(m_mutex);

	if (get_client_cnt(RV_RAW_EVENT_RAW_DATA_REPORT_ON_TIME)) {
		event.sensor_id = get_id();
		event.event_type = RV_RAW_EVENT_RAW_DATA_REPORT_ON_TIME;
		push(event);
	}

	return true;
}
bool humidity_sensor_hal::enable(void)
{
	AUTOLOCK(m_mutex);

	set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT);
	set_interval(m_polling_interval);

	m_fired_time = 0;
	INFO("Humidity sensor real starting");
	return true;
}
Example #15
0
void NetManager::ProcPendingDestroy()
{
	AUTOLOCK(m_destroyQueueLock);

	while (!m_destroyQueue.empty())
	{
		NetChannelBase* pChannel = m_destroyQueue[0];
		SAFE_DELETE(pChannel);
		m_destroyQueue.pop_front();
	}
}
bool pir_long_sensor::process_event(void)
{
	sensor_event_t event;

	if (!m_sensor_hal->is_data_ready(true))
		return true;

	m_sensor_hal->get_sensor_data(event.data);

	AUTOLOCK(m_client_info_mutex);
	AUTOLOCK(m_mutex);

	if (get_client_cnt(PIR_LONG_EVENT_CHANGE_STATE)) {
		event.sensor_id = get_id();
		event.event_type = PIR_LONG_EVENT_CHANGE_STATE;
		raw_to_state(event.data);
		push(event);
	}

	return true;
}
Example #17
0
static void
portal_revoke_permissions (GDBusMethodInvocation *invocation,
                           GVariant *parameters,
                           const char *app_id)
{
  const char *target_app_id;
  const char *id;
  g_autofree const char **permissions = NULL;
  g_autoptr(XdgAppDbEntry) entry = NULL;
  XdpPermissionFlags perms;

  g_variant_get (parameters, "(&s&s^a&s)", &id, &target_app_id, &permissions);

  {
    AUTOLOCK(db);

    entry = xdg_app_db_lookup (db, id);
    if (entry == NULL)
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_FOUND,
                                               "No such document: %s", id);
        return;
      }

    if (!xdg_app_is_valid_name (target_app_id))
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_INVALID_ARGUMENT,
                                               "Invalid app name: %s", target_app_id);
        return;
      }

    perms = xdp_parse_permissions (permissions);

    /* Must have grant-permissions, or be itself */
    if (!xdp_entry_has_permissions (entry, app_id,
                                    XDP_PERMISSION_FLAGS_GRANT_PERMISSIONS) ||
        strcmp (app_id, target_app_id) == 0)
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_ALLOWED,
                                               "Not enough permissions");
        return;
      }

    do_set_permissions (entry, id, target_app_id,
                        ~perms & xdp_entry_get_permissions (entry, target_app_id));
  }

  /* Invalidate with lock dropped to avoid deadlock */
  xdp_fuse_invalidate_doc_app (id, target_app_id);

  g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
}
static void
AllocLockRecurseUnlockFree(int i)
{
    if (0 == i)
        return;

    moz_lock_t lock = NEWLOCK("deadlockDetector.scalability.t1");
    {
        AUTOLOCK(_, lock);
        AllocLockRecurseUnlockFree(i - 1);
    }
    DELETELOCK(lock);
}
Example #19
0
void WorldServerNormal::OnWorldDisconnect(ServerInfo* pInfo)
{
	MyLog::error("<<--Server Manager Remove War World!");

	AUTOLOCK(m_lockLoginWar);

	m_nConnectWarState = eCWS_Waiting;
	Servers.m_pWarWorld = NULL;

	SetModuleName("World");

	WorldGuildManager::Instance().OnDisconnectWarWorld();
}
Example #20
0
void NetChannel::TryStartSending()
{
	AUTOLOCK( m_MutexSending );

	if(m_queueSendingPacket.GetCount() > 0)
	{
		if(!m_bHasStartSending)
		{
			m_bHasStartSending = true;
			m_hExitSending.ResetEvent();
			AsynSend( NULL, 0);
		}
	}
}
Example #21
0
NetChannelBase* NetManager::GetChannel(int32 nSocketID)
{
	AUTOLOCK(m_mutexChannels);

	if( nSocketID < 0 || nSocketID >= m_ChannelList.GetMaxElement() )
		return NULL;

	NetChannelBase* pChannel = m_ChannelList.XGet(nSocketID);
	if(!pChannel || pChannel->m_bIsClosing)
		return NULL;

	pChannel->m_RefCount++;
	return pChannel;
}
Example #22
0
int32 NetManager::AddChannel(NetChannelBase* pBase)
{
	AUTOLOCK(m_mutexChannels);

	int32 nSocketID = -1;
	nSocketID = m_ChannelList.add( pBase );
	if( nSocketID >= 0 )
	{
		pBase->SetID( nSocketID );
		pBase->m_RefCount++;
	}

	return nSocketID;
}
Example #23
0
void Logger::_write( int lvl, int ch, int nl, const char *fmt, va_list argp )
{
    time_t now;
    char buf[80];

    // lvl 0 is most important, >0 less impo.
    if (canlog == 0 || lvl > logLevel) {
        return;
    }

    try {
        AUTOLOCK(threaded, &maccess);

        FILE *file = logfiles[channels[ch].file_id].file;
        if (file == NULL) {
            throw Error("No log file for channel %d", ch);
        }

        timeval curTime;
        gettimeofday(&curTime, NULL);
        int milli = curTime.tv_usec / 1000;
        strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime(&curTime.tv_sec));
        char currentTime[84] = "";
        sprintf(currentTime, "%s:%d", buf, milli);

        if (fprintf(file, "%s  %s  ", currentTime, LogLevel[lvl]) < 0) {
            throw Error("Writing log mesage (Logger::_write#strftime)");
        }

        // prefix defined? yes, then write it before fmt string
        if (channels[ch].prefix != "")
            if (fprintf(file, "[%s]  ", channels[ch].prefix.c_str()) < 0) {
                throw Error("Writing log mesage (Logger::_write#channels)");
            }

        // now write format string
        if (vfprintf(file, fmt, argp) < 0) {
            throw Error("Writing log mesage (Logger::_write#vfprintf)");
        }

        // and write NL afterwards
        if (nl) {
            fprintf(file, "\n");
        }

    } catch (Error &e) {
        throw e;
    }
}
Example #24
0
static void
portal_delete (GDBusMethodInvocation *invocation,
               GVariant *parameters,
               const char *app_id)
{
  const char *id;
  g_autoptr(XdgAppDbEntry) entry = NULL;
  g_autofree const char **old_apps = NULL;
  int i;

  g_variant_get (parameters, "(s)", &id);

  {
    AUTOLOCK(db);

    entry = xdg_app_db_lookup (db, id);
    if (entry == NULL)
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_FOUND,
                                             "No such document: %s", id);
        return;
      }

    if (!xdp_entry_has_permissions (entry, app_id, XDP_PERMISSION_FLAGS_DELETE))
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_ALLOWED,
                                               "Not enough permissions");
        return;
      }

    g_debug ("delete %s", id);

    xdg_app_db_set_entry (db, id, NULL);

    if (persist_entry (entry))
      xdg_app_permission_store_call_delete (permission_store, TABLE_NAME,
                                            id, NULL, NULL, NULL);
  }

  /* All i/o is done now, so drop the lock so we can invalidate the fuse caches */
  old_apps = xdg_app_db_entry_list_apps (entry);
  for (i = 0; old_apps[i] != NULL; i++)
    xdp_fuse_invalidate_doc_app (id, old_apps[i]);
  xdp_fuse_invalidate_doc_app (id, NULL);

  /* Now fuse view is up-to-date, so we can return the call */
  g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
}
Example #25
0
void WatchDog::RegWatchDog(int32 nIdx, char* sName, uint32 MaxTime /* = 5000 */)
{
	AUTOLOCK(m_lock);

	if( nIdx < 0 || nIdx >= MAX_WATCH_STATE_SIZE || sName == NULL)
		return;

	WatchState& state = m_watchStates[nIdx];
	if( state.UseFlag )
		return;

	state.Name = sName;
	state.UseFlag = true;
	state.WatchTime = TimeManager::Instance().CurTime();
	state.Step = 0;
	state.MaxTime = MaxTime;
}
bool humidity_sensor_hal::set_interval(unsigned long val)
{
	unsigned long long polling_interval_ns;

	AUTOLOCK(m_mutex);

	polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);

	if (!set_node_value(m_interval_node, polling_interval_ns)) {
		ERR("Failed to set polling node: %s\n", m_interval_node.c_str());
		return false;
	}

	INFO("Interval is changed from %dms to %dms]", m_polling_interval, val);
	m_polling_interval = val;
	return true;
}
Example #27
0
void NetManager::ProcPendingClose()
{
	std::deque<int32> vToClose;

	{
		AUTOLOCK(m_closingQueueLock);

		while (!m_closingQueue.empty())
		{
			int32 nChannelID = m_closingQueue.front();
			m_closingQueue.pop_front();
			vToClose.push_back(nChannelID);
		}
	}

	for (auto itr = vToClose.begin(); itr != vToClose.end(); ++itr)
	{
		CloseChannel(*itr);
	}
}
bool bio_hrm_phy_sensor::process_event(void)
{
	sensor_event_t event;

	if (!m_sensor_hal->is_data_ready(true))
		return true;

	m_sensor_hal->get_sensor_data(event.data);

	AUTOLOCK(m_client_info_mutex);

	if (get_client_cnt(BIO_HRM_EVENT_CHANGE_STATE)) {
		event.sensor_id = get_id();
		event.event_type = BIO_HRM_EVENT_CHANGE_STATE;
		raw_to_base(event.data);
		push(event);
	}

	return true;
}
Example #29
0
LoadTemplate* LoadBatch::GetTemplate2Load(int32 &nWaitTemplateCnt)
{
	for (auto itr = m_list.begin(); itr != m_list.end(); ++itr)
	{
		LoadInfo* pInfo = *itr;
		AUTOLOCK(m_mutex);
		if ( pInfo->CanBeLoad(nWaitTemplateCnt) )
		{
			LoadTemplate* pTemplate = pInfo->m_pTemplate;
			if(!pTemplate)
				continue;

			pTemplate->SetLoadState(eLS_Loading);
			pTemplate->m_strName = pInfo->m_strTemplate;
			return pTemplate;
		}
	}

	return NULL;
}
Example #30
0
void WorldServerNormal::OnWorldConnect(int32 nSrvID, int32 nSocketID, bool bWarGrp, SockAddr& laddr)
{
	if( bWarGrp )
	{
		AUTOLOCK(m_lockLoginWar);

		ServerInfo* pInfo = Servers.AddWarWorld( nSrvID, nSocketID, laddr);
		if( pInfo != NULL )
		{
			m_nConnectWarState = eCWS_Succeed;
			SetModuleName("SubWorld");

			WorldGuildManager::Instance().OnConnectWarWorld();
		}
	}
	else
	{
		MyLog::error("World connect to World Error !");
		return;
	}

}