static void init_serial_port(char *devname, int iobase, int irq, struct unit *unit) { struct serial_port *sp; dev_t devno; sp = (struct serial_port *) kmalloc(sizeof(struct serial_port)); memset(sp, 0, sizeof(struct serial_port)); sp->iobase = iobase; sp->irq = irq; sp->cfg.speed = 115200; sp->cfg.databits = 8; sp->cfg.parity = PARITY_NONE; sp->cfg.stopbits = 1; sp->cfg.rx_timeout = INFINITE; sp->cfg.tx_timeout = INFINITE; init_dpc(&sp->dpc); sp->dpc.flags |= DPC_NORAND; init_event(&sp->event, 0, 0); init_sem(&sp->tx_sem, QUEUE_SIZE); init_mutex(&sp->tx_lock, 0); init_sem(&sp->rx_sem, 0); init_mutex(&sp->rx_lock, 0); // Disable interrupts outp(sp->iobase + UART_IER, 0); // Determine UART type check_uart_type(sp); // Set baudrate, parity, databits and stopbits serial_config(sp); // Enable FIFO if (sp->type == UART_16550A) { outp(sp->iobase + UART_FCR, FCR_ENABLE | FCR_RCV_RST | FCR_XMT_RST | FCR_TRIGGER_14); } // Turn on DTR, RTS and OUT2 sp->mcr = MCR_DTR | MCR_RTS | MCR_IENABLE; outp(sp->iobase + UART_MCR, sp->mcr); // Create device devno = dev_make(devname, &serial_driver, unit, sp); // Enable interrupts register_interrupt(&sp->intr, IRQ2INTR(sp->irq), serial_handler, sp); enable_irq(sp->irq); outp((unsigned short) (sp->iobase + UART_IER), IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); kprintf(KERN_INFO "%s: %s iobase 0x%x irq %d\n", device(devno)->name, uart_name[sp->type], sp->iobase, sp->irq); }
void osi_PostPopulateVCache(struct vcache *avc) { memset(&(avc->vc_bhv_desc), 0, sizeof(avc->vc_bhv_desc)); bhv_desc_init(&(avc->vc_bhv_desc), avc, avc, &Afs_vnodeops); #if defined(AFS_SGI65_ENV) vn_bhv_head_init(&(avc->v.v_bh), "afsvp"); vn_bhv_insert_initial(&(avc->v.v_bh), &(avc->vc_bhv_desc)); avc->v.v_mreg = avc->v.v_mregb = (struct pregion *)avc; # if defined(VNODE_TRACING) avc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0); # endif init_bitlock(&avc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache", avc->v.v_number); init_mutex(&avc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)avc); init_mutex(&avc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)avc); #else bhv_head_init(&(avc->v.v_bh)); bhv_insert_initial(&(avc->v.v_bh), &(avc->vc_bhv_desc)); #endif vnode_pcache_init(&avc->v); #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK) /* Above define is never true execpt in SGI test kernels. */ init_bitlock(&avc->v.v_flag, VLOCK, "vnode", avc->v.v_number); #endif #ifdef INTR_KTHREADS AFS_VN_INIT_BUF_LOCK(&(avc->v)); #endif vSetVfsp(avc, afs_globalVFS); vSetType(avc, VREG); VN_SET_DPAGES(&(avc->v), NULL); osi_Assert((avc->v.v_flag & VINACT) == 0); avc->v.v_flag = 0; osi_Assert(VN_GET_PGCNT(&(avc->v)) == 0); osi_Assert(avc->mapcnt == 0 && avc->vc_locktrips == 0); osi_Assert(avc->vc_rwlockid == OSI_NO_LOCKID); osi_Assert(avc->v.v_filocks == NULL); # if !defined(AFS_SGI65_ENV) osi_Assert(avc->v.v_filocksem == NULL); # endif osi_Assert(avc->cred == NULL); # if defined(AFS_SGI64_ENV) vnode_pcache_reinit(&avc->v); avc->v.v_rdev = NODEV; # endif vn_initlist((struct vnlist *)&avc->v); avc->lastr = 0; }
PJ_DEF(pj_status_t) pj_init(void) { char dummy_guid[PJ_GUID_LENGTH]; pj_str_t guid; PJ_LOG(5, ("pj_init", "Initializing PJ Library..")); /* Init this thread's TLS. */ #if PJ_HAS_THREADS if (pj_thread_init() != 0) { PJ_LOG(1, ("pj_init", "Thread initialization has returned an error")); return -1; } /* Critical section. */ if (init_mutex(&critical_section, "critsec", PJ_MUTEX_SIMPLE) != 0) return -1; #endif /* Init random seed. */ srand( clock() ); /* Startup GUID. */ guid.ptr = dummy_guid; pj_generate_unique_string( &guid ); return PJ_OK; }
DynamicPlane::DynamicPlane() : gstDynamic() #endif { // initialize transform to identity fixedPlane = new TexturePlane(0.0, 1.0, 0.0, 0.0); #ifdef VRPN_USE_HDAPI //XXX Probably going to need some linking code in here somewhere to keep track of objects #else xform.identity(); fixedPlane->setParent(this); #endif buzzForce = new BuzzForceField(); buzzForce->setPlane(vrpn_HapticPlane(0.0, 1.0, 0.0, 0.0)); buzzForce->setSpring(fixedPlane->getSurfaceKspring()); buzzForce->restrictToSurface(TRUE); buzzForce->adjustToTexturePlane(fixedPlane); plane = vrpn_HapticPlane(0.0, 1.0, 0.0, 0.0); lastPlane = vrpn_HapticPlane(plane); #ifdef VRPN_USE_HDAPI //XXX Probably going to need some linking code in here somewhere to keep track of objects #else addChild(fixedPlane); addChild(buzzForce); #endif _using_buzz = FALSE; _active = FALSE; _is_new_plane = FALSE; buzzForce->deactivate(); fixedPlane->enableTexture(); fixedPlane->setTextureSize(10.0); fixedPlane->setTextureAspectRatio(0.0); fixedPlane->setInEffect(FALSE); init_mutex(&xform_mutex); }
void TexturePlane::init() { isNewPlane = FALSE; inEffect= FALSE; isInRecovery = FALSE; recoveryPlaneCount = 0; originalPlane = plane; lastDepth = 0; dIncrement = 0; numRecoveryCycles = 1; // boundingRadius = 1000.0; #ifndef VRPN_USE_HDAPI invalidateCumTransf(); dynamicParent = NULL; #endif textureOrigin = vrpn_HapticPosition(0,0,0); usingTexture = 0; texWL = 10.0; texWN = 1/texWL; texAmp = 0; textureAspect = texAmp*2.0/texWL; fadeActive = FALSE; fadeOldKspring = 0; dSpring_dt = 0; dataCB = NULL; userdata = NULL; data_time = 0; safety_ineffect = TRUE; newCoordinates = FALSE; inContact = FALSE; init_mutex(&tex_param_mutex); }
int main(int argc, char **argv) { int i, dup_vote; int cores, block_size; cores = 16; block_size = 1024*1024; int *thread; file_struct *fs; threadpool_t *pool; thread = malloc(sizeof(int)); if(argc<2) { printf("[usage] vote_counter [-dupvote] [-cores C] [-blocksize B] [filename1] ... [filenameN]\n"); exit(-1); } char **file_list = malloc(sizeof(char *) * MAX_FILE_NUM); memset(file_list, 0, (sizeof(char*))*MAX_FILE_NUM); //analyze input arguments if(!(dup_vote = opts(argc, argv, file_list, &cores, &block_size, &thread))) { exit(-1); } printf("thread number %d\n", *thread); //printf("cores %d; block_size %d\n", cores, block_size); //create pool according to total file size & number if((pool = threadpool_create(*thread, cores, 0)) == NULL) { printf("[error] can not initalize thread\n"); exit(-1); } init_mutex(); dup_vote = dup_vote == 2 ? TRUE : FALSE; for (i=0; file_list[i]!=NULL; i++) { fs = malloc(sizeof(file_struct)); fs->filename = file_list[i]; fs->dup_vote = dup_vote; fs->block_size = block_size; //send read task to thread pool threadpool_add(pool, &readfile, fs, 0); } //wait until all thread finish their job threadpool_destroy(pool, 1); get_vote_result(3); return 0; }
static int init_task_struct(struct task_struct *task, u32 flag) { struct task_struct *parent; unsigned long flags; /* if thread is a kernel thread, his parent is idle */ if (flag & PROCESS_TYPE_KERNEL) parent = idle; else parent = current; /* get a new pid */ task->pid = get_new_pid(task); if ((task->pid) < 0) return -EINVAL; task->uid = parent->uid; task->stack_base = NULL; task->stack_base = NULL; strncpy(task->name, parent->name, PROCESS_NAME_SIZE); task->flag = flag; task->state = 0; /* add task to the child list of his parent. */ task->parent = parent; init_list(&task->p); init_list(&task->child); init_mutex(&task->mutex); enter_critical(&flags); list_add(&parent->child, &task->p); exit_critical(&flags); return 0; }
int x11c_initialise(X11Common* x11Common, int reviewDuration, OnScreenDisplay* osd, X11WindowInfo* windowInfo) { memset(x11Common, 0, sizeof(x11Common)); x11Common->reviewDuration = reviewDuration; x11Common->osd = osd; x11Common->progressBarInput.data = x11Common; x11Common->progressBarInput.set_listener = x11c_set_pbar_listener; x11Common->progressBarInput.unset_listener = x11c_unset_pbar_listener; x11Common->progressBarInput.close = x11c_close_pbar; x11Common->keyboardInput.data = x11Common; x11Common->keyboardInput.set_listener = x11c_set_keyboard_listener; x11Common->keyboardInput.unset_listener = x11c_unset_keyboard_listener; x11Common->keyboardInput.close = x11c_close_keyboard; x11Common->mouseInput.data = x11Common; x11Common->mouseInput.set_listener = x11c_set_mouse_listener; x11Common->mouseInput.unset_listener = x11c_unset_mouse_listener; x11Common->mouseInput.close = x11c_close_mouse; if (windowInfo) { x11Common->windowInfo = *windowInfo; } CHK_ORET(XInitThreads() != 0); CHK_ORET(init_mutex(&x11Common->eventMutex)); CHK_ORET(create_joinable_thread(&x11Common->processEventThreadId, process_event_thread, x11Common)); return 1; }
static inline bool init_mutexes(void) { DWORD pid = GetCurrentProcessId(); tex_mutexes[0] = init_mutex(MUTEX_TEXTURE1, pid); if (!tex_mutexes[0]) { return false; } tex_mutexes[1] = init_mutex(MUTEX_TEXTURE2, pid); if (!tex_mutexes[1]) { return false; } return true; }
PJ_DEF(pj_status_t) pj_init(void) { WSADATA wsa; char dummy_guid[32]; /* use maximum GUID length */ pj_str_t guid; PJ_LOG(5, ("pj_init", "Initializing PJ Library..")); /* Init Winsock.. */ if (WSAStartup(MAKEWORD(2,0), &wsa) != 0) { PJ_LOG(1, ("pj_init", "Winsock initialization has returned an error")); return -1; } /* Init this thread's TLS. */ if (pj_thread_init() != 0) { PJ_LOG(1, ("pj_init", "Thread initialization has returned an error")); return -1; } /* Init random seed. */ srand( GetCurrentProcessId() ); /* Startup GUID. */ guid.ptr = dummy_guid; pj_generate_unique_string( &guid ); /* Initialize critical section. */ if (init_mutex(&critical_section_mutex, "pj%p") != 0) return -1; return PJ_OK; }
OFDPE init_port_manager( const size_t max_send_queue_length, const size_t max_recv_queue_length ) { if ( max_send_queue_length == 0 || max_recv_queue_length == 0 ) { error( "Failed to initialize port manager. Maximum queue length must be greater than zero " "( max_send_queue = %u, max_recv_queue = %u ).", max_send_queue_length, max_recv_queue_length ); return ERROR_INVALID_PARAMETER; } bool ret = init_mutex( &mutex ); if ( !ret ) { return ERROR_INIT_MUTEX; } ret = lock_mutex( &mutex ); if ( !ret ) { return ERROR_LOCK; } config.max_send_queue_length = max_send_queue_length; config.max_recv_queue_length = max_recv_queue_length; init_switch_port(); add_periodic_event_callback_safe( PORT_STATUS_UPDATE_INTERVAL, update_switch_port_status_and_stats, NULL ); ret = unlock_mutex( &mutex ); if ( !ret ) { return ERROR_UNLOCK; } return OFDPE_SUCCESS; }
static struct dentry *new_dentry(struct dentry *parent, struct disk_dentry *ddent, struct chunk_node *ddent_cnode, struct mutex *ddent_mutex) { struct dentry *dentry; assert(have_mutex(ddent_mutex)); dentry = malloc(sizeof(struct dentry)); if (!dentry) return ERR_PTR(ENOMEM); dentry->ddent = ddent; dentry->ddent_cnode = ddent_cnode; dentry->ddent_mutex = ddent_mutex; dentry->parent = parent; dentry->size = le64toh(ddent->size); dentry->mode = le16toh(ddent->mode); dentry->mtime.tv_sec = le32toh(ddent->mtime); dentry->mtime.tv_usec = ddent->mtime_csec * 10000; init_mutex(&dentry->mutex); dentry->ref_count = 0; memset(&dentry->chunk_tree, 0, sizeof(struct chunk_tree)); dentry->secret_chunk = NULL; if (parent) { locked_inc(&parent->ref_count, parent->ddent_mutex); assert(ddent_cnode != NULL); assert(!IS_ERR(ddent_cnode)); dentry_ptr(dentry) = dentry; } return dentry; }
void Init_rbcoremidi() { init_mutex(); init_midi_data(); install_at_exit_handler(); mCoreMIDI = rb_define_module("CoreMIDI"); mCoreMIDIAPI = rb_define_module_under(mCoreMIDI, "API"); rb_define_singleton_method(mCoreMIDIAPI, "create_input_port", t_create_input_port, 2); rb_define_singleton_method(mCoreMIDIAPI, "create_client", t_create_client, 1); rb_define_singleton_method(mCoreMIDIAPI, "get_sources", t_get_sources, 0); rb_define_singleton_method(mCoreMIDIAPI, "get_num_sources", t_get_num_sources, 0); rb_define_singleton_method(mCoreMIDIAPI, "connect_source_to_port", t_connect_source_to_port, 2); rb_define_singleton_method(mCoreMIDIAPI, "disconnect_source_from_port", t_disconnect_source_from_port, 2); rb_define_singleton_method(mCoreMIDIAPI, "check_for_new_data", t_check_for_new_data, 0); // Define CoreMIDI::API::InputPort class cInputPort = rb_define_class_under(mCoreMIDIAPI, "InputPort", rb_cObject); rb_define_alloc_func(cInputPort, inputport_alloc); rb_define_method(cInputPort, "initialize", inputport_initialize, 0); // Define CoreMIDI::API::MIDIClient class cMIDIClient = rb_define_class_under(mCoreMIDIAPI, "MIDIClient", rb_cObject); rb_define_alloc_func(cMIDIClient, midiclient_alloc); rb_define_method(cMIDIClient, "initialize", midiclient_initialize, 0); }
/** * Re-allocate memory * * @param mem pointer to previously talloc'ed memory * @param size amount of memory requested * * @return a pointer to the allocated memory if successful, NULL otherwise */ void* trealloc ( void* mem, size_t size ) { if (mutex == NULL) { init_mutex(); } pthread_mutex_lock(mutex); void **header[3], **aux; if ( !mem ) { pthread_mutex_unlock(mutex); return talloc( size, NULL ); } header[0] = ((void**)mem)[-3]; header[1] = ((void**)mem)[-2]; header[2] = ((void**)mem)[-1]; aux = realloc( (void**)mem - 3, size + sizeof( void* ) * 3 ); if ( !aux ) { pthread_mutex_unlock(mutex); return NULL; } if ( (void**)mem - 3 != aux ) { aux[0] = header[0]; aux[1] = header[1]; aux[2] = header[2]; if ( aux[0] ) header[0][2] = aux; if ( aux[1] ) header[1][2] = aux; if ( aux[2] ) header[2][ header[2][1] == (void**)mem - 3 ] = aux; } pthread_mutex_unlock(mutex); return aux + 3; }
/* support for malloc.h */ void init_mem(void *buffer, unsigned int size) { # ifdef SAFE init_mutex(&malloc_mutex); # endif _mem_init((unsigned int)buffer, (unsigned int)buffer + size); }
static VALUE rb_mutex_alloc(VALUE klass) { Mutex *mutex; mutex = ALLOC(Mutex); init_mutex(mutex); return Data_Wrap_Struct(klass, mark_mutex, free_mutex, mutex); }
static void init_queue(Queue *queue) { init_mutex(&queue->mutex); init_condvar(&queue->value_available); init_condvar(&queue->space_available); init_list(&queue->values); queue->capacity = 0; }
mutex_t *thread_create_mutex(const char *name) { mutex_t *tmp = init_mutex(name); if (!tmp) { kernel_panic("cannot create a mutex.\n"); } return (tmp); }
void init_scheduler() { if(num_Thread==0) { th_t *mainThread, *scheduleThread; if((mainThread = thread_alloc()) == NULL) abort(); if((scheduleThread = thread_alloc()) == NULL) abort(); init_sigaction(); if((ready_queueHead = queueHead_alloc()) == NULL) abort(); if((sched_queueHead = queueHead_alloc()) == NULL) abort(); th_queue_init(ready_queueHead); th_queue_init(sched_queueHead); //th_queue_init(&kernel_queue); mainThread->mctx.status = TH_WAITING; mainThread->mctx.stackAddr = NULL; mainThread->tid = num_Thread++; scheduleThread->mctx.status = TH_SCHED; //scheduleThread->tid = num_kernel_thread++; main_kernel_id = scheduleThread->tid = getpid(); num_kernel_thread++; if((scheduleThread->mctx.stackAddr = stack_alloc()) == NULL) abort(); if((mainThread->mctx.stackAddr = stack_alloc()) == NULL) abort(); //create machine context void (*fnptr)(void*) = (void(*)(void*))scheduler; mctx_create(&(scheduleThread->mctx), fnptr, NULL, scheduleThread->mctx.stackAddr, STACK_SIZE); // mctx_create(&mctx_list[0],fnptr,NULL,mctx_list[0].stackAddr,STACK_SIZE); th_queue_insert(sched_queueHead, PRIORITY_SCHEDULER, scheduleThread); th_queue_insert(ready_queueHead, PRIORITY_NORMAL, mainThread); init_sigaction(); init_mutex(); //th_queue_insert(&kernel_queue, PRIORITY_SCHEDULER, scheduleThread); switch_to_scheduler(); //jump to scheduler } }
int hac_create_http_access(MediaPlayer* player, int port, HTTPAccess** access) { HTTPAccess* newAccess; CALLOC_ORET(newAccess, HTTPAccess, 1); CHK_OFAIL(har_create_resources(&newAccess->resources)); newAccess->control = ply_get_media_control(player); if (newAccess->control == NULL) { fprintf(stderr, "Media player has no control\n"); goto fail; } newAccess->playerListener.data = newAccess; newAccess->playerListener.frame_displayed_event = hac_frame_displayed_event; newAccess->playerListener.frame_dropped_event = hac_frame_dropped_event; newAccess->playerListener.state_change_event = hac_state_change_event; newAccess->playerListener.end_of_source_event = hac_end_of_source_event; newAccess->playerListener.start_of_source_event = hac_start_of_source_event; newAccess->playerListener.player_closed = hac_player_closed; if (!ply_register_player_listener(player, &newAccess->playerListener)) { fprintf(stderr, "Failed to register http access as player listener\n"); goto fail; } CHK_OFAIL((newAccess->ctx = shttpd_init(NULL, "document_root", "/dev/null", NULL)) != NULL); shttpd_register_uri(newAccess->ctx, "/", &http_player_page, newAccess); shttpd_register_uri(newAccess->ctx, "/player.html", &http_player_page, newAccess); shttpd_register_uri(newAccess->ctx, "/index.html", &http_player_page, newAccess); shttpd_register_uri(newAccess->ctx, "/resources/*", &http_static_content, newAccess); shttpd_register_uri(newAccess->ctx, "/player/state.xml", &http_player_state_xml, newAccess); shttpd_register_uri(newAccess->ctx, "/player/state.txt", &http_player_state_txt, newAccess); shttpd_register_uri(newAccess->ctx, "/player/control/*", &http_player_control, newAccess); CHK_OFAIL(shttpd_listen(newAccess->ctx, port, 0)); CHK_OFAIL(init_mutex(&newAccess->playerStateMutex)); CHK_OFAIL(create_joinable_thread(&newAccess->httpThreadId, http_thread, newAccess)); *access = newAccess; return 1; fail: hac_free_http_access(&newAccess); return 0; }
/* * pj_init(void). * Init PJLIB! */ PJ_DEF(pj_status_t) pj_init(void) { char dummy_guid[PJ_GUID_MAX_LENGTH]; pj_str_t guid; pj_status_t rc; #if PJ_HAS_THREADS /* Init this thread's TLS. */ if ((rc=pj_thread_init()) != 0) { return rc; } /* Critical section. */ if ((rc=init_mutex(&critical_section, "critsec", PJ_MUTEX_RECURSE)) != 0) return rc; #endif /* Init logging */ pj_log_init(); /* Initialize exception ID for the pool. * Must do so after critical section is configured. */ rc = pj_exception_id_alloc("PJLIB/No memory", &PJ_NO_MEMORY_EXCEPTION); if (rc != PJ_SUCCESS) return rc; /* Init random seed. */ /* Or probably not. Let application in charge of this */ /* pj_srand( clock() ); */ /* Startup GUID. */ guid.ptr = dummy_guid; pj_generate_unique_string( &guid ); /* Startup timestamp */ #if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0 { pj_timestamp dummy_ts; if ((rc=pj_get_timestamp(&dummy_ts)) != 0) { return rc; } } #endif PJ_LOG(4,(THIS_FILE, "pjlib %s for POSIX initialized", PJ_VERSION)); return PJ_SUCCESS; }
locker::locker(bool use_mutex /* = true */, bool use_spinlock /* = false */) : pFile_(NULL) , myFHandle_(false) { fHandle_ = ACL_FILE_INVALID; if (use_mutex) init_mutex(use_spinlock); else { mutex_ = NULL; #ifdef ACL_HAS_SPINLOCK spinlock_ = NULL; #endif } }
/** * Allocate zeroed memory * * @param size amount of memory requested * @param parent pointer to previously talloc'ed memory from wich this chunk * depends or NULL * * @return a pointer to the allocated memory */ void* tcalloc ( size_t size, void* parent ) { if (mutex == NULL) { init_mutex(); } pthread_mutex_lock(mutex); void **mem = calloc( 1, size + sizeof( void* ) * 3 ); if ( !mem ) { pthread_mutex_unlock(mutex); return NULL; } talloc_set_parent( mem + 3, parent ); pthread_mutex_unlock(mutex); return mem + 3; }
/* * allocate a queue * our event is auto-reset and initially reset */ TASKQ *task_allocq (int numthreads, int timeout) { TASKQ *q; q = (TASKQ *) malloc (sizeof (TASKQ)); init_mutex (q); init_ready (q, FALSE); q->timeout = timeout; q->queue = NULL; q->pool = NULL; q->maxthreads = numthreads; q->running = 0; q->waiting = 0; q->stop = 0; return (q); }
/** * Free memory * * @param mem pointer to previously talloc'ed memory */ void tfree ( void* mem ) { if ( !mem ) return; if (mutex == NULL) { init_mutex(); } pthread_mutex_lock(mutex); talloc_set_parent( mem, NULL ); __tfree( ((void**)mem)[-3] ); free( (void**)mem - 3 ); pthread_mutex_unlock(mutex); }
int init_dv_decoder_resources() { if (g_decoderResourceRefCount == 0) { av_register_all(); memset(&g_decoderResource, 0, sizeof(DVDecoderResource)); CHK_ORET(init_mutex(&g_decoderResource.resourceMutex)); g_decoderResourceRefCount = 1; } else { g_decoderResourceRefCount++; } return 1; }
static char *sqlite_chunkdb_ctor(const char *spec, struct chunk_db *chunk_db) { struct db_info *db_info = chunk_db->db_info; int error; init_mutex(&db_info->mutex); error = sqlite3_open(spec, &db_info->db); if (error != SQLITE_OK) { char *errstr = sprintf_new( "Can't open SQLite database '%s': %s.", spec, sqlite3_errmsg(db_info->db)); sqlite3_close(db_info->db); return errstr; } return 0; }
//init. static int32_t init( struct CSession_t *pThis, const CSessionParam *pSessionParam ) { int32_t iRetCode = -1; if ( !pThis || !pSessionParam ) return iRetCode; if ( init_mutex( &( pThis->Locker ) ) < 0 ) return iRetCode; lock( &( pThis->Locker ) ); iRetCode = init_http_socket( pThis, pSessionParam ); unlock( &( pThis->Locker ) ); return iRetCode; }
static void init(void) { int i; char *s; char *error; struct rlimit rlim; getrlimit(RLIMIT_NOFILE, &rlim); max_fds=(int) rlim.rlim_max; fds=(struct fadv_info *) malloc(max_fds * sizeof(struct fadv_info)); assert(fds != NULL); _original_open = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "open"); _original_open64 = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "open64"); _original_creat = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "creat"); _original_creat64 = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "creat64"); _original_openat = (int (*)(int, const char *, int, mode_t)) dlsym(RTLD_NEXT, "openat"); _original_openat64 = (int (*)(int, const char *, int, mode_t)) dlsym(RTLD_NEXT, "openat64"); _original_dup = (int (*)(int)) dlsym(RTLD_NEXT, "dup"); _original_dup2 = (int (*)(int, int)) dlsym(RTLD_NEXT, "dup2"); _original_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); _original_fopen = (FILE *(*)(const char *, const char *)) dlsym(RTLD_NEXT, "fopen"); _original_fopen64 = (FILE *(*)(const char *, const char *)) dlsym(RTLD_NEXT, "fopen64"); _original_fclose = (int (*)(FILE *)) dlsym(RTLD_NEXT, "fclose"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(EXIT_FAILURE); } if((s = getenv(env_nr_fadvise)) != NULL) nr_fadvise = atoi(s); if(nr_fadvise <= 0) nr_fadvise = 1; PAGESIZE = getpagesize(); for(i = 0; i < max_fds; i++) fds[i].fd = -1; init_mutex(); init_debugging(); handle_stdout(); }
void sync_threads() { //init the mutex variables init_mutex(); //create thread ids pthread_t tid[THREADS]; pthread_create(&tid[0], NULL, thread0, NULL); pthread_create(&tid[1], NULL, thread1, NULL); pthread_create(&tid[2], NULL, thread2, NULL); pthread_join(tid[0], NULL); pthread_join(tid[1], NULL); pthread_join(tid[2], NULL); sem_destroy(&mutex[0]); sem_destroy(&mutex[1]); sem_destroy(&mutex[2]); }