예제 #1
0
파일: alloc.c 프로젝트: fanyang01/sql
int free_blk(ALLOC * a, handle_t h, handle_t atoms)
{
	if (hdl2off(h + atoms) >= fsize(a->fd))
		return fshrink(a->fd, hdl2off(h));

	unsigned char buf[16];
	handle_t prev = 0, next;
	int idx;

	switch (atoms) {
	case 0:
		return -1;
	case 1:
		buf[0] = buf[15] = FRBLK_SINGLE;
		break;
	default:
		buf[0] = buf[15] = FRBLK_LONG;
		if (write_handle(a->fd, atoms, hdl2off(h) + 16) != 0)
			return -1;
	}
	if (writeat(a->fd, buf, sizeof(buf), hdl2off(h)) != sizeof(buf))
		return -1;

	idx = flt_idx(atoms);
	next = a->flt[idx];
	a->flt[idx] = h;
	if (list_setprev(a, h, prev) != 0)
		return -1;
	if (list_setnext(a, h, next) != 0)
		return -1;
	return list_setprev(a, next, h);
}
예제 #2
0
파일: pipe.hpp 프로젝트: JerYme/stlsoft
 /// \brief Closes the write handle, if not already closed
 void close_write()
 {
     if(-1 != write_handle())
     {
         ::close(m_handles[1]);
         m_handles[1] = -1;
     }
 }
 void alteration(const continuable_reader_ptr& ptr,
                 event_bitmask e,
                 fd_meta_event etype) {
     native_socket_type fd;
     switch (e) {
         case event::read:
             fd = ptr->read_handle();
             break;
         case event::write: {
             auto wptr = ptr->as_io();
             if (wptr) fd = wptr->write_handle();
             else {
                 CPPA_LOG_ERROR("ptr->downcast() returned nullptr");
                 return;
             }
             break;
         }
         case event::both: {
             fd = ptr->read_handle();
             auto wptr = ptr->as_io();
             if (wptr) {
                 auto wrfd = wptr->write_handle();
                 if (fd != wrfd) {
                     CPPA_LOG_DEBUG("read_handle != write_handle, split "
                                    "into two function calls");
                     // split into two function calls
                     e = event::read;
                     alteration(ptr, event::write, etype);
                 }
             }
             else {
                 CPPA_LOG_ERROR("ptr->downcast() returned nullptr");
                 return;
             }
             break;
         }
         default:
             CPPA_LOG_ERROR("invalid bitmask");
             return;
     }
     m_alterations.emplace_back(fd_meta_info(fd, ptr, e), etype);
 }
예제 #4
0
파일: alloc.c 프로젝트: fanyang01/sql
int list_setnext(ALLOC * a, handle_t x, handle_t next)
{
	if (x == 0)
		return 0;
	return write_handle(a->fd, next, hdl2off(x) + 8);
}
예제 #5
0
파일: alloc.c 프로젝트: fanyang01/sql
int list_setprev(ALLOC * a, handle_t x, handle_t prev)
{
	if (x == 0)
		return 0;
	return write_handle(a->fd, prev, hdl2off(x) + 1);
}