Beispiel #1
0
void check_all_locks(void)
{
	unsigned int i;

	check_lock(&shm->reaper_lock);
	check_lock(&shm->syscalltable_lock);

	for_each_child(i)
		check_lock(&shm->children[i]->syscall.lock);
}
Beispiel #2
0
/* returns TRUE if something is awry */
bool check_all_locks(void)
{
	unsigned int i;
	bool ret = FALSE;

	check_lock(&shm->syscalltable_lock);

	for_each_child(i)
		ret |= check_lock(&shm->children[i]->syscall.lock);

	return ret;
}
Beispiel #3
0
void _spin_lock(spinlock_t *lock)
{
    check_lock(&lock->debug);
    while ( unlikely(!_raw_spin_trylock(&lock->raw)) )
        while ( likely(_raw_spin_is_locked(&lock->raw)) )
            cpu_relax();
}
Beispiel #4
0
void _write_lock_irq(rwlock_t *lock)
{
    ASSERT(local_irq_is_enabled());
    local_irq_disable();
    check_lock(&lock->debug);
    _raw_write_lock(&lock->raw);
}
Beispiel #5
0
bool
ttylock::lock()
{
	int old_mask, pid;
	bool ret = true;

	if(get_names(tty) < 0) 
		return false;

	old_mask = umask(0);
	pid = getpid();

	if (write_lock(pid_name, pid) < 0) {
		umask(old_mask);
		return false;
	}
	umask(old_mask);

	if (link(pid_name.toLatin1(), dev_name.toLatin1()) < 0) {
		if ((ret = check_lock(dev_name, getpid())) >= 0)
			goto quit;
	}
 quit:
	if(!ret)
		unlink(dev_name.toLatin1());
	unlink(pid_name.toLatin1());
	locked = ret;
	return ret;
}
Beispiel #6
0
void lock(lock_t *_lock)
{
	pid_t pid = getpid();

	while (_lock->lock != UNLOCKED) {
		if (_lock->owner == pid) {
			debugf("lol, already have lock!\n");
			show_backtrace();
			panic(EXIT_LOCKING_CATASTROPHE);
			_exit(EXIT_FAILURE);
		}

		/* This is pretty horrible. But if we call lock()
		 * from stuck_syscall_info(), and a child is hogging a lock
		 * (or worse, a dead child), we'll deadlock, because main won't
		 *  ever get back, and subsequently check_lock().
		 * So we add an extra explicit check here.
		 */
		if (pid == mainpid) {
			check_lock(_lock);
		} else {
			/* Ok, we're a child pid.
			 * if something bad happened, like main crashed,
			 * we don't want to spin forever, so just get out.
			 */
			if ((shm->exit_reason != STILL_RUNNING) &&
			    (shm->exit_reason != EXIT_REACHED_COUNT)) {
				_exit(EXIT_FAILURE);
			}
		}

		usleep(1);
	}
	__lock(_lock);
}
Beispiel #7
0
static enum ach_status
rdlock( ach_channel_t *chan, int wait, const struct timespec *abstime ) {

    ach_header_t *shm = chan->shm;
    {
        enum ach_status r = chan_lock(chan);
        if( ACH_OK != r ) return r;
    }
    enum ach_status r = ACH_BUG;

    while(ACH_BUG == r) {
        if( chan->cancel ) {  /* check operation cancelled */
            pthread_mutex_unlock( &shm->sync.mutex );
            r = ACH_CANCELED;
        } else if( !wait ) r = ACH_OK;                          /* check no wait */
        else if ( chan->seq_num != shm->last_seq ) r = ACH_OK;  /* check if got a frame */
        /* else condition wait */
        else {
            int i = abstime ?
                pthread_cond_timedwait( &shm->sync.cond,  &shm->sync.mutex, abstime ) :
                pthread_cond_wait( &shm->sync.cond,  &shm->sync.mutex );
            enum ach_status c = check_lock(i, chan, 1);
            if( ACH_OK != c ) r = c;
            /* check r and condition next iteration */
        }
    }

    return r;
}
Beispiel #8
0
unsigned long _write_lock_irqsave(rwlock_t *lock)
{
    unsigned long flags;
    local_irq_save(flags);
    check_lock(&lock->debug);
    _raw_write_lock(&lock->raw);
    return flags;
}
Beispiel #9
0
void
ttylock::unlock()
{
	locked = 0;
	if(get_names(tty) < 0) 
		return;
	if (check_lock(dev_name, 0) == 0)
		unlink(dev_name.toLatin1());
}
Beispiel #10
0
void lock_leave(lock_t *lock)
{
	if (!lock->init) return;
	check_lock();
    //bool dbg = (strcmp(lock->name, "&waterfall_hw_lock") == 0);
    bool dbg = false;
    lock->leave++;
	if (dbg) printf("LOCK t%d %s RELEASE %s\n", TaskID(), TaskName(), lock->name);
}
Beispiel #11
0
void lock_enter(lock_t *lock)
{
	if (!lock->init) return;
	check_lock();
    int token = lock->enter++;
    //bool dbg = (strcmp(lock->name, "&waterfall_hw_lock") == 0);
    bool dbg = false;
    bool waiting = false; 
    while (token > lock->leave) {
		if (dbg && !waiting) {
			printf("LOCK t%d %s WAIT %s\n", TaskID(), TaskName(), lock->name);
			waiting = true;
		}
    	NextTaskL("lock enter");
		check_lock();
    }
	if (dbg) printf("LOCK t%d %s ACQUIRE %s\n", TaskID(), TaskName(), lock->name);
}
Beispiel #12
0
/**
 * generic acl checking for different methods (basic set of methods supported)
 * returns null if no err
 */
static dav_error *check_methods(request_rec *r, const dav_resource *resource,
                                davacl_dir_cfg *conf)
{
    const dav_hooks_repository *repos = REPOS(conf);

    if (repos == NULL || resource == NULL)
	return dav_acl_privilege_error(r, "unknown", NULL);

    switch (r->method_number) {
    default:
	if (r->method_number == iM_ACL) {
	    return check_acl(r, resource, conf, repos);
	}
	else if (r->method_number == iM_HEAD) {
	    return check_get(r, resource, conf, repos);
	}
	else {
	    TRACE(r, "Unknown methdod:%d", r->method_number);
	    return NULL;
	}
	break;

    case M_PUT:
	return check_put(r, resource, conf, repos);

    case M_PROPPATCH:
	return check_proppatch(r, resource, conf, repos);

    case M_MKCOL:
	return check_mkcol(r, resource, conf, repos);

    case M_PROPFIND:
	/* done with individual properties within dav_get_props() and
	 * dav_get_allprops */
	return NULL;

    case M_DELETE:
	return check_delete(r, resource, conf, repos);

    case M_OPTIONS:
    case M_GET:
	return check_get(r, resource, conf, repos);

    case M_COPY:
	return check_copy(r, resource, conf, repos);

    case M_MOVE:
	return check_move(r, resource, conf, repos);

    case M_LOCK:
	return check_lock(r, resource, conf, repos);

    case M_UNLOCK:
	return check_unlock(r, resource, conf, repos);
    }
}
Beispiel #13
0
static void
ct_generic(dbref player, dbref i, warn_type flags)
{
    if ((flags & W_LOCK_PROBS)) {
        lock_list *ll;
        for (ll = Locks(i); ll; ll = L_NEXT(ll)) {
            check_lock(player, i, L_TYPE(ll), L_KEY(ll));
        }
    }
}
Beispiel #14
0
int main(int argc, char **argv) 
{

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  gethostname(hostname, 1023);
  printf("%s rank %d hello world\n", hostname, rank);
  check_lock(argv[1]);
  MPI_Finalize();
}
Beispiel #15
0
int _spin_is_locked(spinlock_t *lock)
{
    check_lock(&lock->debug);

    /*
     * Recursive locks may be locked by another CPU, yet we return
     * "false" here, making this function suitable only for use in
     * ASSERT()s and alike.
     */
    return lock->recurse_cpu == SPINLOCK_NO_CPU
           ? lock->tickets.head != lock->tickets.tail
           : lock->recurse_cpu == smp_processor_id();
}
Beispiel #16
0
void _spin_lock_irq(spinlock_t *lock)
{
    ASSERT(local_irq_is_enabled());
    local_irq_disable();
    check_lock(&lock->debug);
    while ( unlikely(!_raw_spin_trylock(&lock->raw)) )
    {
        local_irq_enable();
        while ( likely(_raw_spin_is_locked(&lock->raw)) )
            cpu_relax();
        local_irq_disable();
    }
}
Beispiel #17
0
/** Write lock 
 **/
extern "C" void wlock(unsigned int *lock)
{
	unsigned int timeout = MAXSPIN;
	unsigned int value;
	extern unsigned int wlock_count, wlock_spin;
	check_lock(lock,true,false);
	atomic_increment(&wlock_count);
	do {
		value = (*lock);
		atomic_increment(&wlock_spin);
		if ( timeout--==0 ) 
			throw_exception("write lock timeout");
	} while ((value&1) || !atomic_compare_and_swap(lock, value, value + 1));
}
Beispiel #18
0
unsigned long _spin_lock_irqsave(spinlock_t *lock)
{
    unsigned long flags;
    local_irq_save(flags);
    check_lock(&lock->debug);
    while ( unlikely(!_raw_spin_trylock(&lock->raw)) )
    {
        local_irq_restore(flags);
        while ( likely(_raw_spin_is_locked(&lock->raw)) )
            cpu_relax();
        local_irq_save(flags);
    }
    return flags;
}
Beispiel #19
0
void _spin_lock(spinlock_t *lock)
{
    spinlock_tickets_t tickets = SPINLOCK_TICKET_INC;
    LOCK_PROFILE_VAR;

    check_lock(&lock->debug);
    tickets.head_tail = arch_fetch_and_add(&lock->tickets.head_tail,
                                           tickets.head_tail);
    while ( tickets.tail != observe_head(&lock->tickets) )
    {
        LOCK_PROFILE_BLOCK;
        arch_lock_relax();
    }
    LOCK_PROFILE_GOT;
    preempt_disable();
    arch_lock_acquire_barrier();
}
Beispiel #20
0
int
main(int argc, char **argv)
{
	int ch, debug = 0, uucpstyle = 0;
	const char *file = NULL;
	char *endptr;
	pid_t pid = -1;
	long tmp_pid;

	while ((ch = getopt(argc, argv, "df:p:u")) != -1) {
		switch (ch) {
		case 'd':
			debug = 1;
			break;
		case 'f':
			file = optarg;
			break;
		case 'p':
			errno = 0;
			tmp_pid = strtol(optarg, &endptr, 10);
			if (*endptr != '\0' || errno ||
			    tmp_pid < 1 || (pid = tmp_pid) != tmp_pid)
				errx(1, "invalid pid specified");
			break;
		case 'u':
			uucpstyle = 1;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc != 0)
		usage();

	if (file == NULL)
		usage();

	if (pid != -1)
		return(create_lock(file, pid, uucpstyle, debug));
	else
		return(check_lock(file, uucpstyle, debug));
}
Beispiel #21
0
void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(void *), void *data)
{
    spinlock_tickets_t tickets = SPINLOCK_TICKET_INC;
    LOCK_PROFILE_VAR;

    check_lock(&lock->debug);
    tickets.head_tail = arch_fetch_and_add(&lock->tickets.head_tail,
                                           tickets.head_tail);
    while ( tickets.tail != observe_head(&lock->tickets) )
    {
        LOCK_PROFILE_BLOCK;
        if ( unlikely(cb) )
            cb(data);
        arch_lock_relax();
    }
    LOCK_PROFILE_GOT;
    preempt_disable();
    arch_lock_acquire_barrier();
}
Beispiel #22
0
void _spin_lock_recursive(spinlock_t *lock)
{
    int cpu = smp_processor_id();

    /* Don't allow overflow of recurse_cpu field. */
    BUILD_BUG_ON(NR_CPUS > 0xfffu);

    check_lock(&lock->debug);

    if ( likely(lock->recurse_cpu != cpu) )
    {
        spin_lock(lock);
        lock->recurse_cpu = cpu;
    }

    /* We support only fairly shallow recursion, else the counter overflows. */
    ASSERT(lock->recurse_cnt < 0xfu);
    lock->recurse_cnt++;
}
Beispiel #23
0
void lock(lock_t *_lock)
{
	pid_t pid = getpid();

	while (_lock->lock == LOCKED) {
		if (_lock->owner == pid) {
			debugf("lol, already have lock!\n");
			show_backtrace();
			panic(EXIT_LOCKING_CATASTROPHE);
			_exit(EXIT_FAILURE);
		}

		/* This is pretty horrible. But if we call lock()
		 * from the watchdog code, and a child is hogging a lock
		 * (or worse, a dead child), we'll never call check_lock()
		 * from the watchdog loop because we'll be stuck here.
		 */
		if (pid == watchdog_pid) {
			check_lock(_lock);
		} else {
			/* Ok, we're a child pid.
			 * if something bad happened, like main/watchdog crashed,
			 * we don't want to spin forever, so just get out.
			 */
			if ((shm->exit_reason != STILL_RUNNING) &&
			    (shm->exit_reason != EXIT_REACHED_COUNT)) {
				_exit(EXIT_FAILURE);
			}
		}

		_lock->contention++;
		usleep(1);
	}

	_lock->lock = LOCKED;
	_lock->contention = 0;
	_lock->owner = pid;
}
Beispiel #24
0
static void check_locks(THR_LOCK *lock, const char *where,
			my_bool allow_no_locks)
{
  uint old_found_errors=found_errors;
  DBUG_ENTER("check_locks");

  if (found_errors < MAX_FOUND_ERRORS)
  {
    if (check_lock(&lock->write,"write",where,1,1) |
	check_lock(&lock->write_wait,"write_wait",where,0,0) |
	check_lock(&lock->read,"read",where,0,1) |
	check_lock(&lock->read_wait,"read_wait",where,0,0))
      found_errors++;

    if (found_errors < MAX_FOUND_ERRORS)
    {
      uint count=0;
      THR_LOCK_DATA *data;
      for (data=lock->read.data ; data ; data=data->next)
      {
	if ((int) data->type == (int) TL_READ_NO_INSERT)
	  count++;
        /* Protect against infinite loop. */
        DBUG_ASSERT(count <= lock->read_no_write_count);
      }
      if (count != lock->read_no_write_count)
      {
	found_errors++;
	fprintf(stderr,
		"Warning at '%s': Locks read_no_write_count was %u when it should have been %u\n", where, lock->read_no_write_count,count);
      }      

      if (!lock->write.data)
      {
	if (!allow_no_locks && !lock->read.data &&
	    (lock->write_wait.data || lock->read_wait.data))
	{
	  found_errors++;
	  fprintf(stderr,
		  "Warning at '%s': No locks in use but locks are in wait queue\n",
		  where);
	}
	if (!lock->write_wait.data)
	{
	  if (!allow_no_locks && lock->read_wait.data)
	  {
	    found_errors++;
	    fprintf(stderr,
		    "Warning at '%s': No write locks and waiting read locks\n",
		    where);
	  }
	}
	else
	{
	  if (!allow_no_locks &&
	      (((lock->write_wait.data->type == TL_WRITE_CONCURRENT_INSERT ||
		 lock->write_wait.data->type == TL_WRITE_ALLOW_WRITE) &&
		!lock->read_no_write_count) ||
	       lock->write_wait.data->type == TL_WRITE_ALLOW_READ ||
	       (lock->write_wait.data->type == TL_WRITE_DELAYED &&
		!lock->read.data)))
	  {
	    found_errors++;
	    fprintf(stderr,
		    "Warning at '%s': Write lock %d waiting while no exclusive read locks\n",where,(int) lock->write_wait.data->type);
	  }
	}	      
      }
      else
      {						/* Have write lock */
	if (lock->write_wait.data)
	{
	  if (!allow_no_locks && 
	      lock->write.data->type == TL_WRITE_ALLOW_WRITE &&
	      lock->write_wait.data->type == TL_WRITE_ALLOW_WRITE)
	  {
	    found_errors++;
	    fprintf(stderr,
		    "Warning at '%s': Found WRITE_ALLOW_WRITE lock waiting for WRITE_ALLOW_WRITE lock\n",
		    where);
	  }
	}
	if (lock->read.data)
	{
          if (!thr_lock_owner_equal(lock->write.data->owner,
                                    lock->read.data->owner) &&
	      ((lock->write.data->type > TL_WRITE_DELAYED &&
		lock->write.data->type != TL_WRITE_ONLY) ||
	       ((lock->write.data->type == TL_WRITE_CONCURRENT_INSERT ||
		 lock->write.data->type == TL_WRITE_ALLOW_WRITE) &&
		lock->read_no_write_count)))
	  {
	    found_errors++;
	    fprintf(stderr,
		    "Warning at '%s': Found lock of type %d that is write and read locked\n",
		    where, lock->write.data->type);
	    DBUG_PRINT("warning",("At '%s': Found lock of type %d that is write and read locked\n",
		    where, lock->write.data->type));

	  }
	}
	if (lock->read_wait.data)
	{
	  if (!allow_no_locks && lock->write.data->type <= TL_WRITE_DELAYED &&
	      lock->read_wait.data->type <= TL_READ_HIGH_PRIORITY)
	  {
	    found_errors++;
	    fprintf(stderr,
		    "Warning at '%s': Found read lock of type %d waiting for write lock of type %d\n",
		    where,
		    (int) lock->read_wait.data->type,
		    (int) lock->write.data->type);
	  }
	}
      }
    }
    if (found_errors != old_found_errors)
    {
      DBUG_PRINT("error",("Found wrong lock"));
    }
  }
  DBUG_VOID_RETURN;
}
Beispiel #25
0
/** Write unlock
 **/
extern "C" void wunlock(unsigned int *lock)
{
	unsigned int value = *lock;
	check_lock(lock,true,true);
	atomic_increment(lock);
}
Beispiel #26
0
const QVector<RecordLine>& RecordList::matching_record_info() const {

    check_lock();

    return *matching_records;
}
Beispiel #27
0
const QVector<MoteHeader>& RecordList::matching_headers() const {

    check_lock();

    return *matching_header;
}
Beispiel #28
0
const QVector<RecordLine>& RecordList::record_info() const {

    check_lock();

    return *records;
}
Beispiel #29
0
const QVector<MoteHeader>& RecordList::headers() const {

    check_lock();

    return *header;
}
Beispiel #30
0
/* run the ping pong test on fd */
static void ping_pong(int fd, int num_locks)
{
	unsigned count = 0;
	int i=0, loops=0;
	unsigned char *val;
	unsigned char incr=0, last_incr=0;
	unsigned char *p = NULL;
	int ret;

	ret = ftruncate(fd, num_locks+1);
	if (ret == -1) {
		printf("ftruncate failed: %s\n", strerror(errno));
		return;
	}

	if (use_mmap) {
		p = mmap(NULL, num_locks+1, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
		if (p == MAP_FAILED) {
			printf("mmap failed: %s\n", strerror(errno));
			return;
		}
	}

	val = (unsigned char *)calloc(num_locks+1, sizeof(unsigned char));
	if (val == NULL) {
		printf("calloc failed\n");
		return;
	}

	start_timer();

	lock_range(fd, 0, 1);
	i = 0;

	while (1) {
		if (lock_range(fd, (i+1) % num_locks, 1) != 0) {
			printf("lock at %d failed! - %s\n",
			       (i+1) % num_locks, strerror(errno));
		}
		if (do_check) {
			ret = check_lock(fd, i, 1);
		}
		if (do_reads) {
			unsigned char c;
			if (use_mmap) {
				c = p[i];
			} else if (pread(fd, &c, 1, i) != 1) {
				printf("read failed at %d\n", i);
			}
			incr = c - val[i];
			val[i] = c;
		}
		if (do_writes) {
			char c = val[i] + 1;
			if (use_mmap) {
				p[i] = c;
			} else if (pwrite(fd, &c, 1, i) != 1) {
				printf("write failed at %d\n", i);
			}
		}
		if (unlock_range(fd, i, 1) != 0) {
			printf("unlock at %d failed! - %s\n",
			       i, strerror(errno));
		}
		i = (i+1) % num_locks;
		count++;
		if (loops > num_locks && incr != last_incr) {
			last_incr = incr;
			printf("data increment = %u\n", incr);
			fflush(stdout);
		}
		if (end_timer() > 1.0) {
			printf("%8u locks/sec\r", 
			       (unsigned)(2*count/end_timer()));
			fflush(stdout);
			start_timer();
			count=0;
		}
		loops++;
	}
}