CORBA::Boolean TAO_RT_Mutex::try_lock (TimeBase::TimeT wait_time) { int result; if (wait_time == 0) // No wait. result = this->mu_.tryacquire (); else { // Wait for the specified amount of time before giving up. // (wait_time units are 100ns. See TimeBase.pidl) TimeBase::TimeT seconds = wait_time / 10000000u; TimeBase::TimeT microseconds = (wait_time % 10000000u) / 10; ACE_Time_Value relative_time (ACE_U64_TO_U32 (seconds), ACE_U64_TO_U32 (microseconds)); ACE_Time_Value absolute_time = relative_time + ACE_OS::gettimeofday (); result = this->mu_.acquire (absolute_time); } if (result == 0) return 1; else if (result == -1 && (errno == ETIME || errno == EBUSY)) return 0; else // Some really bad error. throw ::CORBA::INTERNAL (); }
static void xtest_a(void * data, char * name) { fs_node_t * tty = data; fprintf(tty, "[%s] Hello world.\n", name); while (1) { fprintf(tty, "[%s] Ping.\n", name); unsigned long s, ss; relative_time(1, 0, &s, &ss); sleep_until((process_t *)current_process, s, ss); switch_task(0); } }
int things_list_cb(void *data, int argc, char **argv, char **azColName){ int i; struct tm tt; char *laststr; char humandate[256]; const char *button_group_start="<div class=\"btn-group\" role=\"group\" aria-label=\"actions\">"; const char *button_start="<div type=\"button\" class=\"btn btn-default\">"; // fprintf(stderr, "callback: %s\n", (const char*)data); for(i=0; i<argc; i++){ // save all fields into the hashmap hashmap_put(thing , azColName[i], argv[i] ? argv[i] : "NULL"); } attrcat(data,"list_of_things","<tr>"); snprintf(line,ml, "<td><a href=\"/things?macaddr=%s\">" "%s</td><td>%s</td></a>", thing_get("macaddr"), thing_get("hostname"), thing_get("os")); attrcat(data,"list_of_things",line); // get last datestamp laststr = thing_get("last"); if(laststr) relative_time(laststr,humandate); snprintf(line, ml, "<td>%s</td><td>", humandate); attrcat(data,"list_of_things",line); // action buttons attrcat(data,"list_of_things",button_group_start); // info button attrcat(data,"list_of_things",button_start); snprintf(line,ml, "<a href=\"/things?macaddr=%s\">info</a></div>", thing_get("macaddr")); attrcat(data,"list_of_things",line); attrcat(data,"list_of_things","</div></td></tr>"); // snprintf(line,ml,"<td>%s</td><td>%s</td>\n", // thing_get("macaddr"), thing_get("ip4")); // attrcat(data,"list_of_things",line); return 0; }
int thing_show_cb(void *data, int argc, char **argv, char **azColName){ int i; char humandate[256]; memset(humandate,0,256); for(i=0; i<argc; i++){ // save all fields into the template if(!argv[i]) continue; if(strcmp(azColName[i],"last")==0) { // kore_log(LOG_DEBUG,"last: %s",argv[i]); relative_time(argv[i],humandate); attrset(data, "last", humandate); } else if(strcmp(azColName[i],"age")==0) { // kore_log(LOG_DEBUG,"age: %s",argv[i]); relative_time(argv[i],humandate); attrset(data, "age", humandate); } else { attrprintf(data, azColName[i], "%s", argv[i]); } } return 0; }
int ACE_SPIPE_Connector::connect (ACE_SPIPE_Stream &new_io, const ACE_SPIPE_Addr &remote_sap, ACE_Time_Value *timeout, const ACE_Addr & /* local_sap */, int /* reuse_addr */, int flags, int perms, LPSECURITY_ATTRIBUTES sa, int pipe_mode) { ACE_TRACE ("ACE_SPIPE_Connector::connect"); // Make darn sure that the O_CREAT flag is not set! ACE_CLR_BITS (flags, O_CREAT); ACE_HANDLE handle; ACE_UNUSED_ARG (pipe_mode); #if defined (ACE_WIN32) && \ !defined (ACE_HAS_PHARLAP) && !defined (ACE_HAS_WINCE) // We need to allow for more than one attempt to connect, // calculate the absolute time at which we give up. ACE_Time_Value absolute_time; if (timeout != 0) absolute_time = ACE_OS::gettimeofday () + *timeout; // Loop until success or failure. for (;;) { handle = ACE_OS::open (remote_sap.get_path_name(), flags, perms, sa); if (handle != ACE_INVALID_HANDLE) // Success! break; // Check if we have a busy pipe condition. if (::GetLastError() != ERROR_PIPE_BUSY) // Nope, this is a failure condition. break; // This will hold the time out value used in the ::WaitNamedPipe // call. DWORD time_out_value; // Check if we are to block until we connect. if (timeout == 0) // Wait for as long as it takes. time_out_value = NMPWAIT_WAIT_FOREVER; else { // Calculate the amount of time left to wait. ACE_Time_Value relative_time (absolute_time - ACE_OS::gettimeofday ()); // Check if we have run out of time. if (relative_time <= ACE_Time_Value::zero) { // Mimick the errno value returned by // ACE::handle_timed_open. if (*timeout == ACE_Time_Value::zero) errno = EWOULDBLOCK; else errno = ETIMEDOUT; // Exit the connect loop with the failure. break; } // Get the amount of time remaining for ::WaitNamedPipe. time_out_value = relative_time.msec (); } // Wait for the named pipe to become available. ACE_TEXT_WaitNamedPipe (remote_sap.get_path_name (), time_out_value); // Regardless of the return value, we'll do one more attempt to // connect to see if it is now available and to return // consistent error values. } // Set named pipe mode if we have a valid handle. if (handle != ACE_INVALID_HANDLE) { // Check if we are changing the pipe mode from the default. if (pipe_mode != (PIPE_READMODE_BYTE | PIPE_WAIT)) { DWORD dword_pipe_mode = pipe_mode; if (!::SetNamedPipeHandleState (handle, &dword_pipe_mode, 0, 0)) { // We were not able to put the pipe into the requested // mode. ACE_OS::close (handle); handle = ACE_INVALID_HANDLE; } } } #else /* ACE_WIN32 && !ACE_HAS_PHARLAP */ handle = ACE::handle_timed_open (timeout, remote_sap.get_path_name (), flags, perms, sa); #endif /* !ACE_WIN32 || ACE_HAS_PHARLAP || ACE_HAS_WINCE */ new_io.set_handle (handle); new_io.remote_addr_ = remote_sap; // class copy. return handle == ACE_INVALID_HANDLE ? -1 : 0; }