• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ semaphore_P函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中semaphore_P函数的典型用法代码示例。如果您正苦于以下问题:C++ semaphore_P函数的具体用法?C++ semaphore_P怎么用?C++ semaphore_P使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了semaphore_P函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: minithread_yield

void
minithread_yield() {
  //put current thread at end of runnable
  semaphore_P(runnable_q_lock);
  current_thread->priority = 0;
  current_thread->rem_quanta = 1;

  if (multilevel_queue_enqueue(runnable_q,
      current_thread->priority,current_thread) == 0) {
    runnable_count++;
  }
  semaphore_V(runnable_q_lock);
  //call scheduler here
  scheduler();
}
开发者ID:kentalabur,项目名称:egs,代码行数:15,代码来源:minithread.c


示例2: vfs_deinit

/**
 * Force unmount on all filesystems. This function should be used only
 * when halting the system. Waits for all VFS operations to complete
 * but does not wait for all files to be closed. After this function
 * is called the VFS and the whole operating system can no longer be
 * used.
 */
void vfs_deinit(void)
{
  fs_t *fs;
  int row;

  semaphore_P(vfs_op_sem);
  vfs_usable = 0;

  kprintf("VFS: Entering forceful unmount of all filesystems.\n");
  if (vfs_ops > 0) {
    kprintf("VFS: Delaying force unmount until the pending %d "
            "operations are done.\n", vfs_ops);
    semaphore_V(vfs_op_sem);
    semaphore_P(vfs_unmount_sem);
    semaphore_P(vfs_op_sem);
    KERNEL_ASSERT(vfs_ops == 0);
    kprintf("VFS: Continuing forceful unmount.\n");
  }

  semaphore_P(vfs_table.sem);
  semaphore_P(openfile_table.sem);

  for (row = 0; row < CONFIG_MAX_FILESYSTEMS; row++) {
    fs = vfs_table.filesystems[row].filesystem;
    if (fs != NULL) {
      kprintf("VFS: Forcefully unmounting volume [%s]\n",
              vfs_table.filesystems[row].mountpoint);
      fs->unmount(fs);
      vfs_table.filesystems[row].filesystem = NULL;
    }
  }

  semaphore_V(openfile_table.sem);
  semaphore_V(vfs_table.sem);
  semaphore_V(vfs_op_sem);
}
开发者ID:PtxDK,项目名称:OSM,代码行数:43,代码来源:vfs.c


示例3: reaper_queue_cleanup

/* Deletes all the elements in the cleanup_queue and then get the next
 * RUNNABLE minithread, if it exists. Otherwise, it will continuously poll the
 * queue and wait until another thread is made RUNNABLE */
int reaper_queue_cleanup(arg_t arg) {
  //delete all zombie minithreads in cleanup_queue
  minithread_t* temp;
  while (1) {
    semaphore_P(reaper_sema); //waits until something is ready to be deleted
    if (queue_length(schedule_data->cleanup_queue) > 0) { //double checks size
      interrupt_level_t old_level = set_interrupt_level(DISABLED); 
      queue_dequeue(schedule_data->cleanup_queue, (void **) &temp);
      free(temp);
      set_interrupt_level(old_level);
    }
  }
  // will never return
  return 0;
}
开发者ID:AlexSommer,项目名称:minithreads,代码行数:18,代码来源:minithread.c


示例4: employee

static int
employee(int* arg) {
    phone_t new_phone = NULL;
    int id = employee_id++;

    while (1) {
        /* Check if there is any customer in need of a phone */
        semaphore_P(customer_sem);

        /* Wait if buffer full */
        semaphore_P(empty_sem);
        new_phone = phone_create();
        if (NULL != new_phone) {
            queue_append(phone_queue, new_phone);
            printf("Employee %d unpacked phone %d\n", id, new_phone->serial_num);
        }
        /* Signal a phone is ready */
        semaphore_V(full_sem);

        /* minithread_yield(); */
    }

    return 0;
}
开发者ID:DolphinWilly,项目名称:PortOSnix,代码行数:24,代码来源:retail_shop_1.c


示例5: source

/* produce all integers from 2 to max */
int source(int* arg) {
    channel_t* c = (channel_t *) arg;
    int i;

    for (i=2; i<=max; i++) {
        c->value = i;
        semaphore_V(c->consume);
        semaphore_P(c->produce);
    }

    c->value = -1;
    semaphore_V(c->consume);

    return 0;
}
开发者ID:Amanjot1507,项目名称:OS-Work,代码行数:16,代码来源:sieve.c


示例6: minisocket_free

static void minisocket_free (minisocket_t * socket) {
  network_interrupt_arg_t *packet = NULL;
  while (queue_dequeue(socket->data, (void **)&packet) != -1) {
    free(packet);
  }
  queue_free(socket->data);
  socket->data = NULL;
  semaphore_destroy(socket->data_ready);
  semaphore_destroy(socket->wait_for_ack);
  semaphore_destroy(socket->send_receive_mutex);
  semaphore_P(ports_mutex);
  ports[socket->local_port] = NULL;
  semaphore_V(ports_mutex);
  free(socket);
}
开发者ID:Amanjot1507,项目名称:OS-Work,代码行数:15,代码来源:minisocket.c


示例7: sched_request_task

// returns new task id
uint32_t sched_request_task(task_type type, std::shared_ptr<void> data)
{
	uint32_t task_id;
	std::unique_ptr<new_task_req> request(new new_task_req);

	request->tcp = data;
	request->type = type;
	request->task_id = task_counter++;
	task_id = request->task_id;
	
	semaphore_P(sched_new_task_lock, 1);
	new_task_queue.push_back(std::move(request));
	semaphore_V(sched_new_task_lock, 1);

	return task_id;
}
开发者ID:qwertzdenek,项目名称:os-project,代码行数:17,代码来源:scheduler.cpp


示例8: vfs_start_op

/**
 * Start a new operation on VFS. Operation is defined to be any such
 * sequence of actions (a VFS function call) that may touch some
 * filesystem.
 *
 * @return VFS_OK if operation can continue, error (negative) if
 * operation must be cancelled.
 */
static int vfs_start_op()
{
    int ret = VFS_OK;

    semaphore_P(vfs_op_sem);

    if (vfs_usable) {
        vfs_ops++;
    } else {
        ret = VFS_UNUSABLE;
    }

    semaphore_V(vfs_op_sem);

    return ret;
}
开发者ID:Rotte,项目名称:osm-k,代码行数:24,代码来源:vfs.c


示例9: miniport_create_unbound

/* Creates an unbound port for listening. Multiple requests to create the same
 * unbound port should return the same miniport reference. It is the responsibility
 * of the programmer to make sure he does not destroy unbound miniports while they
 * are still in use by other threads -- this would result in undefined behavior.
 * Unbound ports must range from 0 to 32767. If the programmer specifies a port number
 * outside this range, it is considered an error.
 */
miniport_t
miniport_create_unbound(int port_number) {
  miniport_t new_port;

  if (port_number < 0 || port_number >= BOUND_PORT_START) {
    // user error
    return NULL;
  }
  if (miniport_array[port_number]) {
    return miniport_array[port_number];
  }
  semaphore_P(unbound_ports_lock);
  new_port = (miniport_t)malloc(sizeof(struct miniport)); 
  if (new_port == NULL) {
    semaphore_V(unbound_ports_lock);
    return NULL;
  }
  new_port->p_type = UNBOUND_PORT;
  new_port->p_num = port_number;
  new_port->u.unbound.port_pkt_q = queue_new();
  if (!new_port->u.unbound.port_pkt_q) {
    free(new_port);
    semaphore_V(unbound_ports_lock);
    return NULL;
  }
  new_port->u.unbound.port_pkt_available_sem = semaphore_create();
  if (!new_port->u.unbound.port_pkt_available_sem) {
    queue_free(new_port->u.unbound.port_pkt_q);
    free(new_port);
    semaphore_V(unbound_ports_lock);
    return NULL;
  } 
  new_port->u.unbound.q_lock = semaphore_create();
  if (!new_port->u.unbound.q_lock) {
    queue_free(new_port->u.unbound.port_pkt_q);
    semaphore_destroy(new_port->u.unbound.port_pkt_available_sem);
    free(new_port);
    semaphore_V(unbound_ports_lock);
    return NULL;
  }
  semaphore_initialize(new_port->u.unbound.port_pkt_available_sem,0);
  semaphore_initialize(new_port->u.unbound.q_lock,1);
  miniport_array[port_number] = new_port;
  semaphore_V(unbound_ports_lock);
  return new_port;
   
}
开发者ID:kentalabur,项目名称:egs,代码行数:54,代码来源:minimsg.c


示例10: ctl_program

static void ctl_program(int ch, int val)
{
        if(ch >= MAX_TK_MIDI_CHANNELS)
		return;
	if (!ctl.trace_playing)
		return;
	if (ch < 0 || ch >= MAX_TK_MIDI_CHANNELS) return;
	if(channel[ch].special_sample)
	    val = channel[ch].special_sample;
	else
	    val += progbase;

	semaphore_P(semid);
	Panel->channel[ch].program = val;
	Panel->c_flags[ch] |= FLAG_PROG;
	semaphore_V(semid);
}
开发者ID:avm,项目名称:timidity,代码行数:17,代码来源:tk_c.c


示例11: vfs_end_op

/**
 * End a VFS operation.
 */
static void vfs_end_op()
{
    semaphore_P(vfs_op_sem);

    vfs_ops--;

    KERNEL_ASSERT(vfs_ops >= 0);

    /* Wake up pending unmount if VFS is now idle. */
    if (!vfs_usable && (vfs_ops == 0))
        semaphore_V(vfs_unmount_sem);

    if (!vfs_usable && (vfs_ops > 0))
        kprintf("VFS: %d operations still pending\n", vfs_ops);

    semaphore_V(vfs_op_sem);
}
开发者ID:Rotte,项目名称:osm-k,代码行数:20,代码来源:vfs.c


示例12: vfs_seek

int vfs_seek(openfile_t file, int seek_position)
{
    openfile_entry_t *openfile;

    if (vfs_start_op() != VFS_OK)
        return VFS_UNUSABLE;

    KERNEL_ASSERT(seek_position >= 0);
    semaphore_P(openfile_table.sem);

    openfile = vfs_verify_open(file);
    openfile->seek_position = seek_position;

    semaphore_V(openfile_table.sem);

    vfs_end_op();
    return VFS_OK;
}
开发者ID:Rotte,项目名称:osm-k,代码行数:18,代码来源:vfs.c


示例13: miniroute_send_pkt

/* sends a miniroute packet, automatically discovering the path if necessary.
 * See description in the .h file.
 */
int
miniroute_send_pkt(network_address_t dest_address, int hdr_len, char* hdr,
                   int data_len, char* data)
{
    int total_len = hdr_len + data_len;
    int sent_len = 0;
    struct routing_header routing_hdr;
    char *total_data = malloc(total_len);
    miniroute_path_t path = NULL;

    /* Find route if it is not in cache */
    semaphore_P(discovery_mutex);
    miniroute_cache_get_by_addr(route_cache,  dest_address, (void**)&path);

    if (NULL == path || path->exp_time < ticks) {
#if MINIROUTE_CACHE_DEBUG == 1
        printf("Address not found, discovering path.\n");
#endif
        path = miniroute_discover_path(dest_address);
    }

    semaphore_V(discovery_mutex);
    if (NULL != path && NULL != (total_data = malloc(total_len))) {
        /* Pack data and miniroute header */
        memcpy(total_data, hdr, hdr_len);
        memcpy(total_data + hdr_len, data, data_len);

        miniroute_pack_data_hdr(&routing_hdr, path);
        sent_len = network_send_pkt(path->hop[1], MINIROUTE_HDRSIZE,
                                    (char*)&routing_hdr, total_len, total_data);
    }
#if MINIROUTE_DEBUG == 1
    printf("Network packet sent.\n");
#endif
#if MINIROUTE_CACHE_DEBUG == 1
    printf("Sending data with header: \n");
    miniroute_print_hdr(&routing_hdr);
#endif

    if (sent_len < hdr_len)
        return -1;
    else
        return sent_len - hdr_len;
}
开发者ID:DolphinWilly,项目名称:PortOSnix,代码行数:47,代码来源:miniroute.c


示例14: miniport_create_bound

/* Creates a bound port for use in sending packets. The two parameters, addr and
 * remote_unbound_port_number together specify the remote's listening endpoint.
 * This function should assign bound port numbers incrementally between the range
 * 32768 to 65535. Port numbers should not be reused even if they have been destroyed,
 * unless an overflow occurs (ie. going over the 65535 limit) in which case you should
 * wrap around to 32768 again, incrementally assigning port numbers that are not
 * currently in use.
 */
miniport_t
miniport_create_bound(network_address_t addr, int remote_unbound_port_number)
{
    int num;
    semaphore_P(port_mutex);
    num = miniport_get_boundedport_num();
    if (num < MIN_BOUNDED || num > MAX_BOUNDED) {
        semaphore_V(port_mutex);
        return NULL;
    }
    if ((port[num] = malloc(sizeof(struct miniport))) != NULL) {
        port[num]->type = BOUNDED;
        port[num]->num = num;
        network_address_copy(addr, port[num]->bound.addr);
        port[num]->bound.remote = remote_unbound_port_number;
    }
    semaphore_V(port_mutex);
    return port[num];
}
开发者ID:DolphinWilly,项目名称:PortOSnix,代码行数:27,代码来源:minimsg.c


示例15: sched_get_running_tasks

std::string sched_get_running_tasks()
{
	std::stringstream ss;

	semaphore_P(sched_lock, 1);
	for (int i = 0; i < CORE_COUNT; i++)
	{
		if (sched_active_task(i))
		{
			ss << i << "| ";
			ss << running_tasks[i]->task_id << ' ';
			ss << task_state_names[running_tasks[i]->state] << ' ';
			ss << task_type_names[running_tasks[i]->type] << '\n';
		}
	}
	semaphore_V(sched_lock, 1);

	return ss.str();
}
开发者ID:qwertzdenek,项目名称:os-project,代码行数:19,代码来源:scheduler.cpp


示例16: minisocket_destroy

void minisocket_destroy(minisocket_t sock, minisocket_error* error){
  network_interrupt_arg_t* pkt;

  semaphore_P(server_lock);
  sock_array[sock->src_port] = NULL;
  semaphore_V(server_lock);
  *error = SOCKET_NOERROR;
  //free all queued packets. interrupts not disabled
  //because socket in array set to null, network
  //handler cannot access queue
  while (queue_dequeue(sock->pkt_q,(void**)&pkt) != -1){
    free(pkt);
  }
  queue_free(sock->pkt_q);
  semaphore_destroy(sock->pkt_ready_sem);
  semaphore_destroy(sock->ack_ready_sem);
  semaphore_destroy(sock->sock_lock);
  free(sock);
}
开发者ID:kentalabur,项目名称:egs,代码行数:19,代码来源:minisocket.c


示例17: sched_get_cores_info

std::string sched_get_cores_info()
{
	std::stringstream ss;

	semaphore_P(sched_lock, 1);
	for (int i = 0; i < CORE_COUNT; i++)
	{
		if (sched_active_task(i))
		{
			ss << "core " << i << " occupied" << '\n';
		}
		else {
			ss << "core " << i << " free" << '\n';
		}
	}
	semaphore_V(sched_lock, 1);

	return ss.str();
}
开发者ID:qwertzdenek,项目名称:os-project,代码行数:19,代码来源:scheduler.cpp


示例18: main

int main()
{
    struct exchange
    {
        char buf[BUFSIZ+80];
        int seq;
    }shm;
    int shmid;
    unsigned char *retval;
    int producer, consumer, i;
    char readbuf[BUFSIZ];

    //创建信号量consumer
    consumer = open_semaphore_set(ftok("consumer", 0), 1);

    //初始化信号量consumer的值为1
    init_a_semaphore(consumer, 0, 1);

    //创建信号量producer
    producer = open_semaphore_set(ftok("producer", 0), 1);

    //初始化信号量producer的值为1
    init_a_semaphore(producer, 0, 1);

    //创建共享存储区用于存放生产者产生的数据
    shmid = shmget(ftok("share", 0),sizeof(struct exchange), 0666|IPC_CREAT);
    retval = shmat(shmid, (unsigned char *)0, 0);

    //生产者与消费者同步
    for (i = 0; ; i++)
    {
        printf("enter some text:");
        fgets(readbuf, BUFSIZ, stdin);
        semaphore_P(consumer);
        sprintf(retval, "messge %2d form producer %d is \" %s \" ", i, getpid(), readbuf);
        semaphore_V(producer);
        if (strncmp(readbuf, "end", 3) == 0)
            break;
    }
    exit(0);

    return 0;
}
开发者ID:AI-Ying,项目名称:Experiment,代码行数:43,代码来源:producer.c


示例19: miniport_destroy

/*
 * Destroys a miniport and frees up its resources. If the miniport was in use at
 * the time it was destroyed, subsequent behavior is undefined.
 */
void
miniport_destroy(miniport_t miniport)
{
    semaphore_P(port_mutex);
    if (NULL == miniport) {
        semaphore_V(port_mutex);
        return;
    }
    if (UNBOUNDED == miniport->type) {
        queue_free(miniport->unbound.data);
        semaphore_destroy(miniport->unbound.ready);
    }
    if (BOUNDED == miniport->type) {
        --bound_count;
    }
    port[miniport->num] = NULL;
    free(miniport);
    semaphore_V(port_mutex);
}
开发者ID:DolphinWilly,项目名称:PortOSnix,代码行数:23,代码来源:minimsg.c


示例20: vfs_mount

int vfs_mount(fs_t *fs, char *name)
{
    int i;
    int row;

    KERNEL_ASSERT(name != NULL && name[0] != '\0');

    if (vfs_start_op() != VFS_OK)
        return VFS_UNUSABLE;

    semaphore_P(vfs_table.sem);

    for (i = 0; i < CONFIG_MAX_FILESYSTEMS; i++) {
        if (vfs_table.filesystems[i].filesystem == NULL)
            break;
    }

    row = i;

    if(row >= CONFIG_MAX_FILESYSTEMS) {
        semaphore_V(vfs_table.sem);
        kprintf("VFS: Warning, maximum mount count exceeded, mount failed.\n");
        vfs_end_op();
        return VFS_LIMIT;
    }

    for (i = 0; i < CONFIG_MAX_FILESYSTEMS; i++) {
        if(stringcmp(vfs_table.filesystems[i].mountpoint, name) == 0) {
            semaphore_V(vfs_table.sem);
            kprintf("VFS: Warning, attempt to mount 2 filesystems "
                    "with same name\n");
            vfs_end_op();
            return VFS_ERROR;
        }
    }

    stringcopy(vfs_table.filesystems[row].mountpoint, name, VFS_NAME_LENGTH);
    vfs_table.filesystems[row].filesystem = fs;

    semaphore_V(vfs_table.sem);
    vfs_end_op();
    return VFS_OK;
}
开发者ID:Rotte,项目名称:osm-k,代码行数:43,代码来源:vfs.c



注:本文中的semaphore_P函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ semaphore_V函数代码示例发布时间:2022-05-30
下一篇:
C++ sema_up函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap