static BOOL log_connection (conn_t * conn, int event, config_t * conf) { switch (event) { case LOG_EVT_SERVERSTART: if (locksinit == FALSE) os_mutex_init (&connection_filelock); if (config_getConnLog (conf)) { os_mutex_lock (&connection_filelock); logfile = fopen (config_getConnLog (conf), "a"); os_mutex_unlock (&connection_filelock); } else { logfile = NULL; } break; case LOG_EVT_SERVERCLOSE: if (logfile) { os_mutex_lock (&connection_filelock); fclose (logfile); logfile = NULL; os_mutex_unlock (&connection_filelock); } break; case LOG_EVT_SERVERRESTART: log_connection (conn, LOG_EVT_SERVERCLOSE, conf); log_connection (conn, LOG_EVT_SERVERSTART, conf); break; case LOG_EVT_LOG: if (logfile) return connection_real_log (conn); break; } return TRUE; }
static BOOL log_checkForLogOutput () { BOOL changed[LOG_MAX]; int i; time_t now; struct tm *tm; #ifdef HAVE_LOCALTIME_R struct tm realtm; #endif #ifdef WITH_DEBUG DEBUG_LOG ("Attempting to find if log output necessary"); #endif for (i = 0; i < LOG_MAX; i++) changed[i] = FALSE; time (&now); os_mutex_lock (&lastlog_lock); #ifdef HAVE_LOCALTIME_R tm = localtime_r (&now, &realtm); #else os_mutex_lock (&localtime_lock); tm = localtime (&now); #endif /* FIXME: Year checking? */ if (tm->tm_mon != lastlog[LOG_MONTH]) changed[LOG_MONTH] = TRUE; if ((tm->tm_mday != lastlog[LOG_DAY]) || (changed[LOG_MONTH])) changed[LOG_DAY] = TRUE; if ((tm->tm_hour != lastlog[LOG_HOUR]) || (changed[LOG_DAY])) changed[LOG_HOUR] = TRUE; if ((tm->tm_min != lastlog[LOG_MINUTE]) || (changed[LOG_HOUR])) changed[LOG_MINUTE] = TRUE; log_updatelast (tm); #ifndef HAVE_LOCALTIME_R os_mutex_unlock (&localtime_lock); #endif for (i = 0; i < LOG_MAX; i++) { if (changed[i]) { if (logAddrFilename[i]) log_outputLog (&logAddr[i], logAddrFilename[i]); if (logUserFilename[i]) log_outputLog (&logUser[i], logUserFilename[i]); } } os_mutex_unlock (&lastlog_lock); return TRUE; }
static BOOL connection_real_log (conn_t * conn) { char *strSourceAddr; char *strDestAddr; char *strUser; time_t now; char strTime[100]; #ifdef HAVE_LOCALTIME_R struct tm realtm; #endif struct tm *tm; time (&now); #ifdef HAVE_LOCALTIME_R tm = localtime_r (&now, &realtm); #else os_mutex_lock (&localtime_lock); tm = localtime (&now); #endif strftime (strTime, sizeof (strTime), "%a, %d %b %Y %H:%M:%S", tm); #ifndef HAVE_LOCALTIME_R os_mutex_unlock (&localtime_lock); #endif os_mutex_lock (&connection_filelock); if (logfile) { strSourceAddr = ai_getString (&conn->source); strDestAddr = ai_getString (&conn->dest); strUser = conn->user; if (strUser) { fprintf (logfile, "%s %s %s %s\n", strTime, strSourceAddr, strDestAddr, strUser); } else { fprintf (logfile, "%s %s %s\n", strTime, strSourceAddr, strDestAddr); } os_mutex_unlock (&connection_filelock); free (strSourceAddr); free (strDestAddr); return TRUE; } else { os_mutex_unlock (&connection_filelock); return FALSE; } }
void* dcc_can_thread(void*) { PacketBase pkt(15); while(1) { struct can_frame frame; ssize_t ret = read(mostacan_fd, &frame, sizeof(frame)); ASSERT(ret == sizeof(frame)); if (IS_CAN_FRAME_ERR(frame)) continue; if (IS_CAN_FRAME_RTR(frame)) continue; // We reconstruct an MCP2515-compatible packet from what was received. can_frame_to_mcp_buffer(frame, pkt.buf()); os_mutex_lock(&dcc_mutex); can_destination = DST_CAN_INCOMING; MoStaMaster_HandlePacket(pkt); DccLoop_HandlePacket(pkt); DccLoop_ProcessIO(); DccLoop_ProcessIO(); bool send_to_host = can_destination & CDST_HOST; ASSERT(can_pending == 0); os_mutex_unlock(&dcc_mutex); if (send_to_host) { PacketQueue::instance()->TransmitConstPacket(pkt.buf()); } } return NULL; }
unsigned int ZION_CALLBACK log_thread(void* arg) { LOG_CTX* ctx = (LOG_CTX*)arg; unsigned int msglen = ctx->stream.len; char buf[1000]; int level = 0; for(;;) { os_sem_wait(&ctx->stream.inque); os_mutex_lock(&ctx->stream.mtx); if(ctx->stream.inque_size==0) { os_mutex_unlock(&ctx->stream.mtx); break; } stream_read(ctx, (char*)&msglen, (unsigned int)sizeof(msglen)); stream_read(ctx, buf, msglen); buf[msglen] = '\0'; if(ctx->stream.ouque_size>0) { ctx->stream.ouque_size--; os_sem_post(&ctx->stream.ouque); } ctx->stream.inque_size--; os_mutex_unlock(&ctx->stream.mtx); map[ctx->type].func_write(ctx, level, buf, msglen); } return 0; }
void config_dereference (config_t * conf) { #ifdef WITH_DEBUG char szDebug[300]; #endif os_mutex_lock (&conf->lock); conf->refcount--; if (conf->refcount == 0) { config_free (conf); os_mutex_unlock (&conf->lock); /* Ok, this happens outside the lock. But we know * nothing is using it, so it can't hurt. */ os_mutex_close (&conf->lock); free (conf); #ifdef WITH_DEBUG sprintf (szDebug, "Last reference to config %p, now destroyed", (void *) conf); DEBUG_LOG (szDebug); #endif } else { os_mutex_unlock (&conf->lock); } }
/* * ARGS * paddr protocol address * * RETURN * pointer to haddr or NULL if entry not found */ uint8* arp_get_haddr(uint32 paddr) { int i; uint8* ret; os_mutex_lock(&net.mutex, NET_MUTEX_MASK_ARP, OS_FLAG_NONE, OS_WAIT_FOREVER); DEBUGARP_STR("arp cache, lookup entry "); DEBUGARP_HEX(&paddr, 4); DEBUGARP_STR("\r\n"); ret = NULL; for (i = 0; i < ARP_CACHE_SIZE; i++) { DEBUGARP_STR(" entry "); DEBUGARP_HEX(&cache.data[i].paddr, 4); DEBUGARP_STR(", "); DEBUGARP_HEX(&cache.data[i].haddr, HADDR_LEN); DEBUGARP_STR("\r\n"); if (cache.data[i].paddr == paddr) { DEBUGARP_STR(" found\r\n"); ret = cache.data[i].haddr; goto out; } } out: os_mutex_unlock(&net.mutex, NET_MUTEX_MASK_ARP); return ret; }
void config_reference (config_t * conf) { os_mutex_lock (&conf->lock); conf->refcount++; os_mutex_unlock (&conf->lock); }
/****************************************************************************** * Function: jpeg_queue_abort * Description: Aborts the queue object * Input parameters: * p_queue - The pointer to queue object to be aborted. * Return values: * JPEGERR_SUCCESS * JPEGERR_ENULLPTR * Notes: none *****************************************************************************/ int jpeg_queue_abort(jpeg_queue_t *p_queue) { jpeg_q_t *p_q; if(!p_queue) { JPEG_DBG_ERROR("jpeg_queue_abort: failed with empty queue pointer\n"); return JPEGERR_ENULLPTR; } p_q = (jpeg_q_t *)(*p_queue); if (!p_q) { JPEG_DBG_ERROR("jpeg_queue_abort: failed with empty queue\n"); return JPEGERR_ENULLPTR; } // Abort os_mutex_lock(&(p_q->mutex)); if (p_q->state == QUEUE_STATE_TIMEWAIT) { // Change queue state p_q->state = QUEUE_STATE_ABORT; // Signal the dequeue function os_cond_signal(&(p_q->get_cond)); while (QUEUE_STATE_ABORT == p_q->state) { // Wait unitil abort can be unblocked os_cond_wait(&(p_q->abort_cond), &(p_q->mutex)); } } p_q->state = QUEUE_STATE_ABORTED; os_mutex_unlock(&(p_q->mutex)); return JPEGERR_SUCCESS; }
/****************************************************************************** * Function: jpeg_queue_reset * Description: Resets the queue object * Input parameters: * queue - The queue object to be reset. * Return values: * JPEGERR_SUCCESS * JPEGERR_ENULLPTR * Notes: none *****************************************************************************/ int jpeg_queue_reset(jpeg_queue_t queue) { jpeg_q_t *p_q = (jpeg_q_t *)queue; int rc = JPEGERR_SUCCESS; if (!p_q) { JPEG_DBG_ERROR("jpeg_queue_reset: failed with empty queue pointer\n"); return JPEGERR_ENULLPTR; } // Abort previous queue rc = jpeg_queue_abort(&queue); if (JPEG_FAILED(rc)) { JPEG_DBG_ERROR("jpeg_queue_reset: jpeg_queue_abort failed \n"); return rc; } os_mutex_lock(&(p_q->mutex)); // Initialize queue head, tail and counts all to zero p_q->queue_head = 0; p_q->queue_tail = 0; p_q->queue_cnt = 0; (void)STD_MEMSET(&(p_q->queue_pool), 0, sizeof(jpeg_queue_pool_t)); p_q->state = QUEUE_STATE_IDLE; os_mutex_unlock(&(p_q->mutex)); return JPEGERR_SUCCESS; }
int log_puts(LOG_HANDLE ctx, int level, const char* msg, unsigned int msglen) { if(msglen==0) msglen = (unsigned int)strlen(msg); if(ctx->stream.buf==NULL) return map[ctx->type].func_write(ctx, level, msg, msglen); for(;;) { os_mutex_lock(&ctx->stream.mtx); if(ctx->stream.len+sizeof(msglen)+msglen <= ctx->stream.max) break; ctx->stream.ouque_size++; os_mutex_unlock(&ctx->stream.mtx); os_sem_wait(&ctx->stream.ouque); } stream_write(ctx, (char*)&msglen, (unsigned int)sizeof(msglen)); stream_write(ctx, msg, msglen); ctx->stream.inque_size++; if(ctx->stream.ouque_size>0) { ctx->stream.ouque_size--; os_sem_post(&ctx->stream.ouque); } os_sem_post(&ctx->stream.inque); os_mutex_unlock(&ctx->stream.mtx); get_level_string(level); return ERR_NOERROR; }
static void * test_worker(void *arg) { /* check before pool is closed, then let main continue */ UT_ASSERTne(obj_direct(thread_oid), NULL); os_mutex_lock(&lock1); cond1 = 1; os_cond_signal(&sync_cond1); os_mutex_unlock(&lock1); /* wait for main thread to free & close, then check */ os_mutex_lock(&lock2); while (!cond2) os_cond_wait(&sync_cond2, &lock2); os_mutex_unlock(&lock2); UT_ASSERTeq(obj_direct(thread_oid), NULL); return NULL; }
static long long dcc_timer_callback(void*, void*) { os_mutex_lock(&dcc_mutex); DccLoop_Timer(); MoStaMaster_Timer(); DccLoop_ProcessIO(); DccLoop_ProcessIO(); os_mutex_unlock(&dcc_mutex); return OS_TIMER_RESTART; //SEC_TO_NSEC(1); }
int fdwatch_remove(FDWATCH_HANDLE handle, FDWATCH_ITEM* item) { assert(handle && handle->inuse); if(handle==NULL || (!handle->inuse)) return ERR_INVALID_HANDLE; os_mutex_lock(&handle->list_mtx); rlist_remove(&handle->enable_list, &item->item); os_mutex_unlock(&handle->list_mtx); return ERR_NOERROR; }
static void update_invrgn_by_rect(crgn_info_t *p_invrgn, BOOL is_add, const rect_t *p_rc, const rect_t *p_client_rect) { rect_t temp_rect; MT_ASSERT(p_invrgn != NULL && p_client_rect != NULL); #ifdef MUTI_THREAD_SUPPORT os_mutex_lock(p_invrgn->lock); #endif if(p_rc != NULL) { temp_rect = *p_rc; normalize_rect(&temp_rect); if(is_rect_covered(p_client_rect, &temp_rect)) { if(is_add) { gdi_set_cliprgn(&p_invrgn->crgn, p_client_rect); } else { gdi_empty_cliprgn(&p_invrgn->crgn); } } else if(intersect_rect(&temp_rect, &temp_rect, p_client_rect)) { if(is_add) { gdi_add_cliprect(&p_invrgn->crgn, &temp_rect); } else { gdi_subtract_cliprect(&p_invrgn->crgn, &temp_rect); } } } else { if(is_add) { gdi_set_cliprgn(&p_invrgn->crgn, p_client_rect); } else { gdi_empty_cliprgn(&p_invrgn->crgn); } } #ifdef MUTI_THREAD_SUPPORT os_mutex_unlock(p_invrgn->lock); #endif }
static void room_timer_proc(TIMER handle, void* key) { int idx; os_mutex_lock(&room_mtx); cur_time ++; for(idx=0; idx<sizeof(room_list)/sizeof(room_list[0]); idx++) { if(room_list[idx]==NULL) continue; cube_room_tick(room_list[idx]); } os_mutex_unlock(&room_mtx); }
void ctrl_empty_invrgn(control_t *p_ctrl) { MT_ASSERT(p_ctrl != NULL); #ifdef MUTI_THREAD_SUPPORT os_mutex_lock(p_ctrl->invrgn_info.lock); #endif gdi_empty_cliprgn(&p_ctrl->invrgn_info.crgn); #ifdef MUTI_THREAD_SUPPORT os_mutex_unlock(p_ctrl->invrgn_info.lock); #endif }
Gui::Gui(GenesisContext *context, ResourceBundle *resource_bundle) : _running(true), _focus_window(nullptr), _utility_window(create_utility_window()), _resource_bundle(resource_bundle), _spritesheet(this, "spritesheet"), img_entry_dir(_spritesheet.get_image_info("font-awesome/folder.png")), img_entry_dir_open(_spritesheet.get_image_info("font-awesome/folder-open.png")), img_entry_file(_spritesheet.get_image_info("font-awesome/file.png")), img_plus(_spritesheet.get_image_info("font-awesome/plus-square.png")), img_minus(_spritesheet.get_image_info("font-awesome/minus-square.png")), img_microphone(_spritesheet.get_image_info("font-awesome/microphone.png")), img_volume_up(_spritesheet.get_image_info("font-awesome/volume-up.png")), img_check(_spritesheet.get_image_info("font-awesome/check.png")), img_caret_right(_spritesheet.get_image_info("font-awesome/caret-right.png")), img_caret_down(_spritesheet.get_image_info("font-awesome/caret-down.png")), img_arrow_up(_spritesheet.get_image_info("font-awesome/arrow-up.png")), img_arrow_down(_spritesheet.get_image_info("font-awesome/arrow-down.png")), img_arrow_left(_spritesheet.get_image_info("font-awesome/arrow-left.png")), img_arrow_right(_spritesheet.get_image_info("font-awesome/arrow-right.png")), img_music(_spritesheet.get_image_info("font-awesome/music.png")), img_plug(_spritesheet.get_image_info("font-awesome/plug.png")), img_exclamation_circle(_spritesheet.get_image_info("font-awesome/exclamation-circle.png")), img_null(_spritesheet.get_image_info("img/null.png")), img_play_head(_spritesheet.get_image_info("img/play_head.png")), _genesis_context(context), dragging(false), drag_data(nullptr), drag_window(nullptr) { ft_ok(FT_Init_FreeType(&_ft_library)); _resource_bundle->get_file_buffer("font.ttf", _default_font_buffer); ft_ok(FT_New_Memory_Face(_ft_library, (FT_Byte*)_default_font_buffer.raw(), _default_font_buffer.length(), 0, &_default_font_face)); cursor_default = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); cursor_ibeam = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); cursor_hresize = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR); cursor_vresize = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); genesis_set_audio_device_callback(_genesis_context, audio_device_callback, this); genesis_set_midi_device_callback(_genesis_context, midi_device_callback, this); genesis_set_sound_backend_disconnect_callback(_genesis_context, sound_backend_disconnect_callback, this); genesis_flush_events(_genesis_context); genesis_refresh_midi_devices(_genesis_context); gui_mutex = ok_mem(os_mutex_create()); os_mutex_lock(gui_mutex); }
void Gui::exec() { os_mutex_unlock(gui_mutex); fps = 60.0; double last_time = os_get_time(); while (_running) { os_mutex_lock(gui_mutex); genesis_flush_events(_genesis_context); glfwPollEvents(); events.trigger(EventFlushEvents); os_mutex_unlock(gui_mutex); _utility_window->draw(); double this_time = os_get_time(); double delta = this_time - last_time; last_time = this_time; double this_fps = 1.0 / delta; fps = fps * 0.90 + this_fps * 0.10; } os_mutex_lock(gui_mutex); }
/****************************************************************************** * Function: jpege_queue_enqueue * Description: Enqueue a sequence of entry. It accepts the double pointer to the * entry to be enqueued and the number of entries in the * array, appends the entries sequentially to the tail of queue. * The number of entries to be enqueued is checked against * the valid slots of the queue, and * return fail if it is larger than the valid size. * Input parameters: * queue - The queue object. * pp_enqueue_buf - The double pointer to enqueued entry(s) . * enqueue_entry_cnt - The number of enqueued entry(s). * Return values: * JPEGERR_SUCCESS * JPEGERR_EFAILED * JPEGERR_ENULLPTR * (See jpegerr.h for description of error values.) * Notes: none *****************************************************************************/ int jpeg_queue_enqueue( jpeg_queue_t queue, void **pp_enqueue_entry, uint32_t enqueue_entry_cnt) { uint32_t i, q_index; jpeg_q_t *p_q; // Input parameter validation if ((!pp_enqueue_entry) || (!enqueue_entry_cnt)) { JPEG_DBG_ERROR("jpeg_queue_enqueue: failed with input parameter check\n"); return JPEGERR_EBADPARM; } p_q = (jpeg_q_t *)queue; if (!p_q) { JPEG_DBG_ERROR("jpeg_queue_enqueue: failed with empty queue pointer\n"); return JPEGERR_ENULLPTR; } // Enqueue entry(s) to the queue os_mutex_lock(&(p_q->mutex)); // Reject if the enqueued entry(s) are greater than valid slots left: // queue_cnt is current number of entries in queue, // it plus the number of entry to be enqueued can not exceed the // number of entries allowed inside queue. if ((p_q->queue_cnt + enqueue_entry_cnt) > MAX_QUEUE_NUM) { JPEG_DBG_ERROR("jpeg_queue_enqueue: enqueuing more entries than valid queue slots\n"); os_mutex_unlock(&(p_q->mutex)); return JPEGERR_EFAILED; } // Enqueue the entry for (i = 0; i < enqueue_entry_cnt; i++) { // Appends the entries sequentially to the tail of queue. q_index = QUEUE_MOD(p_q->queue_tail + i); p_q->queue_pool[q_index].p_data = *(pp_enqueue_entry + i); } // Update the tail of queue and entries number p_q->queue_tail = QUEUE_MOD(p_q->queue_tail + enqueue_entry_cnt); p_q->queue_cnt += enqueue_entry_cnt; // Signal that enqueuing entries is done os_cond_signal(&(p_q->get_cond)); os_mutex_unlock(&(p_q->mutex)); return JPEGERR_SUCCESS; }
bool debug_alloc_get_serial(U64 serial, Debug_Alloc_Header *out) { os_mutex_lock(&g_debug_memory.lock); Debug_Alloc_Header *header = unsafe_debug_alloc_get_serial(serial); if (header) { *out = *header; } os_mutex_unlock(&g_debug_memory.lock); return header != 0; }
void *debug_allocate(size_t size, const char *type, size_t type_size, Source_Loc loc) { Debug_Alloc_Header *header_and_data = (Debug_Alloc_Header*) malloc(sizeof(Debug_Alloc_Header) + size); if (!header_and_data) return 0; header_and_data->magic = DEBUG_ALLOC_HEADER_MAGIC; header_and_data->state = DEBUG_ALLOC_ALLOCATED_STATE; header_and_data->type = type; header_and_data->type_size = type_size; header_and_data->size = size; header_and_data->alloc_loc = loc; header_and_data->free_loc.file = 0; header_and_data->free_loc.line = 0; header_and_data->free_trace_length = 0; header_and_data->thread_id = os_current_thread_id(); header_and_data->prev_serial = 0; header_and_data->next_serial = 0; header_and_data->alloc_trace_length = os_capture_stack_trace( header_and_data->alloc_trace, Count(header_and_data->alloc_trace)); os_mutex_lock(&g_debug_memory.lock); header_and_data->serial = ++g_debug_memory.serial; header_and_data->prev = &g_debug_memory.root; header_and_data->next = g_debug_memory.root.next; if (g_debug_memory.root.next) g_debug_memory.root.next->prev = header_and_data; g_debug_memory.root.next = header_and_data; if (g_debug_memory.log) { g_debug_memory.log_index = (g_debug_memory.log_index + 1) % g_debug_memory.log_size; g_debug_memory.log[g_debug_memory.log_index] = *header_and_data; } #ifdef BREAK_AT_SERIAL if (header_and_data->serial == BREAK_AT_SERIAL) os_debug_break(); #endif os_mutex_unlock(&g_debug_memory.lock); return header_and_data + 1; }
static void run_write(void *userdata) { OrderedMapFile *omf = (OrderedMapFile *)userdata; for (;;) { OrderedMapFileBatch *batch = nullptr; omf->queue.shift(&batch); if (!batch || !omf->running) break; // compute transaction size int transaction_size = get_transaction_size(batch); omf->write_buffer.resize(transaction_size); uint8_t *transaction_ptr = (uint8_t*)omf->write_buffer.raw(); write_uint32be(&transaction_ptr[4], transaction_size); write_uint32be(&transaction_ptr[8], batch->puts.length()); write_uint32be(&transaction_ptr[12], batch->dels.length()); int offset = TRANSACTION_METADATA_SIZE; for (int i = 0; i < batch->puts.length(); i += 1) { OrderedMapFilePut *put = &batch->puts.at(i); write_uint32be(&transaction_ptr[offset], put->key->size); offset += 4; write_uint32be(&transaction_ptr[offset], put->value->size); offset += 4; memcpy(&transaction_ptr[offset], put->key->data, put->key->size); offset += put->key->size; memcpy(&transaction_ptr[offset], put->value->data, put->value->size); offset += put->value->size; } for (int i = 0; i < batch->dels.length(); i += 1) { OrderedMapFileDel *del = &batch->dels.at(i); write_uint32be(&transaction_ptr[offset], del->key->size); offset += 4; memcpy(&transaction_ptr[offset], del->key->data, del->key->size); offset += del->key->size; } assert(offset == transaction_size); ordered_map_file_batch_destroy(batch); // compute crc32 write_uint32be(&transaction_ptr[0], crc32(0, &transaction_ptr[4], transaction_size - 4)); // append to file size_t amt_written = fwrite(transaction_ptr, 1, transaction_size, omf->file); if (amt_written != (size_t)transaction_size) panic("write to disk failed"); os_mutex_lock(omf->mutex); os_cond_signal(omf->cond, omf->mutex); os_mutex_unlock(omf->mutex); } }
static void ondisconnect(NETWORK_HANDLE handle, void* userptr) { CUBE_CONNECTION* conn; CUBE_ROOM* room; conn = (CUBE_CONNECTION*)userptr; os_mutex_lock(&room_mtx); if(conn->room!=NULL) { room = conn->room; cube_room_leave(room, conn, 0); } os_mutex_unlock(&room_mtx); network_del(handle); mempool_free(conn_pool, conn); }
void ctrl_init_invrgn(control_t *p_ctrl) { rect_t rc; MT_ASSERT(p_ctrl != NULL); #ifdef MUTI_THREAD_SUPPORT os_mutex_lock(p_ctrl->invrgn_info.lock); #endif gdi_init_cliprgn(&p_ctrl->invrgn_info.crgn, gdi_get_cliprc_heap()); ctrl_get_client_rect(p_ctrl, &rc); gdi_set_cliprgn(&p_ctrl->invrgn_info.crgn, &rc); #ifdef MUTI_THREAD_SUPPORT os_mutex_unlock(p_ctrl->invrgn_info.lock); #endif }
/* * fill entry in ARP cache * * NOTE entries values are stored in big endian format * */ void arp_fill_cache(uint8 *haddr, uint32 paddr) { int i; uint8 bcast[HADDR_LEN]; os_mutex_lock(&net.mutex, NET_MUTEX_MASK_ARP, OS_FLAG_NONE, OS_WAIT_FOREVER); /* exclude broadcast message */ memset(&bcast, 0xff, HADDR_LEN); if (arp_haddr_match(haddr, bcast)) goto out; /* NOTE exclude self */ if (paddr == net_info.paddr) goto out; for (i = 0; i < ARP_CACHE_SIZE; i++) { /* if entry was found update it */ if (cache.data[i].paddr == paddr) { DEBUGARP_STR("arp cache, entry found "); DEBUGARP_HEX(haddr, HADDR_LEN); DEBUGARP_STR(", "); DEBUGARP_HEX(&paddr, 4); DEBUGARP_STR("\r\n"); memcpy(cache.data[i].haddr, haddr, HADDR_LEN); goto out; } } /* entry not found */ if (i == ARP_CACHE_SIZE) { DEBUGARP_STR("arp cache, new entry "); DEBUGARP_HEX(haddr, HADDR_LEN); DEBUGARP_STR(", "); DEBUGARP_HEX(&paddr, 4); DEBUGARP_STR("\r\n"); cache.data[cache.fp].paddr = paddr; memcpy(cache.data[cache.fp].haddr, haddr, HADDR_LEN); cache.fp++; if (cache.fp >= ARP_CACHE_SIZE) cache.fp = 0; } out: os_mutex_unlock(&net.mutex, NET_MUTEX_MASK_ARP); }
enum CORE_bool_e os_circular_buffer_push_back(struct os_circular_buffer_t *buffer_, uint8_t element_) { os_mutex_lock(); if(buffer_ && !(((buffer_->end + 1) & CORE_config(os_circular_buffer, mask)) == buffer_->home)) { buffer_->data[buffer_->end] = element_; ++buffer_->end; buffer_->end &= CORE_config(os_circular_buffer, mask); os_mutex_unlock(); return CORE_bool_true; } os_mutex_unlock(); return CORE_bool_false; }
uint8_t os_circular_buffer_pop_front(struct os_circular_buffer_t *buffer_) { os_mutex_lock(); if(buffer_ && !(buffer_->end == buffer_->home)) { uint8_t element = buffer_->data[buffer_->home]; ++buffer_->home; buffer_->home &= CORE_config(os_circular_buffer, mask); os_mutex_unlock(); return element; } os_mutex_unlock(); return 0; }
static int __set_attribute(const char *uuid, const char *attr_name, char *attr_value) { int ret = SERVICE_RESULT_ERR; const char *mac = NULL; attr_hanler_ptr attr_handler = NULL; log_trace("uuid = %s, attr_name = %s, attr_value = %s", uuid, attr_name, attr_value); device_helper_ptr helper = NULL; helper = msdp_get_helper(uuid); PTR_RETURN(helper, ret, "no exist model helper, uuid = %s", uuid) os_mutex_lock(helper->mutex_lock); attr_handler = msdp_get_attr_handler(helper, attr_name); if (attr_handler) { log_trace("Exist attribute(%s) handler on devtype:%02x", attr_name, helper->dev_type); if (helper->dev_type == DEV_TYPE_GATEWAY) { PTR_GOTO((attr_handler)->set_cb, unlock_out, "attribute %s's get_cb is NULL", attr_name); ret = ((set_attr_cb)attr_handler->set_cb)(attr_value); log_trace("set attibute \"%s\" handler ret = %d", attr_name, ret); } else { // modify by wukong 2017-4-17 char mac[ETHER_ADDR_BYTES] = {0}; get_mac_by_uuid(uuid, mac); //modify by wukong end 2017-4-17 PTR_GOTO((attr_handler->set_cb), unlock_out, "subdevice attribute %s's set_cb is NULL", attr_name); ret = ((set_subdev_attr_cb)attr_handler->set_cb)(mac, attr_value); log_trace("set attibute \"%s\" handler ret = %d\n", attr_name, ret); } } else { log_error("unsupport attribute \"%s\"", attr_name); } unlock_out: os_mutex_unlock((helper->mutex_lock)); return ret; }
static void onaccept(void* userptr, SOCK_HANDLE sock, const SOCK_ADDR* pname) { int idx; CUBE_CONNECTION* conn; NETWORK_EVENT event; os_mutex_lock(&room_mtx); for(idx=0; idx<sizeof(conn_list)/sizeof(conn_list[0]); idx++) { if(conn_list[idx]==NULL) break; } if(idx==sizeof(conn_list)/sizeof(conn_list[0])) { sock_close(sock); os_mutex_unlock(&room_mtx); return; } conn = (CUBE_CONNECTION*)mempool_alloc(conn_pool); if(conn==NULL) { sock_close(sock); os_mutex_unlock(&room_mtx); return; } event.OnConnect = onconnect; event.OnData = ondata; event.OnDisconnect = ondisconnect; event.recvbuf_buf = conn->recv_buf; event.recvbuf_max = sizeof(conn->recv_buf); event.recvbuf_pool = NULL; memset(conn, 0, sizeof(*conn)); conn->index = idx; conn_list[idx] = conn; conn->handle = network_add(sock, &event, conn); if(!conn->handle) { mempool_free(conn_pool, conn); sock_close(sock); os_mutex_unlock(&room_mtx); return; } os_mutex_unlock(&room_mtx); }