コード例 #1
0
ファイル: threads_wrapper.c プロジェクト: ebichu/dd-wrt
int threads_wrapper_init()
{

	create_mutex(&crit_sec_create_mutex);
	create_mutex(&crit_sec_create_sem);

	return 1;
}
コード例 #2
0
ファイル: mutexes.c プロジェクト: amintimany/verifast
int main() //@ : main
    //@ requires true;
    //@ ensures true;
{
    struct counter *counter = malloc(sizeof(struct counter));
    if (counter == 0) abort();
    counter->count = 0;
    //@ close counter(counter)();
    //@ close create_mutex_ghost_arg(counter(counter));
    struct mutex *mutex = create_mutex();
    counter->mutex = mutex;
    
    count_pulses_async(counter, 1);
    count_pulses_async(counter, 2);
    
    while (true)
        //@ invariant [1/3]mutex(mutex, counter(counter));
    {
        sleep(1000);
        mutex_acquire(mutex);
        //@ open counter(counter)();
        print_int(counter->count);
        //@ close counter(counter)();
        mutex_release(mutex);
    }
}
コード例 #3
0
ファイル: tcp.c プロジェクト: ebichu/dd-wrt
static CONNECT_THREAD_DATA *create_connect_data(void *p_data)
{
	CONNECT_THREAD_DATA	*p_thread_data=NULL;


	p_thread_data=safe_malloc(sizeof(CONNECT_THREAD_DATA));


	if (!(p_thread_data)) {

		DBG_PRINTF((LOG_CRIT,"C:" MODULE_TAG "failed allocating connect thread data in create_connect_data...\n"));

		return NULL;
	}
	else {

		memset(p_thread_data,0,sizeof(CONNECT_THREAD_DATA));
		p_thread_data->p_self=p_data;
		p_thread_data->rc=RC_IP_CONNECT_FAILED;

		create_mutex(&p_thread_data->t_data_mutex);
		create_semaphore(&p_thread_data->t_data_sem);

		return p_thread_data;
	}
}
コード例 #4
0
ファイル: vpx_mem_tracker.c プロジェクト: gotomypc/libvpx
/*
    vpx_memory_tracker_init(int padding_size, int pad_value)
      padding_size - the size of the padding before and after each mem addr.
                     Values > 0 indicate that integrity checks can be performed
                     by inspecting these areas.
      pad_value - the initial value within the padding area before and after
                  each mem addr.

    Initializes global memory tracker structure
    Allocates the head of the list
*/
int vpx_memory_tracker_init(int padding_size, int pad_value)
{
    if (!g_b_mem_tracker_inited)
    {
        if (memtrack.head = (struct mem_block *)MEM_TRACK_MALLOC(sizeof(struct mem_block)))
        {
            int ret;

            MEM_TRACK_MEMSET(memtrack.head, 0, sizeof(struct mem_block));

            memtrack.tail = memtrack.head;

            memtrack.current_allocated = 0;
            memtrack.max_allocated     = 0;

            memtrack.padding_size = padding_size;
            memtrack.pad_value    = pad_value;

#if defined(LINUX) || defined(__uClinux__)
            ret = pthread_mutex_init(&memtrack.mutex,
                                     NULL);            /*mutex attributes (NULL=default)*/
#elif defined(WIN32) || defined(_WIN32_WCE)
            memtrack.mutex = create_mutex(NULL,   /*security attributes*/
                                          FALSE,  /*we don't want initial ownership*/
                                          NULL);  /*mutex name*/
            ret = !memtrack.mutex;
#elif defined(VXWORKS)
            memtrack.mutex = sem_bcreate(SEM_Q_FIFO, /*SEM_Q_FIFO non-priority based mutex*/
                                         SEM_FULL);  /*SEM_FULL initial state is unlocked*/
            ret = !memtrack.mutex;
#elif defined(NDS_NITRO)
            os_init_mutex(&memtrack.mutex);
            ret = 0;
#elif defined(NO_MUTEX)
            ret = 0;
#endif

            if (ret)
            {
                memtrack_log("vpx_memory_tracker_init: Error creating mutex!\n");

                MEM_TRACK_FREE(memtrack.head);
                memtrack.head = NULL;
            }
            else
            {
                memtrack_log("Memory Tracker init'd, v."vpx_mem_tracker_version" pad_size:%d pad_val:0x%x %d\n"
                             , padding_size
                             , pad_value
                             , pad_value);
                g_b_mem_tracker_inited = 1;
            }
        }
    }

    return g_b_mem_tracker_inited;
}
コード例 #5
0
ファイル: char.c プロジェクト: imgits/seaos-kernel
void init_char_devs()
{
	/* These devices are all built into the kernel. We must initialize them now */
	set_chardevice(0, null_rw, 0, 0);
	set_chardevice(1, zero_rw, 0, 0);
	set_chardevice(3, ttyx_rw, ttyx_ioctl, ttyx_select);
	set_chardevice(4, tty_rw, tty_ioctl, tty_select);
	set_chardevice(5, serial_rw, 0, 0);
	create_mutex(&cd_search_lock);
}
コード例 #6
0
ファイル: work_queue.c プロジェクト: jonathanturner/minnow
struct Work_Queue *create_work_queue() {
    struct Work_Queue *retval = (struct Work_Queue*)malloc(sizeof(struct Work_Queue));

    struct Actor *guard = create_actor();
    retval->head = guard;
    retval->tail = guard;

    retval->mutex_lock = create_mutex();

    return retval;
}
コード例 #7
0
ファイル: ipc_mutex.c プロジェクト: tinselcity/experiments
//: ----------------------------------------------------------------------------
//: Main...
//: ----------------------------------------------------------------------------
int main(void)
{

        pthread_mutex_t *a_mutex = NULL;
        int l_status = 0;
        int i;


#ifdef WRITER
        printf(": Creating Mutex.\n");
        l_status = create_mutex(&a_mutex);
        if(l_status != 0) {

                printf("Error performing create_mutex.\n");
                return -1;

        }
#else
        printf(": Opening Mutex.\n");
        l_status = open_mutex(&a_mutex);
        if(l_status != 0) {

                printf("Error performing open_mutex.\n");
                return -1;

        }
#endif


        for(i = 0; i < RUN_FOR_ITERATIIONS; ++i) {

#ifdef WRITER
                printf(": Mutex[%3d] -Unlock\n", i);
                pthread_mutex_unlock(a_mutex);
                sleep(2);
#else
                printf(": Mutex[%3d] -Try Lock.\n", i);
                pthread_mutex_lock(a_mutex);
                printf(": Mutex[%3d] -LOCKED\n", i);
#endif


        }

        // TODO Cleanup...

        return 0;

}
コード例 #8
0
PyMODINIT_FUNC
PyInit__simpleaudio(void)
{
    PyObject *m;

    m = PyModule_Create(&_simpleaudio_module);
    if (m == NULL)
        return NULL;

    sa_python_error = PyErr_NewException("_simpleaudio.SimpleaudioError", NULL, NULL);
    Py_INCREF(sa_python_error);
    PyModule_AddObject(m, "SimpleaudioError", sa_python_error);

    /* initialize the list head mutex */
    play_list_head.mutex = create_mutex();

    dbg1("init'd list head at %p\n", &play_list_head);

    return m;
}
コード例 #9
0
ファイル: tblock.c プロジェクト: amintimany/verifast
struct tlock * mylock_create() 
    //@ requires create_tlock_ghost_arg(?p) &*& p();
    //@ ensures tlock(result, p);
{
    struct tlock *result = malloc(sizeof(struct tlock));
    if (result == 0) {
        abort();
    }
    result->owner = 0;
    result->next = 0;
    //@ create_box boxId = tlock_box(result, 0, 0, false, nil, p); 
    //@ close tlock_ctor(result, boxId, p)();
    //@ result->boxId = boxId;
    //@ close create_mutex_ghost_arg(tlock_ctor(result, boxId, p));
    struct mutex* l = create_mutex();
    result->mutex = l;
    return result;
    //@ close tlock(result, p);
    //@ open create_tlock_ghost_arg(p);
}
コード例 #10
0
ファイル: output.c プロジェクト: mmaruska/gnu-make
/* Set up the sync handle.  Disables output_sync on error.  */
static int
sync_init ()
{
  int combined_output = 0;

#ifdef WINDOWS32
  if ((!STREAM_OK (stdout) && !STREAM_OK (stderr))
      || (sync_handle = create_mutex ()) == -1)
    {
      perror_with_name ("output-sync suppressed: ", "stderr");
      output_sync = 0;
    }
  else
    {
      combined_output = same_stream (stdout, stderr);
      prepare_mutex_handle_string (sync_handle);
    }

#else
  if (STREAM_OK (stdout))
    {
      struct stat stbuf_o, stbuf_e;

      sync_handle = fileno (stdout);
      combined_output = (fstat (fileno (stdout), &stbuf_o) == 0
                         && fstat (fileno (stderr), &stbuf_e) == 0
                         && stbuf_o.st_dev == stbuf_e.st_dev
                         && stbuf_o.st_ino == stbuf_e.st_ino);
    }
  else if (STREAM_OK (stderr))
    sync_handle = fileno (stderr);
  else
    {
      perror_with_name ("output-sync suppressed: ", "stderr");
      output_sync = 0;
    }
#endif

  return combined_output;
}
コード例 #11
0
play_item_t* new_list_item(play_item_t* list_head) {
    play_item_t* new_item;
    play_item_t* old_tail;

    new_item = PyMem_Malloc(sizeof(play_item_t));
    new_item->next_item = NULL;

    old_tail = list_head;
    while(old_tail->next_item != NULL) {
        old_tail = old_tail->next_item;
    }
    old_tail->next_item = new_item;

    new_item->prev_item = old_tail;
    new_item->mutex = create_mutex();
    new_item->play_id = (list_head->play_id)++;
    new_item->stop_flag = SA_CLEAR;

    dbg1("new list item at %p with ID %llu attached to %p\n", new_item, new_item->play_id, old_tail);

    return new_item;
}
コード例 #12
0
ファイル: buffer.c プロジェクト: necto/verifast
void main()
  //@ requires obs(nil);
  //@ ensures obs(nil);
{
  struct queue *q = create_queue();
    
  //@ close create_mutex_ghost_args(0,nil);
  struct mutex *m = create_mutex();
    
  //@ int gid = new_ctr();
  //@ close create_condvar_ghost_args(m,1,false,vtrn(gid));
  struct condvar *v = create_condvar();

  struct buffer *b = malloc(sizeof(struct buffer));
  if (b==0)
    abort();    
  b->q = q;
  b->m = m;
  b->v = v;
  //@ b->gid = gid;
    
  //@ leak [_]b->v |-> _;
  //@ leak [_]b->m |-> _;
  //@ leak [_]b->gid |-> _;
  //@ leak [_]malloc_block_buffer(_);

  //@ g_chrgu(v);
  //@ inc_ctr(gid);    
  //@ close init_mutex_ghost_args(buffer(b));
  //@ close buffer(b)(empb,finc(empb,v));
  //@ init_mutex(m);
  //@ leak [_]mutex(m);

  //@ close thread_run_data(producer_thread)(cons(v,nil),b);
  thread_start(producer_thread, b);
    
  //@ close thread_run_data(consumer_thread)(nil,b);
  thread_start(consumer_thread, b);
}
コード例 #13
0
int main ()
{
   srand((unsigned int)time(NULL));
   int i;
   //Creating and intializing trains
   trains = (int *)malloc(t*sizeof(int));
   for(i=0;i<t;++i)
      trains[i] = c;

   //Initialise all activeQueries train number to -1
   for(i=0;i<MAX;++i)
      activeQueries[i][0] = -1;

   pthread_t tid[s];
   tinfo param[s];

   create_mutex();
   create_workers(tid,param);
   do_work(tid,param);
   wind_up();
   exit(0);
}
コード例 #14
0
ファイル: mutex.cpp プロジェクト: Shajan/CS
static void test() {
  pid_t childpid;
  mutex mparent = create_mutex(MUTEX_NAME, true);

  if ((childpid = fork()) == -1) {
    sys_error_exit("fork");
  }

  if (childpid == 0) {
    /* Child process */
    mutex m = open_mutex(MUTEX_NAME);
    log("Child try lock mutex");
    if (trylock_mutex(m))  // Should not succeed
      error_exit("Child trylock_mutex: mutex not locked by parent");
    log("Child try to lock, 1 second timeout");
    if (lock_withtimeout_mutex(m, 1))
      error_exit("Child lock_withtimeout_mutex: mutex not locked by parent");
    log("Child try to lock, 4 second timeout");
    if (!lock_withtimeout_mutex(m, 4))
      error_exit("Child lock_withtimeout_mutex: mutex locked by parent");
    log("Child release lock");
    unlock_mutex(m);
    close_mutex(m);
    exit(0);
  } else {
    /* Parent process */
    log("Parent sleep 2 second with lock");
    sleep(2);
    log("Parent unlock");
    unlock_mutex(mparent);
    log("Parent sleep 2 seconds without lock");
    sleep(2);
    log("Parent wait for lock");
    lock_mutex(mparent);
    log("Parent got lock");
    destroy_mutex(MUTEX_NAME, mparent);
  }
}
コード例 #15
0
struct buffer *create_buffer(int size)
//@ requires true &*& size > 0 &*& size * sizeof(int) < INT_MAX &*& [_]ghost_cell<list<int> >(?id_contents, ?alltext);
/*@ ensures
  [_]ghost_cell(id_contents, alltext)
  &*& result == 0 ?
    emp
  :
    buffer(result, id_contents, ?id_progress_read, ?id_progress_write)
    &*& token(id_progress_read, 0)
    &*& token(id_progress_write, 0);
@*/
{
  struct buffer *buffer = malloc(sizeof(struct buffer));
  if (buffer == 0){
    return 0;
  }
  struct ring_buffer *ring_buffer = ring_buffer_create(size);
  if (ring_buffer == 0){
    free(buffer);
    return 0;
  }
  buffer->ring_buffer = ring_buffer;
  //@ int id_progress_read = create_ghost_cell(0);
  //@ int id_progress_write = create_ghost_cell(0); 
  //@ close create_mutex_ghost_arg(buffer_protected(buffer, id_contents, id_progress_read, id_progress_write));
  //@ close exists<list<int> >(nil);
  //@ close buffer_protected(buffer, id_contents, id_progress_read, id_progress_write)();
  buffer->mutex = create_mutex();
  //@ close create_mutex_cond_ghost_args(buffer->mutex);
  buffer->cond_can_push = create_mutex_cond();
  //@ close create_mutex_cond_ghost_args(buffer->mutex);
  buffer->cond_can_pop = create_mutex_cond();

  return buffer;
  //@ close buffer(buffer, id_contents, id_progress_read, id_progress_write);
  //@ close token(id_progress_read, 0);
  //@ close token(id_progress_write, 0);
}
コード例 #16
0
ファイル: threads_wrapper.c プロジェクト: ebichu/dd-wrt
static mutex_t *create_mutex_serial(mutex_t *mutex)
{

	if (!(mutex))

		return NULL;

	/*
		critical section to avoid remote possibility of race on same *mutex --
		see get_mutex comments above.  module clients must initialize the
		present module with threads_wrapper_init().
	*/

	get_mutex(&crit_sec_create_mutex);

	if (!(mutex->is_init)) 

		create_mutex(mutex);


	release_mutex(&crit_sec_create_mutex);

	return mutex;
}
コード例 #17
0
ファイル: barbershop.c プロジェクト: necto/verifast
void main()
    //@ requires obs(nil);
    //@ ensures obs(nil);
{
    //@ close create_mutex_ghost_args(0,nil);
    struct mutex *m = create_mutex();
    
    //@ int gba = new_ctr();
    //@ close create_condvar_ghost_args(m,1,false,vtrn(gba));
    struct condvar *cbarber = create_condvar();

    //@ int gch = new_ctr();
    //@ close create_condvar_ghost_args(m,2,false,vtrn(gch));
    struct condvar *cchair = create_condvar();

    //@ int gdo = new_ctr();
    //@ close create_condvar_ghost_args(m,3,false,vtrn(gdo));
    struct condvar *cdoor = create_condvar();
    
    //@ int gcu = new_ctr();
    //@ close create_condvar_ghost_args(m,4,false,vtrn(gcu));
    struct condvar *ccustomer = create_condvar();
    
    struct barbershop *b = malloc(sizeof(struct barbershop));
    if (b==0)
      abort();
    b->m = m;
    b->barber = 0;
    b->chair = 0;
    b->door = 0;
    b->cbarber = cbarber;
    b->cchair = cchair;
    b->cdoor = cdoor;
    b->ccustomer = ccustomer;
    //@ b->gba = gba;
    //@ b->gch = gch;
    //@ b->gdo = gdo;
    //@ b->gcu = gcu;
    
    //@ leak [_]b->cbarber |-> _;
    //@ leak [_]b->cchair |-> _;
    //@ leak [_]b->cdoor |-> _;
    //@ leak [_]b->ccustomer |-> _;            
    //@ leak [_]b->m |-> _;  
    //@ leak [_]b->gba |-> _;               
    //@ leak [_]b->gch |-> _;               
    //@ leak [_]b->gdo |-> _;               
    //@ leak [_]b->gcu |-> _;               
    //@ leak [_]malloc_block_barbershop(_);
    
    //@ close init_mutex_ghost_args(barbershop(b));
    //@ g_chrgu(cbarber);    
    //@ g_chrgu(cchair);    
    //@ g_chrgu(cdoor);    
    //@ g_chrgu(ccustomer);    
    //@ inc_ctr(gba);
    //@ inc_ctr(gch);
    //@ inc_ctr(gdo);
    //@ inc_ctr(gcu);
    //@ inc_ctr(gcu);
    //@ close barbershop(b)(empb,finc(finc(finc(finc(empb,cbarber),cchair),cdoor),ccustomer));    
    //@ init_mutex(m);
    //@ leak [_]mutex(m);
    
    //@ close unprotected_permissions(b,_,_,_,_,_,_,_,_,_);
    //@ close thread_run_data(get_haircut_thread)(cons(cchair,(cons(ccustomer,nil))),b);
    thread_start(get_haircut_thread, b);

    //@ close unprotected_permissions(b,_,_,_,_,_,_,_,_,_);
    //@ close thread_run_data(get_next_customer_thread)(cons(cbarber,nil),b);
    thread_start(get_next_customer_thread, b);

    //@ close unprotected_permissions(b,_,_,_,_,_,_,_,_,_);
    //@ close thread_run_data(finished_cut_customer_thread)(cons(cdoor,nil),b);
    thread_start(finished_cut_customer_thread, b);
}
コード例 #18
0
ファイル: print_hi.c プロジェクト: jarsp/verifast
int main()
//@ requires true;
//@ ensures result == 'i' || result == 'h';
{
  struct buffer *b = malloc(sizeof(struct buffer));
  if (b == 0){
    abort();
  }
  //@ int id = create_gcf();
  //@ iot iot1 = iot_init;
  //@ iot ioth = iot_split_left(iot1);
  //@ iot ioti = iot_split_right(iot1);
  //@ iot iot2 = iot_join(ioth, ioti);
  //@ create_gcf_instance(id, iot1, {});
  //@ create_gcf_instance(id, ioth, {});
  //@ create_gcf_instance(id, ioti, {});
  //@ create_gcf_instance(id, iot2, {});
  
  //@ close exists<pair<int, list<int> > >(pair('l', {'h'}));
  //@ close exists<pair<int, list<int> > >(pair('r', {'i'}));
  //@ close buffer_invar(id, b)();
  //@ close create_mutex_ghost_arg(buffer_invar(id, b));
  b->mutex = create_mutex();
  
  //@ close buffer(id, b);
  //@ place t1 = place(iot1, {}, place_none, place_none, id);
  //@ place th1 = place(ioth, {}, t1, place_none, id);
  //@ place th2 = place(ioth, {'h'}, t1, place_none, id);
  //@ place ti1 = place(ioti, {}, t1, place_none, id);
  //@ place ti2 = place(ioti, {'i'}, t1, place_none, id);
  //@ place t2 = place(iot2, {}, th2, ti2, id);
  
  //@ close token(t1);
  //@ close split(t1, th1, ti1);
  //@ close putchar_io(id, th1, 'h', th2);
  //@ close putchar_io(id, ti1, 'i', ti2);
  //@ close join(th2, ti2, t2);
  
  print_hi(b);
  //@ open buffer(id, b);
  mutex_dispose(b->mutex);
  //@ open buffer_invar(id, b)();
  int x = b->c;
  free(b);
  return x;
  
  // Open tokens to obtain info about progresses.
  // We need this to prove the postcondition.
  //@ open token(_);
  //@ open token(_);
  //@ open token(_);
  //@ open token(_);
  //@ open token(_);
  
  // Leak ghost data
  //@ leak gcf_instance(_, _, _);
  //@ leak gcf_instance(_, _, _);
  //@ leak gcf_instance(_, _, _);
  //@ leak gcf_instance(_, _, _);
  //@ leak gcf(_, _);
  //@ leak exists(_);
  //@ leak exists(_);
}