int module_install(void) { nodes=0; api=0; primary = (struct ata_controller *)kmalloc(sizeof(struct ata_controller)); secondary = (struct ata_controller *)kmalloc(sizeof(struct ata_controller)); int res = init_ata_device(); if(res) { if(res < 0) kprintf("Error in init'ing ATA controller\n"); kfree(primary); kfree(secondary); if(nodes) kfree(nodes); return EEXIST; } irq_primary = cpu_interrupt_register_handler(32 + ATA_PRIMARY_IRQ, ata_irq_handler); irq_secondary = cpu_interrupt_register_handler(32 + ATA_SECONDARY_IRQ, ata_irq_handler); api = dm_set_available_block_device(atapi_rw_main, 2048, ioctl_atapi, atapi_rw_main_multiple, 0); dm_set_block_device(3, ata_rw_main, 512, ioctl_ata, ata_rw_multiple, 0); primary->wait = mutex_create(0, 0); secondary->wait = mutex_create(0, 0); primary->id=0; secondary->id=1; init_ata_controller(primary); init_ata_controller(secondary); return 0; }
void fun1(void* str) { int ret2,i,ind; str = str; for(i=0 ;i<MAX_MUTEX;i++) { ind = mutex_create(); } ret2 = mutex_create(); check_return(errno,ENOMEM,"3. Mutex Create returns ENOMEM"); ret2 = mutex_unlock(165); check_return(errno,EINVAL,"4. Mutex Unlock return EINVAL"); ret2 = mutex_unlock(23); check_return(errno,EPERM,"5. Mutex Unlock return EPERM"); ret2 = mutex_lock(124); check_return(errno,EINVAL,"6. Mutex Lock return EINVAL"); ret2 = mutex_lock(4); check_return(ret2,0,"7. Mutex Lock return success"); ret2 = mutex_lock(4); check_return(errno,EDEADLOCK,"8. Mutex Lock return EDEADLOCK"); ret2 = mutex_unlock(4); check_return(ret2,0,"9. Mutex Unlock return success"); ret2 = event_wait(10000); check_return(errno,EINVAL,"10. Event Wait return EINVAL"); puts("TEST END!\n"); while(1) { spin++; } }
/* * XXX bad assumption here that conn_wrap_fd for SSL can only happens * for the server side!!!! FIXME !!!! */ Connection *conn_wrap_fd(int fd, int ssl) { Connection *conn; if (socket_set_blocking(fd, 0) < 0) return NULL; conn = gw_malloc(sizeof(*conn)); conn->inlock = mutex_create(); conn->outlock = mutex_create(); conn->claimed = 0; conn->outbuf = octstr_create(""); conn->outbufpos = 0; conn->inbuf = octstr_create(""); conn->inbufpos = 0; conn->fd = fd; conn->connected = yes; conn->read_eof = 0; conn->io_error = 0; conn->output_buffering = DEFAULT_OUTPUT_BUFFERING; conn->registered = NULL; conn->callback = NULL; conn->callback_data = NULL; conn->callback_data_destroyer = NULL; conn->listening_pollin = 0; conn->listening_pollout = 0; #ifdef HAVE_LIBSSL /* * do all the SSL magic for this connection */ if (ssl) { conn->ssl = SSL_new(global_server_ssl_context); conn->peer_certificate = NULL; /* SSL_set_fd can fail, so check it */ if (SSL_set_fd(conn->ssl, conn->fd) == 0) { /* SSL_set_fd failed, log error and return NULL */ error(errno, "SSL: OpenSSL: %.256s", ERR_error_string(ERR_get_error(), NULL)); conn_destroy(conn); return NULL; } /* SSL_set_verify(conn->ssl, 0, NULL); */ /* set read/write BIO layer to non-blocking mode */ BIO_set_nbio(SSL_get_rbio(conn->ssl), 1); BIO_set_nbio(SSL_get_wbio(conn->ssl), 1); /* set accept state , SSL-Handshake will be handled transparent while SSL_[read|write] */ SSL_set_accept_state(conn->ssl); } else { conn->ssl = NULL; conn->peer_certificate = NULL; } #endif /* HAVE_LIBSSL */ return conn; }
/** * Initialize client state. */ int init_client_state() { client.host = NULL; client.client = NULL; client.state = SVCECLIENT_STATE_DISCONNECTED; client.input_buffer_size = 1024*1024; /* or 1<<20? */ client.input_buffer = (char*)malloc(client.input_buffer_size); client.input_queue = dlist_new(); client.input_error = 0; mutex_create(&client.input_lock); thread_create(&client.input_thread, input_thread, NULL); mutex_create(&client.network_lock); client.server_info = NULL; client.peers = NULL; client.peers_size = 0; client.my_id = -1; client.server_host_name = dnew(); client.server_host_addr = dnew(); client.server_host_port = 0; return 0; }
COND * cond_create() { COND * c = (COND*) malloc(sizeof (COND)); memset(c, 0, sizeof (COND)); c->lock = mutex_create(1); c->wait_sem = mutex_create(MAX_SEMAPHORE); c->wait_done = mutex_create(MAX_SEMAPHORE); c->waiting = c->signals = 0; if (!c->lock || !c->wait_sem || !c->wait_done) { cond_delete(c); c = NULL; } return c; };
List *list_create_real(void) { List *list; list = gw_malloc(sizeof(List)); list->tab = NULL; list->tab_size = 0; list->start = 0; list->len = 0; list->single_operation_lock = mutex_create(); list->permanent_lock = mutex_create(); pthread_cond_init(&list->nonempty, NULL); list->num_producers = 0; return list; }
/*************************************************************//** Creates a mutex array to protect a hash table. */ UNIV_INTERN void hash_create_mutexes_func( /*=====================*/ hash_table_t* table, /*!< in: hash table */ #ifdef UNIV_SYNC_DEBUG ulint sync_level, /*!< in: latching order level of the mutexes: used in the debug version */ #endif /* UNIV_SYNC_DEBUG */ ulint n_mutexes) /*!< in: number of mutexes, must be a power of 2 */ { ulint i; ut_ad(table); ut_ad(table->magic_n == HASH_TABLE_MAGIC_N); ut_a(n_mutexes > 0); ut_a(ut_is_2pow(n_mutexes)); table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t)); for (i = 0; i < n_mutexes; i++) { mutex_create(table->mutexes + i, sync_level); } table->n_mutexes = n_mutexes; }
void swi_handler_c(uint32_t swi_num, int *r) { switch (swi_num) { case READ_SWI: read(r[0], (void*) r[1], (size_t) r[2]); break; case WRITE_SWI: write(r[0], (void*) r[1], (size_t) r[2]); break; case TIME_SWI: time(); break; case SLEEP_SWI: sleep((unsigned long) r[0]); break; case CREATE_SWI: task_create((task_t*) r[0], (size_t) r[1]); break; case MUTEX_CREATE: mutex_create(); break; case MUTEX_LOCK: mutex_lock(r[0]); break; case MUTEX_UNLOCK: mutex_unlock(r[0]); break; case EVENT_WAIT: event_wait(r[0]); break; default: printf("Illegal SWI number: %x\n", swi_num); disable_interrupts(); while(1); } }
void init_mq_system() { g_mq_system = (struct mq_system *)calloc(1,sizeof(*g_mq_system)); g_mq_system->mtx = mutex_create(); g_mq_system->thread_mqs = LINK_LIST_CREATE(); pthread_key_create(&g_mq_system->t_key,0); }
barrior_t barrior_create(int waitcount) { barrior_t b = malloc(sizeof(barrior)); b->wait_count = waitcount; b->mtx = mutex_create(); b->cond = condition_create(); return b; }
/** * Initialize IPC stuff * * @return zero on success, non-zero otherwise */ int wt_ipc_init (void) { read_config (); if (blacklisting) { if (ipc_blacklist_init (blacklist_file, reset_timeout)) { blacklisting_error = TRUE; return -1; } } if (ipc_init (host, port)) { return -1; } ipc_enabled = TRUE; hook_register (CORE_ACTIVATE, wt_ipc_start, 0, HOOK_PRIORITY_NORMAL); hook_register (CORE_DEACTIVATE, wt_ipc_stop, 0, HOOK_PRIORITY_NORMAL); mutex = mutex_create (); wt_ipc_builtin_init (); return 0; }
void tWindow_create_thread(tWindow *p){ DWORD dwThreadId; mutex_create(&p->mutex); if(vb) printf("window create beginning thread\n"); p->thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)WindowThreadFunc, (LPVOID)p, 0, &dwThreadId); if (p->thread==NULL){ printf("couldn't create thread\n"); return; } if(vb) printf("window create init cond waiting\n"); condition_create(&p->thread_init_cond); condition_wait(&p->thread_init_cond,NULL); if(vb) printf("window create init cond return\n"); condition_destroy(&p->thread_init_cond); }
gpointer ves_icall_System_Threading_Mutex_CreateMutex_internal (MonoBoolean owned, MonoStringHandle name, MonoBoolean *created, MonoError *error) { gpointer mutex; *created = TRUE; /* Need to blow away any old errors here, because code tests * for ERROR_ALREADY_EXISTS on success (!) to see if a mutex * was freshly created */ mono_w32error_set_last (ERROR_SUCCESS); if (MONO_HANDLE_IS_NULL (name)) { mutex = mutex_create (owned); } else { gchar *utf8_name = mono_string_handle_to_utf8 (name, error); return_val_if_nok (error, NULL); mutex = namedmutex_create (owned, utf8_name); if (mono_w32error_get_last () == ERROR_ALREADY_EXISTS) *created = FALSE; g_free (utf8_name); } return mutex; }
__attribute__((constructor)) static void diskcache_init(void) { #ifdef UNIX // initialise drand48(): srand48(time(NULL)+(int)getpid()); #else // initialise rand(): #ifdef WINDOWS srand(time(NULL)+GetCurrentProcessId()); #else srand(time(NULL)); #endif #endif // create mutex and lock it instantly: cachemutex = mutex_create(); mutex_lock(cachemutex); // get folder path & create folder: cachefolder = diskcache_generateCacheFolderPath(); if (!cachefolder) { // oops, not good return; } if (!file_CreateDirectory(cachefolder)) { // we failed to create the cache dir. free(cachefolder); cachefolder = NULL; return; } // release mutex again: mutex_release(cachemutex); }
void ir_init(log_level level, char *lircrc) { loglevel = level; #if !LINKALL i = malloc(sizeof(struct lirc)); if (!i || !load_lirc()) { return; } #endif fd = LIRC(i, init, LIRC_CLIENT_ID, 0); if (fd > 0) { if (LIRC(i, readconfig,lircrc, &config, NULL) != 0) { LOG_WARN("error reading config: %s", lircrc); } mutex_create(ir.mutex); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + IR_THREAD_STACK_SIZE); pthread_create(&thread, &attr, ir_thread, NULL); pthread_attr_destroy(&attr); } else { LOG_WARN("failed to connect to lircd - ir processing disabled"); } }
gw_prioqueue_t *gw_prioqueue_create(int(*cmp)(const void*, const void *)) { gw_prioqueue_t *ret; gw_assert(cmp != NULL); ret = gw_malloc(sizeof(*ret)); ret->producers = 0; pthread_cond_init(&ret->nonempty, NULL); ret->mutex = mutex_create(); ret->tab = NULL; ret->size = 0; ret->len = 0; ret->seq = 0; ret->cmp = cmp; /* put NULL item at pos 0 that is our stop marker */ make_bigger(ret, 1); ret->tab[0] = gw_malloc(sizeof(**ret->tab)); ret->tab[0]->item = NULL; ret->tab[0]->seq = ret->seq++; ret->len++; return ret; }
// Allocate a new socket static int sock_open() { int i; mutex_lock(fd_mutex); for (i=0; i<SOCKFD_CNT; i++) if (!fds[i].inuse) break; if (i >= SOCKFD_CNT) i = -1; else { // Clean it out and set it as in-use memset(fds+i, 0, sizeof(sockfd_t)); fds[i].inuse = 1; } mutex_unlock(fd_mutex); // Setup some basic stuff fds[i].mutex = mutex_create(); fds[i].connect = cond_create(); fds[i].recv_avail = cond_create(); fds[i].send_avail = cond_create(); fds[i].connmax = 0; fds[i].conncnt = -1; fds[i].recv = -1; fds[i].send = -1; return i; }
__init int init_routes( void ) { if ( array_init( &static_routes ) != 0 ) { goto error1; } if ( array_init( &device_routes ) != 0 ) { goto error2; } array_set_realloc_size( &static_routes, 32 ); array_set_realloc_size( &device_routes, 8 ); route_mutex = mutex_create( "route mutex", MUTEX_NONE ); if ( route_mutex < 0 ) { goto error3; } return 0; error3: array_destroy( &device_routes ); error2: array_destroy( &static_routes ); error1: return -1; }
int aica_audio_open(int freq, int channels, uint32_t size) { if (audio_mut == NULL) { audio_mut = mutex_create(); } sample_rate = freq; chans = channels; tmpbuf = (uint8*) malloc(BUFFER_MAX_FILL); sndbuf = (uint8*) malloc(BUFFER_MAX_FILL); memset (tmpbuf, 0, BUFFER_MAX_FILL); memset (sndbuf, 0, BUFFER_MAX_FILL); sbsize = size; sndptr = last_read = snd_ct = 0; waiting_for_data = 1; shnd = snd_stream_alloc(aica_audio_callback, sbsize); if(shnd < 0) { ds_printf("DS_ERROR: Can't alloc stream\n"); return -1; } snd_stream_prefill(shnd); snd_stream_start(shnd, freq, channels-1); return 0; }
/******************************************************************//** Initializes the memory system. */ UNIV_INTERN void mem_init( /*=====*/ ulint size) /*!< in: common pool size in bytes */ { #ifdef UNIV_MEM_DEBUG ulint i; /* Initialize the hash table */ ut_a(FALSE == mem_hash_initialized); mutex_create(mem_hash_mutex_key, &mem_hash_mutex, SYNC_MEM_HASH); for (i = 0; i < MEM_HASH_SIZE; i++) { UT_LIST_INIT(*mem_hash_get_nth_cell(i)); } UT_LIST_INIT(mem_all_list_base); mem_hash_initialized = TRUE; #endif if (UNIV_LIKELY(srv_use_sys_malloc)) { /* When innodb_use_sys_malloc is set, the mem_comm_pool won't be used for any allocations. We create a dummy mem_comm_pool, because some statistics and debugging code relies on it being initialized. */ size = 1; } mem_comm_pool = mem_pool_create(size); }
struct neighbour_list * neighbour_list_create() { NEW_STRUCT(ret,neighbour_list); ret->array = assoc_array_create(neighbour_list_get_router_id,assoc_array_key_comp_int); ret->mutex = mutex_create(); return ret; }
/* This function is called in f_mount function to create a new / synchronization object, such as semaphore and mutex. When a zero is / returned, the f_mount function fails with FR_INT_ERR. */ int ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */ BYTE vol, /* Corresponding logical drive being processed */ _SYNC_t* sobj /* Pointer to return the created sync object */ ) { return !mutex_create(sobj); }
void log_init(void) { mutex_create(&_mutex); _file = stderr; log_init_platform(); }
int main() { struct point p; p.x = p.y = p.z = 1; int i = 0; for(; i < 1000; ++i) { g_points[i].mtx = mutex_create(); SetPoint(&g_points[i],p); } thread_t t1 = CREATE_THREAD_RUN(1,SetRotine,NULL); thread_t t2 = CREATE_THREAD_RUN(1,GetRoutine,(void*)1); thread_t t3 = CREATE_THREAD_RUN(1,GetRoutine,(void*)2); thread_t t4 = CREATE_THREAD_RUN(1,GetRoutine,(void*)3); uint32_t tick = GetSystemMs(); while(1) { uint32_t new_tick = GetSystemMs(); if(new_tick - tick >= 1000) { printf("get:%d,set:%d,miss:%d\n",get_count,set_count,miss_count); get_count = set_count = miss_count = 0; tick = new_tick; } sleepms(50); } //getchar(); return 0; }
struct rtp_recorder_t* rtp_recorder_create(crypt_aes_p crypt, bool disable_audio, audio_queue_p audio_queue, struct sockaddr* local_end_point, struct sockaddr* remote_end_point, uint16_t remote_control_port, uint16_t remote_timing_port) { struct rtp_recorder_t* rr = (struct rtp_recorder_t*)malloc(sizeof(struct rtp_recorder_t)); bzero(rr, sizeof(struct rtp_recorder_t)); rr->crypt = crypt; rr->disable_audio = disable_audio; rr->audio_queue = audio_queue; rr->timer_mutex = mutex_create(); rr->timer_cond = condition_create(); rr->remote_control_end_point = sockaddr_copy(remote_end_point); rr->remote_timing_end_point = sockaddr_copy(remote_end_point); sockaddr_set_port(rr->remote_control_end_point, remote_control_port); sockaddr_set_port(rr->remote_timing_end_point, remote_timing_port); rr->streaming_socket = _rtp_recorder_create_socket(rr, "Straming socket", local_end_point, remote_end_point); rr->control_socket = _rtp_recorder_create_socket(rr, "Control socket", local_end_point, remote_end_point); rr->timing_socket = _rtp_recorder_create_socket(rr, "Timing socket", local_end_point, remote_end_point); return rr; }
void fun1(void* str) { // On first pass, create the shared mutex mid = mutex_create(); while(1) { if(even_t1) { // first and last s putchar((int)str); // terminating if(once >0) { putchar((int)'!'); while(1) mid++; } once = 1; even_t1 = 0; } else { // should not succeed right away mutex_lock(mid); // prints e putchar((int)'e'); even_t1 = 1; mutex_unlock(mid); } if (event_wait(0) < 0) { panic("Dev 0 failed"); } } }
/** * Initialize testing stuff * * @return TRUE on success, FALSE otherwise */ BOOL Informatics_init_testing (void) { read_config (); active = mutex_create (); unlink_mutex = mutex_create (); suspended = mutex_create (); lck_mutex = mutex_create (); create_testing_pool (); mutex_lock (active); return TRUE; }
void decode_init(log_level level, const char *opt) { int i; loglevel = level; LOG_INFO("init decode"); // register codecs // alc,wma,wmap,wmal,aac,spt,ogg,ogf,flc,aif,pcm,mp3 i = 0; if (!opt || strstr(opt, "aac")) codecs[i++] = register_faad(); if (!opt || strstr(opt, "ogg")) codecs[i++] = register_vorbis(); if (!opt || strstr(opt, "flac")) codecs[i++] = register_flac(); if (!opt || strstr(opt, "pcm")) codecs[i++] = register_pcm(); // try mad then mpg for mp3 unless command line option passed if ( !opt || strstr(opt, "mp3") || strstr(opt, "mad")) codecs[i] = register_mad(); if ((!opt || strstr(opt, "mp3") || strstr(opt, "mpg")) && !codecs[i]) codecs[i] = register_mpg(); mutex_create(decode.mutex); #if LINUX || OSX pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + DECODE_THREAD_STACK_SIZE); pthread_create(&thread, &attr, decode_thread, NULL); pthread_attr_destroy(&attr); #endif #if WIN thread = CreateThread(NULL, DECODE_THREAD_STACK_SIZE, (LPTHREAD_START_ROUTINE)&decode_thread, NULL, 0, NULL); #endif decode.new_stream = true; decode.state = DECODE_STOPPED; }
void log_init(void) { output_buffer = heap_alloc(BUFF_LEN); output_mutex = mutex_create(); uart_init(UART_PORT, NULL, 0); uart_open(UART_PORT, UART_BAUDRATE, 0); }
struct thread_shared_data *thread_data_create() { struct thread_shared_data *thread = (void *)kmalloc(sizeof(struct thread_shared_data)); thread->magic = THREAD_MAGIC; thread->count = 1; mutex_create(&thread->files_lock, 0); return thread; }