Пример #1
0
void cell_gunlocktree(struct cell *c) {

  struct cell *finger;
  TIMER_TIC

  /* First of all, try to unlock this cell. */
  if (lock_unlock(&c->glock) != 0) error("Failed to unlock cell.");

  /* Climb up the tree and unhold the parents. */
  for (finger = c->parent; finger != NULL; finger = finger->parent)
    __sync_fetch_and_sub(&finger->ghold, 1);

  TIMER_TOC(timer_locktree);
}
Пример #2
0
int knet_vrouter_route(kvrouter_t* router, kchannel_ref_t* c, const void* buffer, int size) {
    uint32_t   id    = 0;
    wire_t*    w     = 0;
    kstream_t* s     = 0;
    int        error = error_ok;
    verify(router);
    verify(c);
    verify(buffer);
    verify(size);
    lock_lock(router->lock);
    id = uuid_get_high32(knet_channel_ref_get_uuid(c));
    w = (wire_t*)hash_get(router->table, id);
    if (!w) {
        lock_unlock(router->lock);
        return error_router_wire_not_found;
    }
    verify(w->c2);
    s = knet_channel_ref_get_stream(w->c2);
    verify(s);    
    /* 发送 */
    error = knet_stream_push(s, buffer, size);
    lock_unlock(router->lock);
    return error;
}
Пример #3
0
int fseeko(FILE *stream, off_t offset, int whence)
{
  int res;
  lock_lock(&(stream->lock));
  do {
    if(unsafely_set_stream_offset(stream, offset, whence) == -1) {
      res = -1;
      break;
    }
    memset(&(stream->mb_state), 0, sizeof(mbstate_t));
    res = 0;
  } while(0);
  lock_unlock(&(stream->lock));
  return res;
}
Пример #4
0
int fsetpos(FILE *stream, const fpos_t *pos)
{
  int res;
  lock_lock(&(stream->lock));
  do {
    if(unsafely_set_stream_offset(stream, pos->offset, SEEK_SET) == -1) {
      res = -1;
      break;
    }
    stream->mb_state = pos->mb_state;
    res = 0;
  } while(0);
  lock_unlock(&(stream->lock));
  return res;
}
Пример #5
0
Файл: gq.c Проект: eligo/mul
struct mq_t *gq_pop() {
	struct mq_t *mq = NULL;
	lock_lock(mGq->mLock);
	mq = mGq->mHead;
	if (mq) {
		mGq->mHead = mq->mNext;
		if (!mGq->mHead) {
			assert(mGq->mTail == mq);
			mGq->mTail = NULL;
		}
		mq->mNext = NULL;
	}
	lock_unlock(mGq->mLock);
	return mq;
}
Пример #6
0
void CGeoIP::ThreadGeoIP(void *params)
{
    InfoGeoIPThread *pInfoThread = static_cast<InfoGeoIPThread*>(params);
    std::string host = pInfoThread->m_aIpAddress;
    IGeoIP::GeoInfo info = GetInfo(host.substr(0, host.find_first_of(":")).c_str());

    lock_wait(m_GeoIPLock);
    if (pInfoThread->m_pServerInfoReg)
    {
    	str_copy(pInfoThread->m_pServerInfoReg->m_aCountryCode, info.m_aCountryCode, sizeof(pInfoThread->m_pServerInfoReg->m_aCountryCode));
    	str_copy(pInfoThread->m_pServerInfoReg->m_aCountryName, info.m_aCountryName, sizeof(pInfoThread->m_pServerInfoReg->m_aCountryName));
    }
    *pInfoThread->m_pGeoInfo = info;
    lock_unlock(m_GeoIPLock);
}
Пример #7
0
bool CSound::IsPlaying(CSampleHandle SampleID)
{
	bool Ret = false;
	lock_wait(m_SoundLock);
	CSample *pSample = &m_aSamples[SampleID.Id()];
	for(int i = 0; i < NUM_VOICES; i++)
	{
		if(m_aVoices[i].m_pSample == pSample)
		{
			Ret = true;
		}
	}
	lock_unlock(m_SoundLock);
	return Ret;
}
Пример #8
0
size_t fread(void *ptr, size_t elem_size, size_t elem_count, FILE *stream)
{
  char *buf = (char *) ptr;
  size_t count, read_byte_count;
  lock_lock(&(stream->lock));
  if(__uportlibc_unsafely_prepare_stream_to_read(stream, -1) == EOF) return 0;
  count = elem_size * elem_count;
  read_byte_count = 0;
  while(stream->pushed_c_count > 0 && count > 0) {
    stream->pushed_c_count--;
    *buf = stream->pushed_cs[stream->pushed_c_count];
    buf++;
    count--;
    read_byte_count++;
  }
  if(stream->buf_type != _IONBF) {
    while(stream->buf_data_cur != stream->buf_data_end && count > 0) {
      *buf = *(stream->buf_data_cur);
      buf++;
      stream->buf_data_cur++;
      count--;
      read_byte_count++;
    }
    if(stream->buf_data_cur == stream->buf_data_end) {
      stream->buf_data_cur = stream->buf;
      stream->buf_data_end = stream->buf;
    }
  }
  while(count > 0) {
    size_t tmp_count = (count < SSIZE_MAX ? count : SSIZE_MAX);
    ssize_t res = read(stream->fd, buf, tmp_count);
    if(res == 0) {
      stream->flags |= FILE_FLAG_EOF;
      break;
    }
    if(res == -1) {
      stream->flags |= FILE_FLAG_ERROR;
      break;
    }
    buf += res;
    count -= res;
    read_byte_count += res;
  }
  lock_unlock(&(stream->lock));
  return read_byte_count / elem_size;
}
Пример #9
0
int fgetpos(FILE *stream, fpos_t *pos)
{
  int res;
  lock_lock(&(stream->lock));
  do {
    off_t offset = unsafely_get_stream_offset(stream);
    if(offset == -1) {
      res = -1;
      break;
    }
    pos->offset = offset;
    pos->mb_state = stream->mb_state;
    res = 0;
  } while(0);
  lock_unlock(&(stream->lock));
  return res;
}
Пример #10
0
int putw(int w, FILE *stream)
{
  union word word_union;
  size_t i;
  int res;
  word_union.word = w;
  res = 0;
  lock_lock(&(stream->lock));
  for(i = 0; i < WORD_BIT / 8; i++) {
    if(putc_unlocked(word_union.bytes[i], stream) == EOF) {
      res = EOF;
      break;
    }
  }
  lock_unlock(&(stream->lock));
  return res;
}
Пример #11
0
void FifoConsole::ListenFifoThread(void *pUser)
{
	FifoConsole *pData = (FifoConsole *)pUser;

	if(!gs_FifoLock)
	{
		dbg_msg("fifo", "FIFO not properly initialized");
		exit(2);
	}

	lock_wait(gs_FifoLock);
	if(gs_stopFifoThread)
		return;

	mkfifo(pData->m_pFifoFile, 0600);

	struct stat attribute;
	stat(pData->m_pFifoFile, &attribute);

	if(!S_ISFIFO(attribute.st_mode))
	{
		dbg_msg("fifo", "'%s' is not a FIFO, removing", pData->m_pFifoFile);
		fs_remove(pData->m_pFifoFile);
		mkfifo(pData->m_pFifoFile, 0600);
		stat(pData->m_pFifoFile, &attribute);

		if(!S_ISFIFO(attribute.st_mode))
		{
			dbg_msg("fifo", "Can't remove file, quitting");
			exit(2);
		}
	}

	lock_unlock(gs_FifoLock);

	std::ifstream f;
	char aBuf[8192];

	while (true)
	{
		f.open(pData->m_pFifoFile);
		while (f.getline(aBuf, sizeof(aBuf)))
			pData->m_pConsole->ExecuteLineFlag(aBuf, pData->m_flag, -1);
		f.close();
	}
}
Пример #12
0
int safe_warn(server *srv, const char *format, ...) {
	/* displays a warning */
	lock_lock (&srv->master->lock_log);
	
	va_list args;
	printf ("WARNING ");
	
	va_start (args, format);
	vprintf (format, args);
	va_end (args);
	
	printf ("\n");

	lock_unlock (&srv->master->lock_log);

	return 0;
}
Пример #13
0
int CSound::Update()
{
	// update volume
	int WantedVolume = g_Config.m_SndVolume;

	if(!m_pGraphics->WindowActive() && g_Config.m_SndNonactiveMute)
		WantedVolume = 0;

	if(WantedVolume != m_SoundVolume)
	{
		lock_wait(m_SoundLock);
		m_SoundVolume = WantedVolume;
		lock_unlock(m_SoundLock);
	}

	return 0;
}
Пример #14
0
void CSound::StopVoice(CVoiceHandle Voice)
{
	if(!Voice.IsValid())
		return;

	int VoiceID = Voice.Id();

	if(m_aVoices[VoiceID].m_Age != Voice.Age())
		return;

	lock_wait(m_SoundLock);
	{
		m_aVoices[VoiceID].m_pSample = 0;
		m_aVoices[VoiceID].m_Age++;
	}
	lock_unlock(m_SoundLock);
}
Пример #15
0
enum nss_status internal_function
__nss_cdb_byid(struct nss_cdb *dbp, unsigned long id,
               void *result, char *buf, size_t bufl, int *errnop) {
  enum nss_status r;
  if (bufl < 30)
    return *errnop = ERANGE, NSS_STATUS_TRYAGAIN;
  lock_lock(lock);
  if (!isopen(dbp) && !__nss_cdb_dosetent(dbp))
    *errnop = errno, r = NSS_STATUS_UNAVAIL;
  else {
    r = __nss_cdb_dobyid(dbp, id, result, buf, bufl, errnop);
    if (!dbp->keepopen)
      __nss_cdb_doendent(dbp);
  }
  lock_unlock(lock);
  return r;
}
Пример #16
0
enum nss_status internal_function
__nss_cdb_byname(struct nss_cdb *dbp, const char *name,
                 void *result, char *buf, size_t bufl, int *errnop) {
  enum nss_status r;
  if (*name == ':')
    return *errnop = ENOENT, NSS_STATUS_NOTFOUND;
  lock_lock(lock);
  if (!isopen(dbp) && !__nss_cdb_dosetent(dbp))
    *errnop = errno, r = NSS_STATUS_UNAVAIL;
  else {
    r = __nss_cdb_dobyname(dbp, name, strlen(name), result, buf, bufl, errnop);
    if (!dbp->keepopen)
      __nss_cdb_doendent(dbp);
  }
  lock_unlock(lock);
  return r;
}
Пример #17
0
int main(void)
{
	const int cpu = procnum();
	int i;

	printf("Cpu %x booted\n", cpu);

	for (i=0; i<100; ++i) {
		lock_lock(&lock);
		printf("Hello from cpu %x\n", cpu);
		lock_unlock(&lock);
	}

	if (atomic_inc(&count) == 4)
		exit(0);
	while(1);
}
Пример #18
0
void CSound::StopAll()
{
	// TODO: a nice fade out
	lock_wait(m_SoundLock);
	for(int i = 0; i < NUM_VOICES; i++)
	{
		if(m_aVoices[i].m_pSample)
		{
			if(m_aVoices[i].m_Flags & FLAG_LOOP)
				m_aVoices[i].m_pSample->m_PausedAt = m_aVoices[i].m_Tick;
			else
				m_aVoices[i].m_pSample->m_PausedAt = 0;
		}
		m_aVoices[i].m_pSample = 0;
	}
	lock_unlock(m_SoundLock);
}
Пример #19
0
/* Handle a DHCPREQ message */
static uint32_t request(unsigned int client, uint32_t ip, uint32_t siaddr) {

    if (siaddr != my_ip) {
        /* This message was intended for a different DHCP server. In a real
         * system we wouldn't send a DHCPNAK here, but would just ignore this
         * message. In this simulated setup we are the only server and we
         * *must* send a reply, so we just NAK it.
         */
        dprintf("%s: Sending DHCPNAK due to server IP mismatch\n",
            get_instance_name());
        return 0;
    }

    assert(client < routing_table_sz && "DHCPREQ from non-existent client");

    lock_lock();

    /* IP address the client gets. This will remain 0 after the logic below if
     * we're denying the client's request.
     */
    uint32_t assigned = 0;

    if (routing_table[client] == ip) {
        /* They requested their existing IP. OK, whatever. */
        dprintf("%s: Sending DHCPACK to client %u for its existing IP\n",
            get_instance_name(), client);
        assigned = ip;

    } else if (ip != my_ip && ip != 0 && ip != routing_table[0] &&
            ip != routing_table[1] && ip != routing_table[2] &&
            ip != routing_table[3]) {
        /* They requested an IP that was not ours, 0 or in the routing table
         * already. XXX: we should probably block the broadcast IP here too.
         */
        char pretty_ip[STRLEN_IP];
        ip_to_string(ip, pretty_ip);
        dprintf("%s: Sending DHCPACK to client %u of IP %s\n",
            get_instance_name(), client, pretty_ip);
        routing_table[client] = ip;
        assigned = ip;
    }

    lock_unlock();
    return assigned;
}
Пример #20
0
void CSound::Stop(int SampleID)
{
	// TODO: a nice fade out
	lock_wait(m_SoundLock);
	CSample *pSample = &m_aSamples[SampleID];
	for(int i = 0; i < NUM_VOICES; i++)
	{
		if(m_aVoices[i].m_pSample == pSample)
		{
			if(m_aVoices[i].m_Flags & FLAG_LOOP)
				m_aVoices[i].m_pSample->m_PausedAt = m_aVoices[i].m_Tick;
			else
				m_aVoices[i].m_pSample->m_PausedAt = 0;
			m_aVoices[i].m_pSample = 0;
		}
	}
	lock_unlock(m_SoundLock);
}
Пример #21
0
void thread_barrior() {
	uint32_t map = 1 << __thread_id;
	
	uint32_t full = 0;
	for(int i = 0; i < __thread_count; i++)
		full |= 1 << i;
	
	lock_lock(__barrior_lock);
	if(*__barrior == full) {	// The first one
		*__barrior = map;
	} else {
		*__barrior |= map;
	}
	lock_unlock(__barrior_lock);
	
	while(*__barrior != full && *__barrior & map)
		__asm__ __volatile__ ("nop");
}
Пример #22
0
int getw(FILE *stream)
{
  union word word_union;
  size_t i;
  int w;
  w = 0;
  lock_lock(&(stream->lock));
  for(i = 0; i < WORD_BIT / 8; i++) {
    int c = getc_unlocked(stream);
    if(c == EOF) {
      w = EOF;
      break;
    }
    word_union.bytes[i] = ((char) ((unsigned char) c));
  }
  lock_unlock(&(stream->lock));
  if(w != EOF) w = word_union.word;
  return w;
}
Пример #23
0
int CJobPool::Add(CJob *pJob, JOBFUNC pfnFunc, void *pData)
{
	mem_zero(pJob, sizeof(CJob));
	pJob->m_pfnFunc = pfnFunc;
	pJob->m_pFuncData = pData;

	lock_wait(m_Lock);

	// add job to queue
	pJob->m_pPrev = m_pLastJob;
	if(m_pLastJob)
		m_pLastJob->m_pNext = pJob;
	m_pLastJob = pJob;
	if(!m_pFirstJob)
		m_pFirstJob = pJob;

	lock_unlock(m_Lock);
	return 0;
}
Пример #24
0
Файл: main.c Проект: seL4/camkes
int run(void) {
    const char *name = get_instance_name();
    printf("%s: Started\n", name);

    printf("%s: Trying to acquire the lock...\n", name);
    lock_lock();
    printf("%s: Got it!\n", name);

    printf("%s: Let's do some long running calculation (or more accurately, waste time)...\n", name);
    for (int i = 0; i < 10000; i++)
        asm volatile ("");

    printf("%s: Releasing the lock...\n", name);
    lock_unlock();
    printf("%s: Done; let's spin.\n", name);
    while (1);

    return 0;
}
Пример #25
0
int puts(const char *str)
{
  int res;
  lock_lock(&(stdout->lock));
  do {
    res = fputs_unlocked(str, stdout);
    if(res == EOF) {
      res = EOF;
      break;
    }
    if(putchar_unlocked('\n') == EOF) {
      res = EOF;
      break;
    }
    res++;
  } while(0);
  lock_unlock(&(stdout->lock));
  return res;
}
Пример #26
0
ISound::CVoiceHandle CSound::Play(int ChannelID, int SampleID, int Flags, float x, float y)
{
	int VoiceID = -1;
	int Age = -1;
	int i;

	lock_wait(m_SoundLock);

	// search for voice
	for(i = 0; i < NUM_VOICES; i++)
	{
		int id = (m_NextVoice + i) % NUM_VOICES;
		if(!m_aVoices[id].m_pSample)
		{
			VoiceID = id;
			m_NextVoice = id+1;
			break;
		}
	}

	// voice found, use it
	if(VoiceID != -1)
	{
		m_aVoices[VoiceID].m_pSample = &m_aSamples[SampleID];
		m_aVoices[VoiceID].m_pChannel = &m_aChannels[ChannelID];
		if(Flags & FLAG_LOOP)
			m_aVoices[VoiceID].m_Tick = m_aSamples[SampleID].m_PausedAt;
		else
			m_aVoices[VoiceID].m_Tick = 0;
		m_aVoices[VoiceID].m_Vol = 255;
		m_aVoices[VoiceID].m_Flags = Flags;
		m_aVoices[VoiceID].m_X = (int)x;
		m_aVoices[VoiceID].m_Y = (int)y;
		m_aVoices[VoiceID].m_Falloff = 0.0f;
		m_aVoices[VoiceID].m_Shape = ISound::SHAPE_CIRCLE;
		m_aVoices[VoiceID].m_Circle.m_Radius = DefaultDistance;
		Age = m_aVoices[VoiceID].m_Age;
	}

	lock_unlock(m_SoundLock);
	return CreateVoiceHandle(VoiceID, Age);
}
Пример #27
0
EXPORTED int mappedfile_unlock(struct mappedfile *mf)
{
    int r;

    /* make this safe to call multiple times */
    if (!mf) return 0;
    if (mf->lock_status == MF_UNLOCKED) return 0;

    assert(mf->fd != -1);
    assert(!mf->dirty);

    r = lock_unlock(mf->fd, mf->fname);
    if (r < 0) {
	syslog(LOG_ERR, "IOERROR: lock_unlock %s: %m", mf->fname);
	return r;
    }

    mf->lock_status = MF_UNLOCKED;

    return 0;
}
Пример #28
0
void irq_handler(int irq)
{
  uint32_t ti;
  int left = atomic_add(&max_interrupts, -1);

  ti = soclib_io_get(
		     base(TIMER),
		     procnum()*TIMER_SPAN+TIMER_VALUE);

  lock_lock(&lock);
  printf("IRQ %d received at cycle %d on cpu %d %d interrupts to go\n\n", irq, ti, procnum(), left);
  lock_unlock(&lock);

  soclib_io_set(
		base(TIMER),
                procnum()*TIMER_SPAN+TIMER_RESETIRQ,
		0);

  if ( ! left )
    exit(0);
}
Пример #29
0
int CSound::Play(int ChannelID, CSampleHandle SampleID, int Flags, float x, float y)
{
	if(!SampleID.IsValid())
		return -1;

	int VoiceID = -1;
	int i;

	lock_wait(m_SoundLock);

	// search for voice
	for(i = 0; i < NUM_VOICES; i++)
	{
		int id = (m_NextVoice + i) % NUM_VOICES;
		if(!m_aVoices[id].m_pSample)
		{
			VoiceID = id;
			m_NextVoice = id+1;
			break;
		}
	}

	// voice found, use it
	if(VoiceID != -1)
	{
		m_aVoices[VoiceID].m_pSample = &m_aSamples[SampleID.Id()];
		m_aVoices[VoiceID].m_pChannel = &m_aChannels[ChannelID];
		if(Flags & FLAG_LOOP)
			m_aVoices[VoiceID].m_Tick = m_aSamples[SampleID.Id()].m_PausedAt;
		else
			m_aVoices[VoiceID].m_Tick = 0;
		m_aVoices[VoiceID].m_Vol = 255;
		m_aVoices[VoiceID].m_Flags = Flags;
		m_aVoices[VoiceID].m_X = (int)x;
		m_aVoices[VoiceID].m_Y = (int)y;
	}

	lock_unlock(m_SoundLock);
	return VoiceID;
}
Пример #30
0
/* other routines call this one when they fail */
static int abort_txn(struct dbengine *db, struct txn *tid)
{
    int r = CYRUSDB_OK;
    int rw = 0;
    struct stat sbuf;

    assert(db && tid);

    /* cleanup done while lock is held */
    if (tid->fnamenew) {
        unlink(tid->fnamenew);
        free(tid->fnamenew);
        rw = 1;
    }

    /* release lock */
    r = lock_unlock(db->fd, db->fname);
    if (r == -1) {
        syslog(LOG_ERR, "IOERROR: unlocking db %s: %m", db->fname);
        r = CYRUSDB_IOERROR;
    }

    if (rw) {
        /* return to our normally scheduled fd */
        if (!r && fstat(db->fd, &sbuf) == -1) {
            syslog(LOG_ERR, "IOERROR: fstat on %s: %m", db->fname);
            r = CYRUSDB_IOERROR;
        }
        if (!r) {
            map_free(&db->base, &db->len);
            map_refresh(db->fd, 0, &db->base, &db->len, sbuf.st_size,
                        db->fname, 0);
            db->size = sbuf.st_size;
        }
    }

    free(tid);

    return 0;
}