/* * Open a shared object */ int erts_sys_ddll_open(char *full_name, void **handle) { MODULE_ID mid; int len; int ret = ERL_DE_NO_ERROR; static char dlname[PATH_MAX + EXT_LEN + 1]; if ((mid = get_mid(full_name)) == NULL) { if ((len = sys_strlen(full_name)) > PATH_MAX-EXT_LEN-1) { ret = ERL_DE_LOAD_ERROR_NAME_TO_LONG; goto done; } sys_strcpy(dlname, full_name); sys_strcpy(dlname+len, FILE_EXT); if((mid = get_mid(dlname)) == NULL) { sys_strcpy(dlname+len, ALT_FILE_EXT); if((mid = get_mid(dlname)) == NULL) { ret = ERL_DE_DYNAMIC_ERROR_OFFSET - ((int) ModuleNotFound); goto done; } } } *handle = (void *) mid; done: return ret; }
struct mid_q_entry * AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) { struct mid_q_entry *temp; if (server == NULL) { cifs_dbg(VFS, "Null TCP session in AllocMidQEntry\n"); return NULL; } temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS); memset(temp, 0, sizeof(struct mid_q_entry)); kref_init(&temp->refcount); temp->mid = get_mid(smb_buffer); temp->pid = current->pid; temp->command = cpu_to_le16(smb_buffer->Command); cifs_dbg(FYI, "For smb_command %d\n", smb_buffer->Command); /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ /* when mid allocated can be before when sent */ temp->when_alloc = jiffies; temp->server = server; /* * The default is for the mid to be synchronous, so the * default callback just wakes up the current task. */ temp->callback = cifs_wake_up_task; temp->callback_data = current; atomic_inc(&midCount); temp->mid_state = MID_REQUEST_ALLOCATED; return temp; }
/*{{{ log_open -- log bit_open*/ void log_open(BITMAP *bp) { bp->id = get_mid(); reg_map(bp); if (do_save) SEND_screen(bp->id, bp->wide, bp->high, 0); }
int erts_sys_ddll_open_noext(char *dlname, void **handle, ErtsSysDdllError* err) { MODULE_ID mid; if((mid = get_mid(dlname)) == NULL) { return ERL_DE_DYNAMIC_ERROR_OFFSET - ((int) ModuleNotFound); } *handle = (void *) mid; return ERL_DE_NO_ERROR; }
/*{{{ log_create -- log bit_create*/ void log_create(BITMAP *bp) { if (bp->id == 0) { /* static bitmap */ bp->id = get_mid(); reg_map(bp); if (do_save) SEND_data(bp->id, bp->wide, bp->high, bp->data); /* create a "real" bitmap */ bp->type &= ~_DIRTY; } }
/*{{{ log_alloc -- log bit_alloc*/ void log_alloc(BITMAP *bp) { int id; id = get_mid(); bp->id = id; reg_map(bp); if (do_save) SEND_data(id, BIT_WIDE(bp), BIT_HIGH(bp), BIT_DATA(bp)); }
void reorderList(struct ListNode* head) { struct ListNode *tail; struct ListNode *mid; if(head == NULL || head->next == NULL) return ; mid = get_mid(head); tail = reverse(mid->next); mid->next = NULL; merge(head,tail); }
char* do_if(char* ch1, BOOL ch2, char* ch3, char* ch4) { char stack[1025] = ""; char* buffer; char* buf; char* buf2; int len; BOOL quote = FALSE; int idx = 0; int ldx = 0; buf = malloc(sizeof(char) * (strlen(ch1) * 2)); buf2 = malloc(sizeof(char) * (strlen(ch1))); buffer = buf2; buf[0] = '\0'; buf2[0] = '\0'; // tdata[0]='\0'; len = strlen(ch1); // give_term_debug("Received: #if %s", ch1); while (idx < len) { if (!quote && ch1[idx + 1] == ')') { ldx = left_token(ch1, idx, "("); if (ldx == 0) { give_term_error("Missing open paren."); free(buf); free(buf2); return NULL; } get_mid(ch1, stack, ldx - 1, idx + 2); // give_term_error(stack); } idx++; } free(buf); free(buf2); return NULL; }
/*{{{ check_map -- check bitmap, register and/or download if needed*/ static int check_map(BITMAP *map) { if (map && map->primary->id == 0) { /* static bitmap */ map->primary->id = get_mid(); reg_map(map->primary); map->primary->type |= _DIRTY; } if (map && do_save && map->primary->type & _DIRTY) { SEND_data(map->id, map->primary->wide, map->primary->high, map->data); map->primary->type &= ~_DIRTY; return (1); } return (0); }
//Converts a sorted double linked list to a balanced BST struct dl *convert_to_BST(struct dl *head){ struct dl *mid; if(!head)return NULL; mid=get_mid(head); // printf(">>>>>>>>%d\n",mid->data); if(mid==head && !mid->next){ mid->prev=NULL; mid->next=NULL; return mid;} if(mid->prev)mid->prev->next=NULL; if(mid->next)mid->next->prev=NULL; if(mid->prev) mid->prev=convert_to_BST(head); if(mid->next) mid->next=convert_to_BST(mid->next); return mid; }
double Brent::minimize(const func1d& func, const int maxiter, const double tol) { static const double CGOLD = 0.3819660; static const double ZEPS = 1.0e-12; double d, e; d = e = 0.0; double ax = get_lower(); double bx = get_mid(); double cx = get_upper(); double a, b; a = ax < cx ? ax : cx; b = ax > cx ? ax : cx; double x, w, v; x = w = v = bx; double fx, fw, fv; fx = fw = fv = func(x); for(int it=0; it<maxiter; it++) { double xm = 0.5 * (a + b); double tol1 = tol * abs(x) + ZEPS; double tol2 = 2.0 * tol1; // �I—¹”»’è if(abs(x - xm) <= (tol2 - 0.5 * (b - a))) { break; } // ‘o‹È�ü•âŠÔ if(abs(e) > tol1) { double r = (x - w) * (fx - fv); double q = (x - v) * (fx - fw); double p = (x - v) * q - (x - w) * r; q = 2.0 * (q - r); if(q > 0.0) { p = -p; } q = abs(q); double etemp = e; e = d; if(abs(p) >= abs(0.5 * q * etemp) || p <= q * (a - x) || p >= q * (b - x)) { e = x >= xm ? a - x : b - x; d = CGOLD * e; } else { d = p / q; double u = x + d; if(u - a < tol2 || b - u < tol2) { d = sgn(xm - x) * tol1; } } } else { e = x >= xm ? a - x : b - x; d = CGOLD * e; } double u = abs(d) >= tol1 ? x + d : x + sgn(d) * tol1; double fu = func(u); if(fu <= fx) { if(u >= x) { a = x; } else { b = x; } shift3(v, w, x, u); shift3(fv, fw, fx, fu); } else { if(u < x) { a = u; } else { b = u; } if(fu <= fw || w == x) { v = w; w = u; fv = fw; fw = fu; } else if(fu <= fv || v == x || v == w) { v = u; fv = fu; } } } fmin = fx; xmin = x; return xmin; }